mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-07 02:02:18 +00:00
bc2afa04c6
* removing redundant bls package * gazelle * battling bazel deps * workspace * go-bls works in prysm now * add func and test * add test * fix tests * edit workspace * more verbose logs * lint * all tests passing * handle error in keystore
61 lines
1.9 KiB
Go
61 lines
1.9 KiB
Go
package accounts
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/rand"
|
|
"fmt"
|
|
"os"
|
|
"testing"
|
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
"github.com/prysmaticlabs/prysm/shared/keystore"
|
|
"github.com/prysmaticlabs/prysm/shared/ssz"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
func TestNewValidatorAccount_AccountExists(t *testing.T) {
|
|
directory := "/tmp/testkeystore"
|
|
validatorKey, err := keystore.NewKey(rand.Reader)
|
|
if err != nil {
|
|
t.Fatalf("Cannot create new key: %v", err)
|
|
}
|
|
ks := keystore.NewKeystore(directory)
|
|
if err := ks.StoreKey(directory+"/validatorprivatekey", validatorKey, ""); err != nil {
|
|
t.Fatalf("Unable to store key %v", err)
|
|
}
|
|
if err := NewValidatorAccount(directory, ""); err == nil {
|
|
t.Error("Expected new validator account to throw error, received nil")
|
|
}
|
|
if err := os.RemoveAll(directory); err != nil {
|
|
t.Fatalf("Could not remove directory: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestNewValidatorAccount_PrintsDepositData(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
directory := "/tmp/testkeystore"
|
|
if err := NewValidatorAccount(directory, "1234"); err != nil {
|
|
t.Errorf("Expected new account to be created: %v", err)
|
|
}
|
|
ks := keystore.NewKeystore(directory)
|
|
valKey, err := ks.GetKey(directory+"/validatorprivatekey", "1234")
|
|
if err != nil {
|
|
t.Fatalf("Could not retrieve key: %v", err)
|
|
}
|
|
data := &pb.DepositInput{
|
|
Pubkey: valKey.SecretKey.GetPublicKey().Serialize(),
|
|
ProofOfPossession: []byte("pop"),
|
|
WithdrawalCredentialsHash32: []byte("withdraw"),
|
|
}
|
|
|
|
serializedData := new(bytes.Buffer)
|
|
if err := ssz.Encode(serializedData, data); err != nil {
|
|
t.Fatalf("Could not serialize deposit data: %v", err)
|
|
}
|
|
testutil.AssertLogsContain(t, hook, fmt.Sprintf("%#x", serializedData))
|
|
if err := os.RemoveAll(directory); err != nil {
|
|
t.Fatalf("Could not remove directory: %v", err)
|
|
}
|
|
}
|