mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
8b2b109939
* imported -> local * reverting to the state of the PR at eb1e3c3d1 * use changes from develop * del * rem patch * patch * rename to local * gazelle * add back build * imported rename * gaz * local * merge fix + remove proto changes * comment revert * build * gofmt and one new reference * gofmt pt2 * Update validator/accounts/wallet_edit.go Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/rpc/accounts.go * rename * gaz Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
package local
|
|
|
|
import (
|
|
"context"
|
|
"encoding/hex"
|
|
"testing"
|
|
|
|
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
|
"github.com/prysmaticlabs/prysm/crypto/bls"
|
|
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
|
"github.com/prysmaticlabs/prysm/testing/assert"
|
|
"github.com/prysmaticlabs/prysm/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(),
|
|
})
|
|
}
|