prysm-pulse/validator/accounts/v2/accounts_create_test.go

57 lines
1.7 KiB
Go
Raw Normal View History

package v2
import (
"context"
"testing"
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
"github.com/prysmaticlabs/prysm/shared/testutil/require"
v2keymanager "github.com/prysmaticlabs/prysm/validator/keymanager/v2"
"github.com/prysmaticlabs/prysm/validator/keymanager/v2/derived"
)
func TestCreateAccount_Derived(t *testing.T) {
walletDir, passwordsDir, passwordFile := setupWalletAndPasswordsDir(t)
numAccounts := int64(5)
cliCtx := setupWalletCtx(t, &testWalletConfig{
walletDir: walletDir,
passwordsDir: passwordsDir,
walletPasswordFile: passwordFile,
accountPasswordFile: passwordFile,
keymanagerKind: v2keymanager.Derived,
numAccounts: numAccounts,
})
// We attempt to create the wallet.
_, err := CreateAndSaveWalletCli(cliCtx)
require.NoError(t, err)
// We attempt to open the newly created wallet.
ctx := context.Background()
wallet, err := OpenWallet(cliCtx.Context, &WalletConfig{
WalletDir: walletDir,
})
assert.NoError(t, err)
// We read the keymanager config for the newly created wallet.
encoded, err := wallet.ReadKeymanagerConfigFromDisk(ctx)
assert.NoError(t, err)
opts, err := derived.UnmarshalOptionsFile(encoded)
assert.NoError(t, err)
// We assert the created configuration was as desired.
assert.DeepEqual(t, derived.DefaultKeymanagerOpts(), opts)
require.NoError(t, CreateAccountCli(cliCtx))
keymanager, err := wallet.InitializeKeymanager(cliCtx.Context, true)
require.NoError(t, err)
km, ok := keymanager.(*derived.Keymanager)
if !ok {
t.Fatal("not a derived keymanager")
}
names, err := km.ValidatingAccountNames(ctx)
assert.NoError(t, err)
require.Equal(t, len(names), int(numAccounts))
}