prysm-pulse/validator/keymanager/derived/backup_test.go
Raul Jordan a81c863ddb
Rename Accounts-V2 to Accounts (#7545)
* rename accounts v2

* rename keymanager and fix imports

* rename accounts-v2 instances

* imports

* build

* build fix

* deepsource

* fix up broken aliases

* imports

* gaz

* Update validator/accounts/accounts_import_test.go

Co-authored-by: Ivan Martinez <ivanthegreatdev@gmail.com>

* fmt

Co-authored-by: Ivan Martinez <ivanthegreatdev@gmail.com>
2020-10-15 22:31:52 +00:00

56 lines
1.5 KiB
Go

package derived
import (
"context"
"encoding/hex"
"testing"
"github.com/prysmaticlabs/prysm/shared/bls"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
)
func TestDerivedKeymanager_ExtractKeystores(t *testing.T) {
secretKeysCache = make(map[[48]byte]bls.SecretKey)
dr := &Keymanager{}
validatingKeys := make([]bls.SecretKey, 10)
lock.Lock()
for i := 0; i < len(validatingKeys); i++ {
secretKey := bls.RandKey()
validatingKeys[i] = secretKey
secretKeysCache[bytesutil.ToBytes48(secretKey.PublicKey().Marshal())] = secretKey
}
lock.Unlock()
ctx := context.Background()
password := "password"
// Extracting 0 public keys should return 0 keystores.
keystores, err := dr.ExtractKeystores(ctx, nil, password)
require.NoError(t, err)
assert.Equal(t, 0, len(keystores))
// We attempt to extract a few indices.
keystores, err = dr.ExtractKeystores(
ctx,
[]bls.PublicKey{
validatingKeys[3].PublicKey(),
validatingKeys[5].PublicKey(),
validatingKeys[7].PublicKey(),
},
password,
)
require.NoError(t, err)
receivedPubKeys := make([][]byte, len(keystores))
for i, k := range keystores {
pubKeyBytes, err := hex.DecodeString(k.Pubkey)
require.NoError(t, err)
receivedPubKeys[i] = pubKeyBytes
}
assert.DeepEqual(t, receivedPubKeys, [][]byte{
validatingKeys[3].PublicKey().Marshal(),
validatingKeys[5].PublicKey().Marshal(),
validatingKeys[7].PublicKey().Marshal(),
})
}