prysm-pulse/validator/keymanager/imported/refresh_test.go

59 lines
1.9 KiB
Go
Raw Normal View History

package imported
Begin Dynamic Rescan of Validating Keys (#6963) * begin on dynamic key rescan * Merge branch 'master' into dynamic-rescan * begin dynamic rescan * fsnotify to listen for rescan dir changes * recheck for slashing protection * lint * Merge branch 'master' into dynamic-rescan * less aggressive recheck interval * imports * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * resolve confs * listen for file changes for accounts file * reload accounts from keystore * begin fixing rescan test * add event feed * fix confs * fix conf * fix broken tests * Merge branch 'master' into dynamic-rescan * simplify lines * do nothing if no subscribers * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * fix tests * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * gaz * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * ident * Update WORKSPACE * gaz * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * add keys on service start * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * ensure debounce util works * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * complete refresh, debounce test, and ensure works at runtime * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * imports and remove log * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * resolve confs * fix up e2e tests * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * fix up e2e * Merge refs/heads/master into dynamic-rescan
2020-08-31 23:38:20 +00:00
import (
"context"
"testing"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/event"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
mock "github.com/prysmaticlabs/prysm/validator/accounts/testing"
Begin Dynamic Rescan of Validating Keys (#6963) * begin on dynamic key rescan * Merge branch 'master' into dynamic-rescan * begin dynamic rescan * fsnotify to listen for rescan dir changes * recheck for slashing protection * lint * Merge branch 'master' into dynamic-rescan * less aggressive recheck interval * imports * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * resolve confs * listen for file changes for accounts file * reload accounts from keystore * begin fixing rescan test * add event feed * fix confs * fix conf * fix broken tests * Merge branch 'master' into dynamic-rescan * simplify lines * do nothing if no subscribers * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * fix tests * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * gaz * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * ident * Update WORKSPACE * gaz * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * add keys on service start * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * ensure debounce util works * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * complete refresh, debounce test, and ensure works at runtime * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * imports and remove log * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * resolve confs * fix up e2e tests * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * fix up e2e * Merge refs/heads/master into dynamic-rescan
2020-08-31 23:38:20 +00:00
)
func TestImportedKeymanager_reloadAccountsFromKeystore(t *testing.T) {
Begin Dynamic Rescan of Validating Keys (#6963) * begin on dynamic key rescan * Merge branch 'master' into dynamic-rescan * begin dynamic rescan * fsnotify to listen for rescan dir changes * recheck for slashing protection * lint * Merge branch 'master' into dynamic-rescan * less aggressive recheck interval * imports * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * resolve confs * listen for file changes for accounts file * reload accounts from keystore * begin fixing rescan test * add event feed * fix confs * fix conf * fix broken tests * Merge branch 'master' into dynamic-rescan * simplify lines * do nothing if no subscribers * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * fix tests * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * gaz * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * ident * Update WORKSPACE * gaz * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * add keys on service start * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * ensure debounce util works * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * complete refresh, debounce test, and ensure works at runtime * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * imports and remove log * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * resolve confs * fix up e2e tests * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * fix up e2e * Merge refs/heads/master into dynamic-rescan
2020-08-31 23:38:20 +00:00
password := "Passw03rdz293**%#2"
wallet := &mock.Wallet{
Files: make(map[string]map[string][]byte),
AccountPasswords: make(map[string]string),
WalletPassword: password,
}
dr := &Keymanager{
wallet: wallet,
accountsChangedFeed: new(event.Feed),
}
numAccounts := 20
privKeys := make([][]byte, numAccounts)
pubKeys := make([][]byte, numAccounts)
for i := 0; i < numAccounts; i++ {
privKey := bls.RandKey()
privKeys[i] = privKey.Marshal()
pubKeys[i] = privKey.PublicKey().Marshal()
}
accountsStore, err := dr.createAccountsKeystore(context.Background(), privKeys, pubKeys)
require.NoError(t, err)
require.NoError(t, dr.reloadAccountsFromKeystore(accountsStore))
// Check that the public keys were added to the public keys cache.
for i, keyBytes := range pubKeys {
require.Equal(t, bytesutil.ToBytes48(keyBytes), orderedPublicKeys[i])
}
// Check that the secret keys were added to the secret keys cache.
lock.RLock()
defer lock.RUnlock()
for i, keyBytes := range privKeys {
privKey, ok := secretKeysCache[bytesutil.ToBytes48(pubKeys[i])]
Begin Dynamic Rescan of Validating Keys (#6963) * begin on dynamic key rescan * Merge branch 'master' into dynamic-rescan * begin dynamic rescan * fsnotify to listen for rescan dir changes * recheck for slashing protection * lint * Merge branch 'master' into dynamic-rescan * less aggressive recheck interval * imports * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * resolve confs * listen for file changes for accounts file * reload accounts from keystore * begin fixing rescan test * add event feed * fix confs * fix conf * fix broken tests * Merge branch 'master' into dynamic-rescan * simplify lines * do nothing if no subscribers * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * fix tests * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * gaz * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * ident * Update WORKSPACE * gaz * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * add keys on service start * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * ensure debounce util works * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * complete refresh, debounce test, and ensure works at runtime * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * imports and remove log * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * resolve confs * fix up e2e tests * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * fix up e2e * Merge refs/heads/master into dynamic-rescan
2020-08-31 23:38:20 +00:00
require.Equal(t, true, ok)
require.Equal(t, bytesutil.ToBytes48(keyBytes), bytesutil.ToBytes48(privKey.Marshal()))
Begin Dynamic Rescan of Validating Keys (#6963) * begin on dynamic key rescan * Merge branch 'master' into dynamic-rescan * begin dynamic rescan * fsnotify to listen for rescan dir changes * recheck for slashing protection * lint * Merge branch 'master' into dynamic-rescan * less aggressive recheck interval * imports * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * resolve confs * listen for file changes for accounts file * reload accounts from keystore * begin fixing rescan test * add event feed * fix confs * fix conf * fix broken tests * Merge branch 'master' into dynamic-rescan * simplify lines * do nothing if no subscribers * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * fix tests * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * gaz * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * ident * Update WORKSPACE * gaz * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * add keys on service start * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * ensure debounce util works * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * complete refresh, debounce test, and ensure works at runtime * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * imports and remove log * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * Merge refs/heads/master into dynamic-rescan * resolve confs * fix up e2e tests * Merge branch 'dynamic-rescan' of github.com:prysmaticlabs/prysm into dynamic-rescan * fix up e2e * Merge refs/heads/master into dynamic-rescan
2020-08-31 23:38:20 +00:00
}
// Check the key was added to the global accounts store.
require.Equal(t, numAccounts, len(dr.accountsStore.PublicKeys))
require.Equal(t, numAccounts, len(dr.accountsStore.PrivateKeys))
assert.DeepEqual(t, dr.accountsStore.PublicKeys[0], pubKeys[0])
}