prysm-pulse/validator/keymanager/v2/direct/backup_test.go
Raul Jordan 86b2bd5edd
Implement Accounts-V2 Backup for Direct Keymanager (#6936)
* progress on export feature
* Merge branch 'master' into impl-export
* rename func
* imports
* confs
* export single works
* impl export
* Merge branch 'master' into impl-export
* cleanup exports code
* rename to backup
* rename to backup
* Merge branch 'master' into impl-export
* full test for backup
* Merge branch 'impl-export' of github.com:prysmaticlabs/prysm into impl-export
* gazelle fix
* terence feedback
* merge confs
* Merge branch 'master' into impl-export
* refactor into single select accounts function
* gaz
* Merge refs/heads/master into impl-export
* victor's feedback
* validate yes or no
* confs
* close the zip file in defer
* Merge refs/heads/master into impl-export
* Merge refs/heads/master into impl-export
2020-08-11 23:15:06 +00:00

55 lines
1.5 KiB
Go

package direct
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 TestKeymanager_ExtractKeystores(t *testing.T) {
dr := &Keymanager{
keysCache: make(map[[48]byte]bls.SecretKey),
}
validatingKeys := make([]bls.SecretKey, 10)
for i := 0; i < len(validatingKeys); i++ {
secretKey := bls.RandKey()
validatingKeys[i] = secretKey
dr.keysCache[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(),
})
}