diff --git a/beacon-chain/rpc/beacon/assignments.go b/beacon-chain/rpc/beacon/assignments.go index c4f0634281..72d761ab15 100644 --- a/beacon-chain/rpc/beacon/assignments.go +++ b/beacon-chain/rpc/beacon/assignments.go @@ -14,6 +14,8 @@ import ( "google.golang.org/grpc/status" ) +const errEpoch = "Cannot retrieve information about an epoch in the future, current epoch %d, requesting %d" + // ListValidatorAssignments retrieves the validator assignments for a given epoch, // optional validator indices or public keys may be included to filter validator assignments. func (bs *Server) ListValidatorAssignments( @@ -45,7 +47,7 @@ func (bs *Server) ListValidatorAssignments( if requestedEpoch > currentEpoch { return nil, status.Errorf( codes.InvalidArgument, - "Cannot retrieve information about an epoch in the future, current epoch %d, requesting %d", + errEpoch, currentEpoch, requestedEpoch, ) diff --git a/beacon-chain/rpc/beacon/assignments_test.go b/beacon-chain/rpc/beacon/assignments_test.go index 673f6cb163..837bb4ea09 100644 --- a/beacon-chain/rpc/beacon/assignments_test.go +++ b/beacon-chain/rpc/beacon/assignments_test.go @@ -30,7 +30,7 @@ func TestServer_ListAssignments_CannotRequestFutureEpoch(t *testing.T) { GenesisTimeFetcher: &mock.ChainService{}, } - wanted := "Cannot retrieve information about an epoch in the future" + wanted := errNoEpochInfoError _, err := bs.ListValidatorAssignments( ctx, ðpb.ListValidatorAssignmentsRequest{ diff --git a/beacon-chain/rpc/beacon/validators.go b/beacon-chain/rpc/beacon/validators.go index df7ccdba3e..5bc52e4dcd 100644 --- a/beacon-chain/rpc/beacon/validators.go +++ b/beacon-chain/rpc/beacon/validators.go @@ -55,7 +55,7 @@ func (bs *Server) ListValidatorBalances( if requestedEpoch > currentEpoch { return nil, status.Errorf( codes.InvalidArgument, - "Cannot retrieve information about an epoch in the future, current epoch %d, requesting %d", + errEpoch, currentEpoch, requestedEpoch, ) @@ -207,7 +207,7 @@ func (bs *Server) ListValidators( if q.Epoch > currentEpoch { return nil, status.Errorf( codes.InvalidArgument, - "Cannot retrieve information about an epoch in the future, current epoch %d, requesting %d", + errEpoch, currentEpoch, q.Epoch, ) @@ -401,7 +401,7 @@ func (bs *Server) GetValidatorActiveSetChanges( if requestedEpoch > currentEpoch { return nil, status.Errorf( codes.InvalidArgument, - "Cannot retrieve information about an epoch in the future, current epoch %d, requesting %d", + errEpoch, currentEpoch, requestedEpoch, ) @@ -775,7 +775,7 @@ func (bs *Server) GetIndividualVotes( if req.Epoch > currentEpoch { return nil, status.Errorf( codes.InvalidArgument, - "Cannot retrieve information about an epoch in the future, current epoch %d, requesting %d", + errEpoch, currentEpoch, req.Epoch, ) diff --git a/beacon-chain/rpc/beacon/validators_test.go b/beacon-chain/rpc/beacon/validators_test.go index 751629a545..0c0b40045c 100644 --- a/beacon-chain/rpc/beacon/validators_test.go +++ b/beacon-chain/rpc/beacon/validators_test.go @@ -32,6 +32,10 @@ import ( "github.com/prysmaticlabs/prysm/shared/timeutils" ) +const ( + errNoEpochInfoError = "Cannot retrieve information about an epoch in the future" +) + func TestServer_GetValidatorActiveSetChanges_CannotRequestFutureEpoch(t *testing.T) { beaconDB := dbTest.SetupDB(t) ctx := context.Background() @@ -46,7 +50,7 @@ func TestServer_GetValidatorActiveSetChanges_CannotRequestFutureEpoch(t *testing BeaconDB: beaconDB, } - wanted := "Cannot retrieve information about an epoch in the future" + wanted := errNoEpochInfoError _, err = bs.GetValidatorActiveSetChanges( ctx, ðpb.GetValidatorActiveSetChangesRequest{ @@ -73,7 +77,7 @@ func TestServer_ListValidatorBalances_CannotRequestFutureEpoch(t *testing.T) { GenesisTimeFetcher: &mock.ChainService{}, } - wanted := "Cannot retrieve information about an epoch in the future" + wanted := errNoEpochInfoError _, err = bs.ListValidatorBalances( ctx, ðpb.ListValidatorBalancesRequest{ @@ -415,7 +419,7 @@ func TestServer_ListValidators_CannotRequestFutureEpoch(t *testing.T) { }, } - wanted := "Cannot retrieve information about an epoch in the future" + wanted := errNoEpochInfoError _, err = bs.ListValidators( ctx, ðpb.ListValidatorsRequest{ @@ -1916,7 +1920,7 @@ func TestServer_GetIndividualVotes_RequestFutureSlot(t *testing.T) { req := ðpb.IndividualVotesRequest{ Epoch: helpers.SlotToEpoch(ds.GenesisTimeFetcher.CurrentSlot()) + 1, } - wanted := "Cannot retrieve information about an epoch in the future" + wanted := errNoEpochInfoError _, err := ds.GetIndividualVotes(context.Background(), req) assert.ErrorContains(t, wanted, err) } diff --git a/shared/htrutils/helpers_test.go b/shared/htrutils/helpers_test.go index b9c7832809..c5b06e72e9 100644 --- a/shared/htrutils/helpers_test.go +++ b/shared/htrutils/helpers_test.go @@ -10,6 +10,8 @@ import ( "github.com/prysmaticlabs/prysm/shared/testutil/require" ) +const merkleizingListLimitError = "merkleizing list that is too large, over limit" + func TestBitlistRoot(t *testing.T) { hasher := hashutil.CustomSHA256Hasher() capacity := uint64(10) @@ -44,10 +46,9 @@ func TestBitwiseMerkleizeOverLimit(t *testing.T) { } count := uint64(2) limit := uint64(1) - expected := "merkleizing list that is too large, over limit" _, err := htrutils.BitwiseMerkleize(hasher, chunks, count, limit) - assert.ErrorContains(t, expected, err) + assert.ErrorContains(t, merkleizingListLimitError, err) } func TestBitwiseMerkleizeArrays(t *testing.T) { @@ -73,10 +74,9 @@ func TestBitwiseMerkleizeArraysOverLimit(t *testing.T) { } count := uint64(2) limit := uint64(1) - expected := "merkleizing list that is too large, over limit" _, err := htrutils.BitwiseMerkleizeArrays(hasher, chunks, count, limit) - assert.ErrorContains(t, expected, err) + assert.ErrorContains(t, merkleizingListLimitError, err) } func TestPack(t *testing.T) { diff --git a/shared/mputil/multilock_test.go b/shared/mputil/multilock_test.go index 120c83c9cd..f3822f5ccd 100644 --- a/shared/mputil/multilock_test.go +++ b/shared/mputil/multilock_test.go @@ -312,15 +312,15 @@ func TestSyncCondCompatibility(t *testing.T) { var wg sync.WaitGroup wg.Add(2) cond := sync.NewCond(NewMultilock("A", "C")) - - sharedRsc := "foo" + var testValues = [3]string{"foo", "bar", "fizz!"} + sharedRsc := testValues[0] go func() { cond.L.Lock() - for sharedRsc == "foo" { + for sharedRsc == testValues[0] { cond.Wait() } - sharedRsc = "fizz!" + sharedRsc = testValues[2] cond.Broadcast() cond.L.Unlock() wg.Done() @@ -328,9 +328,9 @@ func TestSyncCondCompatibility(t *testing.T) { go func() { cond.L.Lock() - sharedRsc = "bar" + sharedRsc = testValues[1] cond.Broadcast() - for sharedRsc == "bar" { + for sharedRsc == testValues[1] { cond.Wait() } cond.L.Unlock() @@ -338,5 +338,5 @@ func TestSyncCondCompatibility(t *testing.T) { }() wg.Wait() - assert.Equal(t, "fizz!", sharedRsc) + assert.Equal(t, testValues[2], sharedRsc) } diff --git a/tools/keystores/main_test.go b/tools/keystores/main_test.go index e5cdb93709..48e2ffe44a 100644 --- a/tools/keystores/main_test.go +++ b/tools/keystores/main_test.go @@ -20,6 +20,8 @@ import ( keystorev4 "github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4" ) +const password = "secretPassw0rd$1999" + type cliConfig struct { keystoresPath string password string @@ -70,7 +72,6 @@ func setupRandomDir(t testing.TB) string { func TestDecrypt(t *testing.T) { keystoresDir := setupRandomDir(t) - password := "secretPassw0rd$1999" keystore, privKey := createRandomKeystore(t, password) // We write a random keystore to a keystores directory. encodedKeystore, err := json.MarshalIndent(keystore, "", "\t") @@ -109,7 +110,6 @@ func TestDecrypt(t *testing.T) { func TestEncrypt(t *testing.T) { keystoresDir := setupRandomDir(t) - password := "secretPassw0rd$1999" keystoreFilePath := filepath.Join(keystoresDir, "keystore.json") privKey, err := bls.RandKey() require.NoError(t, err) diff --git a/validator/accounts/BUILD.bazel b/validator/accounts/BUILD.bazel index 74e6ad3373..2bba3236e0 100644 --- a/validator/accounts/BUILD.bazel +++ b/validator/accounts/BUILD.bazel @@ -94,6 +94,7 @@ go_test( "//validator/keymanager/derived:go_default_library", "//validator/keymanager/imported:go_default_library", "//validator/keymanager/remote:go_default_library", + "//validator/testing:go_default_library", "@com_github_gogo_protobuf//types:go_default_library", "@com_github_golang_mock//gomock:go_default_library", "@com_github_google_uuid//:go_default_library", diff --git a/validator/accounts/accounts_backup_test.go b/validator/accounts/accounts_backup_test.go index 7c61cfa5d4..4c6f27201c 100644 --- a/validator/accounts/accounts_backup_test.go +++ b/validator/accounts/accounts_backup_test.go @@ -4,6 +4,7 @@ import ( "archive/zip" "encoding/hex" "encoding/json" + constant "github.com/prysmaticlabs/prysm/validator/testing" "io/ioutil" "os" "path/filepath" @@ -22,10 +23,6 @@ import ( "github.com/prysmaticlabs/prysm/validator/keymanager/derived" ) -var ( - testMnemonic = "tumble turn jewel sudden social great water general cabin jacket bounce dry flip monster advance problem social half flee inform century chicken hard reason" -) - func TestBackupAccounts_Noninteractive_Derived(t *testing.T) { walletDir, _, passwordFilePath := setupWalletAndPasswordsDir(t) // Specify the password locally to this file for convenience. @@ -69,7 +66,7 @@ func TestBackupAccounts_Noninteractive_Derived(t *testing.T) { // Create 2 accounts derivedKM, ok := km.(*derived.Keymanager) require.Equal(t, true, ok) - err = derivedKM.RecoverAccountsFromMnemonic(cliCtx.Context, testMnemonic, "", 2) + err = derivedKM.RecoverAccountsFromMnemonic(cliCtx.Context, constant.TestMnemonic, "", 2) require.NoError(t, err) // Obtain the public keys of the accounts we created diff --git a/validator/accounts/accounts_list_test.go b/validator/accounts/accounts_list_test.go index ff7b6ab1d2..0ed02ac225 100644 --- a/validator/accounts/accounts_list_test.go +++ b/validator/accounts/accounts_list_test.go @@ -3,6 +3,7 @@ package accounts import ( "context" "fmt" + constant "github.com/prysmaticlabs/prysm/validator/testing" "io/ioutil" "math" "os" @@ -249,7 +250,7 @@ func TestListAccounts_DerivedKeymanager(t *testing.T) { require.NoError(t, err) numAccounts := 5 - err = keymanager.RecoverAccountsFromMnemonic(cliCtx.Context, testMnemonic, "", numAccounts) + err = keymanager.RecoverAccountsFromMnemonic(cliCtx.Context, constant.TestMnemonic, "", numAccounts) require.NoError(t, err) rescueStdout := os.Stdout diff --git a/validator/client/wait_for_activation_test.go b/validator/client/wait_for_activation_test.go index 8724b95dfb..9ff20d6cfc 100644 --- a/validator/client/wait_for_activation_test.go +++ b/validator/client/wait_for_activation_test.go @@ -3,6 +3,7 @@ package client import ( "context" "fmt" + constant "github.com/prysmaticlabs/prysm/validator/testing" "testing" "time" @@ -304,8 +305,7 @@ func TestWaitForActivation_AccountsChanged(t *testing.T) { }) t.Run("Derived keymanager", func(t *testing.T) { - mnemonic := "tumble turn jewel sudden social great water general cabin jacket bounce dry flip monster advance problem social half flee inform century chicken hard reason" - seed := bip39.NewSeed(mnemonic, "") + seed := bip39.NewSeed(constant.TestMnemonic, "") inactivePrivKey, err := util.PrivateKeyFromSeedAndPath(seed, fmt.Sprintf(derived.ValidatingKeyDerivationPathTemplate, 0)) require.NoError(t, err) @@ -327,7 +327,7 @@ func TestWaitForActivation_AccountsChanged(t *testing.T) { ListenForChanges: true, }) require.NoError(t, err) - err = km.RecoverAccountsFromMnemonic(ctx, mnemonic, "", 1) + err = km.RecoverAccountsFromMnemonic(ctx, constant.TestMnemonic, "", 1) require.NoError(t, err) client := mock.NewMockBeaconNodeValidatorClient(ctrl) v := validator{ @@ -369,7 +369,7 @@ func TestWaitForActivation_AccountsChanged(t *testing.T) { go func() { // We add the active key into the keymanager and simulate a key refresh. time.Sleep(time.Second * 1) - err = km.RecoverAccountsFromMnemonic(ctx, mnemonic, "", 2) + err = km.RecoverAccountsFromMnemonic(ctx, constant.TestMnemonic, "", 2) require.NoError(t, err) channel <- struct{}{} }() diff --git a/validator/keymanager/derived/BUILD.bazel b/validator/keymanager/derived/BUILD.bazel index 323a5b33f9..ad02f15610 100644 --- a/validator/keymanager/derived/BUILD.bazel +++ b/validator/keymanager/derived/BUILD.bazel @@ -41,6 +41,7 @@ go_test( "//shared/testutil/assert:go_default_library", "//shared/testutil/require:go_default_library", "//validator/accounts/testing:go_default_library", + "//validator/testing:go_default_library", "@com_github_tyler_smith_go_bip39//:go_default_library", "@com_github_wealdtech_go_eth2_util//:go_default_library", ], diff --git a/validator/keymanager/derived/keymanager_test.go b/validator/keymanager/derived/keymanager_test.go index 3c760d017a..439d86fa7e 100644 --- a/validator/keymanager/derived/keymanager_test.go +++ b/validator/keymanager/derived/keymanager_test.go @@ -3,6 +3,7 @@ package derived import ( "context" "fmt" + constant "github.com/prysmaticlabs/prysm/validator/testing" "testing" validatorpb "github.com/prysmaticlabs/prysm/proto/validator/accounts/v2" @@ -15,15 +16,18 @@ import ( util "github.com/wealdtech/go-eth2-util" ) +const ( + password = "secretPassw0rd$1999" +) + // We test that using a '25th word' mnemonic passphrase leads to different // public keys derived than not specifying the passphrase. func TestDerivedKeymanager_MnemnonicPassphrase_DifferentResults(t *testing.T) { - sampleMnemonic := "tumble turn jewel sudden social great water general cabin jacket bounce dry flip monster advance problem social half flee inform century chicken hard reason" ctx := context.Background() wallet := &mock.Wallet{ Files: make(map[string]map[string][]byte), AccountPasswords: make(map[string]string), - WalletPassword: "secretPassw0rd$1999", + WalletPassword: password, } km, err := NewKeymanager(ctx, &SetupConfig{ Wallet: wallet, @@ -31,14 +35,14 @@ func TestDerivedKeymanager_MnemnonicPassphrase_DifferentResults(t *testing.T) { }) require.NoError(t, err) numAccounts := 5 - err = km.RecoverAccountsFromMnemonic(ctx, sampleMnemonic, "mnemonicpass", numAccounts) + err = km.RecoverAccountsFromMnemonic(ctx, constant.TestMnemonic, "mnemonicpass", numAccounts) require.NoError(t, err) without25thWord, err := km.FetchValidatingPublicKeys(ctx) require.NoError(t, err) wallet = &mock.Wallet{ Files: make(map[string]map[string][]byte), AccountPasswords: make(map[string]string), - WalletPassword: "secretPassw0rd$1999", + WalletPassword: password, } km, err = NewKeymanager(ctx, &SetupConfig{ Wallet: wallet, @@ -46,7 +50,7 @@ func TestDerivedKeymanager_MnemnonicPassphrase_DifferentResults(t *testing.T) { }) require.NoError(t, err) // No mnemonic passphrase this time. - err = km.RecoverAccountsFromMnemonic(ctx, sampleMnemonic, "", numAccounts) + err = km.RecoverAccountsFromMnemonic(ctx, constant.TestMnemonic, "", numAccounts) require.NoError(t, err) with25thWord, err := km.FetchValidatingPublicKeys(ctx) require.NoError(t, err) @@ -72,13 +76,12 @@ func TestDerivedKeymanager_RecoverSeedRoundTrip(t *testing.T) { } func TestDerivedKeymanager_FetchValidatingPublicKeys(t *testing.T) { - sampleMnemonic := "tumble turn jewel sudden social great water general cabin jacket bounce dry flip monster advance problem social half flee inform century chicken hard reason" - derivedSeed, err := seedFromMnemonic(sampleMnemonic, "") + derivedSeed, err := seedFromMnemonic(constant.TestMnemonic, "") require.NoError(t, err) wallet := &mock.Wallet{ Files: make(map[string]map[string][]byte), AccountPasswords: make(map[string]string), - WalletPassword: "secretPassw0rd$1999", + WalletPassword: password, } ctx := context.Background() dr, err := NewKeymanager(ctx, &SetupConfig{ @@ -87,7 +90,7 @@ func TestDerivedKeymanager_FetchValidatingPublicKeys(t *testing.T) { }) require.NoError(t, err) numAccounts := 5 - err = dr.RecoverAccountsFromMnemonic(ctx, sampleMnemonic, "", numAccounts) + err = dr.RecoverAccountsFromMnemonic(ctx, constant.TestMnemonic, "", numAccounts) require.NoError(t, err) // Fetch the public keys. @@ -112,13 +115,12 @@ func TestDerivedKeymanager_FetchValidatingPublicKeys(t *testing.T) { } func TestDerivedKeymanager_FetchValidatingPrivateKeys(t *testing.T) { - sampleMnemonic := "tumble turn jewel sudden social great water general cabin jacket bounce dry flip monster advance problem social half flee inform century chicken hard reason" - derivedSeed, err := seedFromMnemonic(sampleMnemonic, "") + derivedSeed, err := seedFromMnemonic(constant.TestMnemonic, "") require.NoError(t, err) wallet := &mock.Wallet{ Files: make(map[string]map[string][]byte), AccountPasswords: make(map[string]string), - WalletPassword: "secretPassw0rd$1999", + WalletPassword: password, } ctx := context.Background() dr, err := NewKeymanager(ctx, &SetupConfig{ @@ -127,7 +129,7 @@ func TestDerivedKeymanager_FetchValidatingPrivateKeys(t *testing.T) { }) require.NoError(t, err) numAccounts := 5 - err = dr.RecoverAccountsFromMnemonic(ctx, sampleMnemonic, "", numAccounts) + err = dr.RecoverAccountsFromMnemonic(ctx, constant.TestMnemonic, "", numAccounts) require.NoError(t, err) // Fetch the private keys. @@ -152,11 +154,10 @@ func TestDerivedKeymanager_FetchValidatingPrivateKeys(t *testing.T) { } func TestDerivedKeymanager_Sign(t *testing.T) { - sampleMnemonic := "tumble turn jewel sudden social great water general cabin jacket bounce dry flip monster advance problem social half flee inform century chicken hard reason" wallet := &mock.Wallet{ Files: make(map[string]map[string][]byte), AccountPasswords: make(map[string]string), - WalletPassword: "secretPassw0rd$1999", + WalletPassword: password, } ctx := context.Background() dr, err := NewKeymanager(ctx, &SetupConfig{ @@ -165,7 +166,7 @@ func TestDerivedKeymanager_Sign(t *testing.T) { }) require.NoError(t, err) numAccounts := 5 - err = dr.RecoverAccountsFromMnemonic(ctx, sampleMnemonic, "", numAccounts) + err = dr.RecoverAccountsFromMnemonic(ctx, constant.TestMnemonic, "", numAccounts) require.NoError(t, err) pubKeys, err := dr.FetchAllValidatingPublicKeys(ctx) diff --git a/validator/keymanager/imported/import_test.go b/validator/keymanager/imported/import_test.go index 1038c216ab..83ff85d415 100644 --- a/validator/keymanager/imported/import_test.go +++ b/validator/keymanager/imported/import_test.go @@ -17,6 +17,8 @@ import ( keystorev4 "github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4" ) +const password = "secretPassw0rd$1999" + func createRandomKeystore(t testing.TB, password string) *keymanager.Keystore { encryptor := keystorev4.New() id, err := uuid.NewRandom() @@ -93,7 +95,6 @@ func TestImportedKeymanager_CreateAccountsKeystore_NoDuplicates(t *testing.T) { } func TestImportedKeymanager_ImportKeystores(t *testing.T) { - password := "secretPassw0rd$1999" // Setup the keymanager. wallet := &mock.Wallet{ Files: make(map[string]map[string][]byte), diff --git a/validator/keymanager/imported/keymanager_test.go b/validator/keymanager/imported/keymanager_test.go index aff09406f7..0e50ae9eee 100644 --- a/validator/keymanager/imported/keymanager_test.go +++ b/validator/keymanager/imported/keymanager_test.go @@ -20,7 +20,6 @@ import ( func TestImportedKeymanager_RemoveAccounts(t *testing.T) { hook := logTest.NewGlobal() - password := "secretPassw0rd$1999" wallet := &mock.Wallet{ Files: make(map[string]map[string][]byte), WalletPassword: password, @@ -70,7 +69,6 @@ func TestImportedKeymanager_RemoveAccounts(t *testing.T) { } func TestImportedKeymanager_FetchValidatingPublicKeys(t *testing.T) { - password := "secretPassw0rd$1999" wallet := &mock.Wallet{ Files: make(map[string]map[string][]byte), WalletPassword: password, @@ -109,7 +107,6 @@ func TestImportedKeymanager_FetchValidatingPublicKeys(t *testing.T) { } func TestImportedKeymanager_FetchAllValidatingPublicKeys(t *testing.T) { - password := "secretPassw0rd$1999" wallet := &mock.Wallet{ Files: make(map[string]map[string][]byte), WalletPassword: password, @@ -143,7 +140,6 @@ func TestImportedKeymanager_FetchAllValidatingPublicKeys(t *testing.T) { } func TestImportedKeymanager_FetchValidatingPrivateKeys(t *testing.T) { - password := "secretPassw0rd$1999" wallet := &mock.Wallet{ Files: make(map[string]map[string][]byte), WalletPassword: password, @@ -178,7 +174,6 @@ func TestImportedKeymanager_FetchValidatingPrivateKeys(t *testing.T) { } func TestImportedKeymanager_Sign(t *testing.T) { - password := "secretPassw0rd$1999" wallet := &mock.Wallet{ Files: make(map[string]map[string][]byte), AccountPasswords: make(map[string]string), diff --git a/validator/rpc/BUILD.bazel b/validator/rpc/BUILD.bazel index 3dbde83208..4114319bf1 100644 --- a/validator/rpc/BUILD.bazel +++ b/validator/rpc/BUILD.bazel @@ -93,6 +93,7 @@ go_test( "//validator/keymanager:go_default_library", "//validator/keymanager/derived:go_default_library", "//validator/keymanager/imported:go_default_library", + "//validator/testing:go_default_library", "@com_github_dgrijalva_jwt_go//:go_default_library", "@com_github_gogo_protobuf//types:go_default_library", "@com_github_golang_mock//gomock:go_default_library", diff --git a/validator/rpc/accounts_test.go b/validator/rpc/accounts_test.go index cbeab7a38c..2ade06334e 100644 --- a/validator/rpc/accounts_test.go +++ b/validator/rpc/accounts_test.go @@ -19,18 +19,17 @@ import ( "github.com/prysmaticlabs/prysm/validator/flags" "github.com/prysmaticlabs/prysm/validator/keymanager" "github.com/prysmaticlabs/prysm/validator/keymanager/derived" + constant "github.com/prysmaticlabs/prysm/validator/testing" ) var ( defaultWalletPath = filepath.Join(flags.DefaultValidatorDir(), flags.WalletDefaultDirName) - testMnemonic = "tumble turn jewel sudden social great water general cabin jacket bounce dry flip monster advance problem social half flee inform century chicken hard reason" ) func TestServer_ListAccounts(t *testing.T) { ctx := context.Background() localWalletDir := setupWalletDir(t) defaultWalletPath = localWalletDir - strongPass := "29384283xasjasd32%%&*@*#*" // We attempt to create the wallet. w, err := accounts.CreateWalletWithKeymanager(ctx, &accounts.CreateWalletConfig{ WalletCfg: &wallet.Config{ @@ -51,7 +50,7 @@ func TestServer_ListAccounts(t *testing.T) { numAccounts := 50 dr, ok := km.(*derived.Keymanager) require.Equal(t, true, ok) - err = dr.RecoverAccountsFromMnemonic(ctx, testMnemonic, "", numAccounts) + err = dr.RecoverAccountsFromMnemonic(ctx, constant.TestMnemonic, "", numAccounts) require.NoError(t, err) resp, err := s.ListAccounts(ctx, &pb.ListAccountsRequest{ PageSize: int32(numAccounts), @@ -96,7 +95,6 @@ func TestServer_BackupAccounts(t *testing.T) { ctx := context.Background() localWalletDir := setupWalletDir(t) defaultWalletPath = localWalletDir - strongPass := "29384283xasjasd32%%&*@*#*" // We attempt to create the wallet. w, err := accounts.CreateWalletWithKeymanager(ctx, &accounts.CreateWalletConfig{ WalletCfg: &wallet.Config{ @@ -117,7 +115,7 @@ func TestServer_BackupAccounts(t *testing.T) { numAccounts := 50 dr, ok := km.(*derived.Keymanager) require.Equal(t, true, ok) - err = dr.RecoverAccountsFromMnemonic(ctx, testMnemonic, "", numAccounts) + err = dr.RecoverAccountsFromMnemonic(ctx, constant.TestMnemonic, "", numAccounts) require.NoError(t, err) resp, err := s.ListAccounts(ctx, &pb.ListAccountsRequest{ PageSize: int32(numAccounts), diff --git a/validator/rpc/auth_test.go b/validator/rpc/auth_test.go index 0f10121081..e2d998f2ea 100644 --- a/validator/rpc/auth_test.go +++ b/validator/rpc/auth_test.go @@ -31,7 +31,6 @@ func TestServer_SignupAndLogin_RoundTrip(t *testing.T) { localWalletDir := setupWalletDir(t) defaultWalletPath = localWalletDir - strongPass := "29384283xasjasd32%%&*@*#*" ss := &Server{ valDB: valDB, @@ -100,7 +99,6 @@ func TestServer_ChangePassword_Preconditions(t *testing.T) { localWalletDir := setupWalletDir(t) defaultWalletPath = localWalletDir ctx := context.Background() - strongPass := "29384283xasjasd32%%&*@*#*" ss := &Server{ walletDir: defaultWalletPath, } diff --git a/validator/rpc/wallet_test.go b/validator/rpc/wallet_test.go index 649baad1af..d054ef2c30 100644 --- a/validator/rpc/wallet_test.go +++ b/validator/rpc/wallet_test.go @@ -25,11 +25,12 @@ import ( keystorev4 "github.com/wealdtech/go-eth2-wallet-encryptor-keystorev4" ) +const strongPass = "29384283xasjasd32%%&*@*#*" + func TestServer_CreateWallet_Imported(t *testing.T) { localWalletDir := setupWalletDir(t) defaultWalletPath = localWalletDir ctx := context.Background() - strongPass := "29384283xasjasd32%%&*@*#*" s := &Server{ walletInitializedFeed: new(event.Feed), walletDir: defaultWalletPath, @@ -86,7 +87,6 @@ func TestServer_CreateWallet_Derived(t *testing.T) { localWalletDir := setupWalletDir(t) defaultWalletPath = localWalletDir ctx := context.Background() - strongPass := "29384283xasjasd32%%&*@*#*" s := &Server{ walletInitializedFeed: new(event.Feed), walletDir: localWalletDir, @@ -125,7 +125,6 @@ func TestServer_WalletConfig(t *testing.T) { localWalletDir := setupWalletDir(t) defaultWalletPath = localWalletDir ctx := context.Background() - strongPass := "29384283xasjasd32%%&*@*#*" s := &Server{ walletInitializedFeed: new(event.Feed), walletDir: defaultWalletPath, @@ -157,7 +156,6 @@ func TestServer_ImportKeystores_FailedPreconditions_WrongKeymanagerKind(t *testi localWalletDir := setupWalletDir(t) defaultWalletPath = localWalletDir ctx := context.Background() - strongPass := "29384283xasjasd32%%&*@*#*" w, err := accounts.CreateWalletWithKeymanager(ctx, &accounts.CreateWalletConfig{ WalletCfg: &wallet.Config{ WalletDir: defaultWalletPath, @@ -181,7 +179,6 @@ func TestServer_ImportKeystores_FailedPreconditions(t *testing.T) { localWalletDir := setupWalletDir(t) defaultWalletPath = localWalletDir ctx := context.Background() - strongPass := "29384283xasjasd32%%&*@*#*" w, err := accounts.CreateWalletWithKeymanager(ctx, &accounts.CreateWalletConfig{ WalletCfg: &wallet.Config{ WalletDir: defaultWalletPath, @@ -217,7 +214,6 @@ func TestServer_ImportKeystores_OK(t *testing.T) { localWalletDir := setupWalletDir(t) defaultWalletPath = localWalletDir ctx := context.Background() - strongPass := "29384283xasjasd32%%&*@*#*" w, err := accounts.CreateWalletWithKeymanager(ctx, &accounts.CreateWalletConfig{ WalletCfg: &wallet.Config{ WalletDir: defaultWalletPath, diff --git a/validator/testing/BUILD.bazel b/validator/testing/BUILD.bazel index 6b81e70311..ef62856170 100644 --- a/validator/testing/BUILD.bazel +++ b/validator/testing/BUILD.bazel @@ -4,6 +4,7 @@ go_library( name = "go_default_library", testonly = True, srcs = [ + "constants.go", "mock_protector.go", "mock_slasher.go", "protection_history.go", diff --git a/validator/testing/constants.go b/validator/testing/constants.go new file mode 100644 index 0000000000..262573914e --- /dev/null +++ b/validator/testing/constants.go @@ -0,0 +1,3 @@ +package testing + +const TestMnemonic = "tumble turn jewel sudden social great water general cabin jacket bounce dry flip monster advance problem social half flee inform century chicken hard reason"