mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-03 16:37:39 +00:00
Enforce validator's keystore dir (#5707)
* enforces keystore dir * Merge refs/heads/master into recheck-before-raw-tx-data * do not ignore error * Merge branch 'recheck-before-raw-tx-data' of github.com:prysmaticlabs/prysm into recheck-before-raw-tx-data
This commit is contained in:
parent
436d545f80
commit
b42cc724c5
@ -161,6 +161,16 @@ func CreateValidatorAccount(path string, passphrase string) (string, string, err
|
|||||||
path = text
|
path = text
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Forces user to create directory if using non-default path.
|
||||||
|
if path != DefaultValidatorDir() {
|
||||||
|
exists, err := Exists(path)
|
||||||
|
if err != nil {
|
||||||
|
return path, passphrase, err
|
||||||
|
}
|
||||||
|
if !exists {
|
||||||
|
return path, passphrase, fmt.Errorf("path %q does not exist", path)
|
||||||
|
}
|
||||||
|
}
|
||||||
if err := NewValidatorAccount(path, passphrase); err != nil {
|
if err := NewValidatorAccount(path, passphrase); err != nil {
|
||||||
return "", "", errors.Wrapf(err, "could not initialize validator account")
|
return "", "", errors.Wrapf(err, "could not initialize validator account")
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package accounts
|
package accounts
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
@ -14,7 +15,7 @@ func TestNewValidatorAccount_AccountExists(t *testing.T) {
|
|||||||
directory := testutil.TempDir() + "/testkeystore"
|
directory := testutil.TempDir() + "/testkeystore"
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := os.RemoveAll(directory); err != nil {
|
if err := os.RemoveAll(directory); err != nil {
|
||||||
t.Log(err)
|
t.Logf("Could not remove directory: %v", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
validatorKey, err := keystore.NewKey()
|
validatorKey, err := keystore.NewKey()
|
||||||
@ -38,7 +39,13 @@ func TestNewValidatorAccount_AccountExists(t *testing.T) {
|
|||||||
t.Errorf("%v\n", f.Name())
|
t.Errorf("%v\n", f.Name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := os.RemoveAll(directory); err != nil {
|
}
|
||||||
t.Fatalf("Could not remove directory: %v", err)
|
|
||||||
|
func TestNewValidatorAccount_CreateValidatorAccount(t *testing.T) {
|
||||||
|
directory := "foobar"
|
||||||
|
_, _, err := CreateValidatorAccount(directory, "foobar")
|
||||||
|
wantErrString := fmt.Sprintf("path %q does not exist", directory)
|
||||||
|
if err == nil || err.Error() != wantErrString {
|
||||||
|
t.Errorf("expected error not thrown, want: %v, got: %v", wantErrString, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user