prysm-pulse/validator/keymanager/imported/refresh_test.go
Nishant Das 211d9bc0b9
Update BLST And Herumi (#7632)
* fix build from source

* clean up

* update again

* change everything

* workaround for now

* fix versioning

* all passing now

* fix build issues

* clean up

* revert use of MulVerify

* gaz

* stub

* Apply suggestions from code review

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>

* fix all

* fix test

* todo

* fix stub

* revert back

* make deep source happy

* Update shared/bls/herumi/public_key.go

* Update shared/bls/blst/signature.go

* Update shared/bls/blst/signature_test.go

* imports

* move iface to common, export errors

* rm iface build

Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
Co-authored-by: terence tsao <terence@prysmaticlabs.com>
2020-10-30 19:06:33 +00:00

60 lines
1.9 KiB
Go

package imported
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"
)
func TestImportedKeymanager_reloadAccountsFromKeystore(t *testing.T) {
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, err := bls.RandKey()
require.NoError(t, err)
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])]
require.Equal(t, true, ok)
require.Equal(t, bytesutil.ToBytes48(keyBytes), bytesutil.ToBytes48(privKey.Marshal()))
}
// 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])
}