mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-31 15:31:20 +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
|
||||
}
|
||||
}
|
||||
// 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 {
|
||||
return "", "", errors.Wrapf(err, "could not initialize validator account")
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package accounts
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
@ -14,7 +15,7 @@ func TestNewValidatorAccount_AccountExists(t *testing.T) {
|
||||
directory := testutil.TempDir() + "/testkeystore"
|
||||
defer func() {
|
||||
if err := os.RemoveAll(directory); err != nil {
|
||||
t.Log(err)
|
||||
t.Logf("Could not remove directory: %v", err)
|
||||
}
|
||||
}()
|
||||
validatorKey, err := keystore.NewKey()
|
||||
@ -38,7 +39,13 @@ func TestNewValidatorAccount_AccountExists(t *testing.T) {
|
||||
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