mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-09 11:11:20 +00:00
bc16fa9f50
* initialize derived wallet * derived wallet + account creation * initialize wallet seed * encrypted seed file creation * generate next acct * create seed from pass * properly creating derived accounts * fix up formatting * prep for review * start tests for derived create account * add derived test * linter * gaz * derived keymanager create account test complete * Merge branch 'master' into derived-keymanager * tests pass * gaz * fix list test * Merge refs/heads/master into derived-keymanager * ivan feedback * skip mnemonic confirm * Merge branch 'derived-keymanager' of github.com:prysmaticlabs/prysm into derived-keymanager * comment * tidy * fmt * organize * test interface conformity * Update validator/accounts/v2/iface/wallet.go * ivan comments * Merge branch 'derived-keymanager' of github.com:prysmaticlabs/prysm into derived-keymanager * Merge refs/heads/master into derived-keymanager * Merge branch 'master' of github.com:prysmaticlabs/prysm into derived-keymanager * Fix * Fix test * Merge refs/heads/master into derived-keymanager * fix errs * imports * Gaz
74 lines
2.4 KiB
Go
74 lines
2.4 KiB
Go
package v2
|
|
|
|
import (
|
|
"context"
|
|
"crypto/rand"
|
|
"fmt"
|
|
"io/ioutil"
|
|
"math/big"
|
|
"os"
|
|
"path"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
v2keymanager "github.com/prysmaticlabs/prysm/validator/keymanager/v2"
|
|
mock "github.com/prysmaticlabs/prysm/validator/keymanager/v2/testing"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func init() {
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
logrus.SetOutput(ioutil.Discard)
|
|
}
|
|
|
|
func setupWalletDir(t testing.TB) (string, string) {
|
|
randPath, err := rand.Int(rand.Reader, big.NewInt(1000000))
|
|
require.NoError(t, err, "Could not generate random file path")
|
|
walletDir := path.Join(testutil.TempDir(), fmt.Sprintf("/%d", randPath))
|
|
require.NoError(t, os.RemoveAll(walletDir), "Failed to remove directory")
|
|
passwordsDir := path.Join(testutil.TempDir(), fmt.Sprintf("/%d", randPath))
|
|
require.NoError(t, os.RemoveAll(passwordsDir), "Failed to remove directory")
|
|
t.Cleanup(func() {
|
|
require.NoError(t, os.RemoveAll(walletDir), "Failed to remove directory")
|
|
require.NoError(t, os.RemoveAll(passwordsDir), "Failed to remove directory")
|
|
})
|
|
return walletDir, passwordsDir
|
|
}
|
|
|
|
func TestCreateAndReadWallet(t *testing.T) {
|
|
ctx := context.Background()
|
|
if _, err := NewWallet(ctx, &WalletConfig{
|
|
PasswordsDir: "",
|
|
WalletDir: "",
|
|
}); err == nil {
|
|
t.Error("Expected error when passing in empty directories, received nil")
|
|
}
|
|
walletDir, passwordsDir := setupWalletDir(t)
|
|
keymanagerKind := v2keymanager.Direct
|
|
wallet, err := NewWallet(ctx, &WalletConfig{
|
|
PasswordsDir: passwordsDir,
|
|
WalletDir: walletDir,
|
|
KeymanagerKind: keymanagerKind,
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
keymanager := &mock.MockKeymanager{
|
|
ConfigFileContents: []byte("hello-world"),
|
|
}
|
|
keymanagerConfig, err := keymanager.MarshalConfigFile(ctx)
|
|
require.NoError(t, err, "Could not marshal keymanager config file")
|
|
require.NoError(t, wallet.WriteKeymanagerConfigToDisk(ctx, keymanagerConfig), "Could not write keymanager config file to disk")
|
|
|
|
walletPath := path.Join(walletDir, keymanagerKind.String())
|
|
configFilePath := path.Join(walletPath, KeymanagerConfigFileName)
|
|
require.Equal(t, true, fileExists(configFilePath), "Expected config file to have been created at path: %s", configFilePath)
|
|
|
|
// We should be able to now read the wallet as well.
|
|
_, err = NewWallet(ctx, &WalletConfig{
|
|
PasswordsDir: passwordsDir,
|
|
WalletDir: walletDir,
|
|
})
|
|
require.NoError(t, err)
|
|
}
|