2019-01-31 11:57:57 +00:00
|
|
|
package accounts
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/rand"
|
2019-03-29 22:26:41 +00:00
|
|
|
"io/ioutil"
|
2019-01-31 11:57:57 +00:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/keystore"
|
2019-02-23 06:06:20 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
2019-01-31 11:57:57 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewValidatorAccount_AccountExists(t *testing.T) {
|
2019-02-13 23:49:06 +00:00
|
|
|
directory := testutil.TempDir() + "/testkeystore"
|
|
|
|
defer os.RemoveAll(directory)
|
2019-01-31 11:57:57 +00:00
|
|
|
validatorKey, err := keystore.NewKey(rand.Reader)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Cannot create new key: %v", err)
|
|
|
|
}
|
|
|
|
ks := keystore.NewKeystore(directory)
|
2019-02-13 23:49:06 +00:00
|
|
|
if err := ks.StoreKey(directory+params.BeaconConfig().ValidatorPrivkeyFileName, validatorKey, ""); err != nil {
|
2019-01-31 11:57:57 +00:00
|
|
|
t.Fatalf("Unable to store key %v", err)
|
|
|
|
}
|
2019-03-29 22:26:41 +00:00
|
|
|
if err := NewValidatorAccount(directory, ""); err != nil {
|
|
|
|
t.Errorf("Should support multiple keys: %v", err)
|
|
|
|
}
|
|
|
|
files, _ := ioutil.ReadDir(directory)
|
|
|
|
if len(files) != 3 {
|
2019-04-18 17:23:38 +00:00
|
|
|
t.Errorf("multiple validators were not created only %v files in directory", len(files))
|
2019-03-29 22:26:41 +00:00
|
|
|
for _, f := range files {
|
|
|
|
t.Errorf("%v\n", f.Name())
|
|
|
|
}
|
2019-01-31 11:57:57 +00:00
|
|
|
}
|
|
|
|
if err := os.RemoveAll(directory); err != nil {
|
|
|
|
t.Fatalf("Could not remove directory: %v", err)
|
|
|
|
}
|
|
|
|
}
|