mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 21:07:18 +00:00
93bbb86a30
* Add test for exporting and importing * Add test for non-interactive * Test import cli * Merge branch 'master' of github.com:prysmaticlabs/prysm into test-export * Merge branch 'master' into test-export * Cleanup tests a bit * Change to assert * Fix tests * Merge branch 'master' of github.com:prysmaticlabs/prysm into test-export * Fix comment, change constants * Fixes * Change to require * Fix broken test * Merge refs/heads/master into test-export * Merge refs/heads/master into test-export * Merge refs/heads/master into test-export * Merge refs/heads/master into test-export * Merge refs/heads/master into test-export * Merge refs/heads/master into test-export * Merge refs/heads/master into test-export * Merge refs/heads/master into test-export * Merge refs/heads/master into test-export * Merge refs/heads/master into test-export * Merge refs/heads/master into test-export * Merge refs/heads/master into test-export * Merge refs/heads/master into test-export * Merge refs/heads/master into test-export * Merge refs/heads/master into test-export * Merge refs/heads/master into test-export * Merge refs/heads/master into test-export
60 lines
2.0 KiB
Go
60 lines
2.0 KiB
Go
package v2
|
|
|
|
import (
|
|
"flag"
|
|
"io/ioutil"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
"github.com/prysmaticlabs/prysm/validator/flags"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
func TestImport_Noninteractive(t *testing.T) {
|
|
testDir := testutil.TempDir()
|
|
walletDir := filepath.Join(testDir, walletDirName)
|
|
passwordsDir := filepath.Join(testDir, passwordDirName)
|
|
exportDir := filepath.Join(testDir, exportDirName)
|
|
importDir := filepath.Join(testDir, importDirName)
|
|
importPasswordDir := filepath.Join(testDir, importPasswordDirName)
|
|
|
|
passwordFilePath := filepath.Join(testDir, passwordFileName)
|
|
require.NoError(t, ioutil.WriteFile(passwordFilePath, []byte(password), os.ModePerm))
|
|
defer func() {
|
|
assert.NoError(t, os.RemoveAll(walletDir))
|
|
assert.NoError(t, os.RemoveAll(passwordsDir))
|
|
assert.NoError(t, os.RemoveAll(exportDir))
|
|
assert.NoError(t, os.RemoveAll(importDir))
|
|
assert.NoError(t, os.RemoveAll(importPasswordDir))
|
|
}()
|
|
|
|
wallet := setupWallet(t, testDir)
|
|
|
|
accounts, err := wallet.AccountNames()
|
|
require.NoError(t, err)
|
|
assert.Equal(t, len(accounts), 1)
|
|
|
|
require.NoError(t, wallet.zipAccounts(accounts, exportDir))
|
|
if _, err := os.Stat(filepath.Join(exportDir, archiveFilename)); os.IsNotExist(err) {
|
|
t.Fatal("Expected file to exist")
|
|
}
|
|
|
|
app := cli.App{}
|
|
set := flag.NewFlagSet("test", 0)
|
|
set.String(flags.WalletDirFlag.Name, importDir, "")
|
|
set.String(flags.WalletPasswordsDirFlag.Name, importPasswordDir, "")
|
|
set.String(flags.BackupPathFlag.Name, exportDir, "")
|
|
set.String(flags.PasswordFileFlag.Name, passwordFilePath, "")
|
|
assert.NoError(t, set.Set(flags.WalletDirFlag.Name, importDir))
|
|
assert.NoError(t, set.Set(flags.WalletPasswordsDirFlag.Name, importPasswordDir))
|
|
assert.NoError(t, set.Set(flags.BackupPathFlag.Name, exportDir))
|
|
assert.NoError(t, set.Set(flags.PasswordFileFlag.Name, passwordFilePath))
|
|
cliCtx := cli.NewContext(&app, set, nil)
|
|
|
|
require.NoError(t, ImportAccount(cliCtx))
|
|
}
|