prysm-pulse/validator/accounts/wallet/wallet_test.go

52 lines
1.4 KiB
Go
Raw Normal View History

package wallet_test
import (
"io/ioutil"
"os"
Accounts V2: Refactor prompts, deduplicate into directory and password (#6674) * Refactor input code, deduplicate into directory and password * Change to filepath * Rename * Make consts visible to whole validator package * Fix * Try commands and fix * Fix defaults * Fixes * Merge branch 'master' into refactor-input-prompts * Merge refs/heads/master into refactor-input-prompts * Merge refs/heads/master into refactor-input-prompts * Merge refs/heads/master into refactor-input-prompts * Merge refs/heads/master into refactor-input-prompts * Remove consts and add comment * Merge branch 'refactor-input-prompts' of github.com:prysmaticlabs/prysm into refactor-input-prompts * Undo * Fixes * Update validator/accounts/v2/prompt.go * Merge refs/heads/master into refactor-input-prompts * gofmt * Merge refs/heads/master into refactor-input-prompts * Merge refs/heads/master into refactor-input-prompts * Merge refs/heads/master into refactor-input-prompts * Merge refs/heads/master into refactor-input-prompts * Merge branch 'master' into refactor-input-prompts * Merge refs/heads/master into refactor-input-prompts * Fix * Merge refs/heads/master into refactor-input-prompts * Merge refs/heads/master into refactor-input-prompts * Accounts V2: Simplify Wallet Save/Read To and From Disk Functions (#6686) * simplify wallet functions * fix build * futher simplify wallet * simplify read/write methods * move direct functions to direct keymanager * further move direct km specific funcs * cleanup * simplify the direct tests * fixed tests * lint * further simplify * tidy * fix config write * fixed test Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> * conflict resolution * trim
2020-07-23 03:10:23 +00:00
"path/filepath"
"testing"
2020-08-01 00:08:40 +00:00
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
"github.com/sirupsen/logrus"
)
func init() {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
}
func Test_Exists_RandomFiles(t *testing.T) {
path := filepath.Join(t.TempDir(), "wallet")
exists, err := wallet.Exists(path)
require.Equal(t, false, exists)
require.NoError(t, err)
require.NoError(t, os.MkdirAll(path+"/direct", params.BeaconIoConfig().ReadWriteExecutePermissions), "Failed to create directory")
exists, err = wallet.Exists(path)
require.NoError(t, err)
require.Equal(t, true, exists)
}
func Test_IsValid_RandomFiles(t *testing.T) {
path := filepath.Join(t.TempDir(), "wallet")
valid, err := wallet.IsValid(path)
require.NoError(t, err)
require.Equal(t, false, valid)
require.NoError(t, os.MkdirAll(path, params.BeaconIoConfig().ReadWriteExecutePermissions), "Failed to create directory")
valid, err = wallet.IsValid(path)
require.ErrorContains(t, "no wallet found", err)
require.Equal(t, false, valid)
2020-08-01 00:08:40 +00:00
walletDir := filepath.Join(path, "direct")
require.NoError(t, os.MkdirAll(walletDir, params.BeaconIoConfig().ReadWriteExecutePermissions), "Failed to create directory")
valid, err = wallet.IsValid(path)
2020-08-01 00:08:40 +00:00
require.NoError(t, err)
require.Equal(t, true, valid)
2020-08-01 00:08:40 +00:00
}