prysm-pulse/validator/keymanager/local/backup_test.go
Raul Jordan d077483577
Add V3 Suffix to All Prysm Packages (#11083)
* v3 import renamings

* tidy

* fmt

* rev

* Update beacon-chain/core/epoch/precompute/reward_penalty_test.go

* Update beacon-chain/core/helpers/validators_test.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/alias.go

* Update beacon-chain/db/iface/BUILD.bazel

* Update beacon-chain/db/kv/kv.go

* Update beacon-chain/db/kv/state.go

* Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go

* Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go

* Update beacon-chain/sync/initial-sync/service.go

* fix deps

* fix bad replacements

* fix bad replacements

* change back

* gohashtree version

* fix deps

Co-authored-by: Nishant Das <nishdas93@gmail.com>
Co-authored-by: Potuz <potuz@prysmaticlabs.com>
2022-08-16 12:20:13 +00:00

56 lines
1.6 KiB
Go

package local
import (
"context"
"encoding/hex"
"testing"
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/crypto/bls"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v3/testing/assert"
"github.com/prysmaticlabs/prysm/v3/testing/require"
)
func TestLocalKeymanager_ExtractKeystores(t *testing.T) {
secretKeysCache = make(map[[fieldparams.BLSPubkeyLength]byte]bls.SecretKey)
dr := &Keymanager{}
validatingKeys := make([]bls.SecretKey, 10)
for i := 0; i < len(validatingKeys); i++ {
secretKey, err := bls.RandKey()
require.NoError(t, err)
validatingKeys[i] = secretKey
secretKeysCache[bytesutil.ToBytes48(secretKey.PublicKey().Marshal())] = secretKey
}
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(),
})
}