2020-09-04 00:58:36 +00:00
|
|
|
package rpc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
ptypes "github.com/gogo/protobuf/types"
|
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/validator/accounts/v2"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
|
|
v2 "github.com/prysmaticlabs/prysm/validator/accounts/v2"
|
2020-09-17 01:34:42 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/validator/accounts/v2/wallet"
|
2020-09-04 00:58:36 +00:00
|
|
|
v2keymanager "github.com/prysmaticlabs/prysm/validator/keymanager/v2"
|
|
|
|
"github.com/prysmaticlabs/prysm/validator/keymanager/v2/direct"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestServer_CreateAccount(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
localWalletDir := setupWalletDir(t)
|
|
|
|
defaultWalletPath = localWalletDir
|
|
|
|
strongPass := "29384283xasjasd32%%&*@*#*"
|
|
|
|
// We attempt to create the wallet.
|
2020-09-17 01:34:42 +00:00
|
|
|
w, err := v2.CreateWalletWithKeymanager(ctx, &v2.CreateWalletConfig{
|
|
|
|
WalletCfg: &wallet.Config{
|
2020-09-04 00:58:36 +00:00
|
|
|
WalletDir: defaultWalletPath,
|
|
|
|
KeymanagerKind: v2keymanager.Direct,
|
|
|
|
WalletPassword: strongPass,
|
|
|
|
},
|
|
|
|
SkipMnemonicConfirm: true,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2020-09-17 01:34:42 +00:00
|
|
|
km, err := w.InitializeKeymanager(ctx, true /* skip mnemonic confirm */)
|
2020-09-04 00:58:36 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
s := &Server{
|
|
|
|
keymanager: km,
|
|
|
|
walletInitialized: true,
|
2020-09-17 01:34:42 +00:00
|
|
|
wallet: w,
|
2020-09-04 00:58:36 +00:00
|
|
|
}
|
|
|
|
resp, err := s.CreateAccount(ctx, &ptypes.Empty{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.NotNil(t, resp.Account.ValidatingPublicKey)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestServer_ListAccounts(t *testing.T) {
|
|
|
|
ctx := context.Background()
|
|
|
|
localWalletDir := setupWalletDir(t)
|
|
|
|
defaultWalletPath = localWalletDir
|
|
|
|
strongPass := "29384283xasjasd32%%&*@*#*"
|
|
|
|
// We attempt to create the wallet.
|
2020-09-17 01:34:42 +00:00
|
|
|
w, err := v2.CreateWalletWithKeymanager(ctx, &v2.CreateWalletConfig{
|
|
|
|
WalletCfg: &wallet.Config{
|
2020-09-04 00:58:36 +00:00
|
|
|
WalletDir: defaultWalletPath,
|
|
|
|
KeymanagerKind: v2keymanager.Direct,
|
|
|
|
WalletPassword: strongPass,
|
|
|
|
},
|
|
|
|
SkipMnemonicConfirm: true,
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
2020-09-17 01:34:42 +00:00
|
|
|
km, err := w.InitializeKeymanager(ctx, true /* skip mnemonic confirm */)
|
2020-09-04 00:58:36 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
s := &Server{
|
|
|
|
keymanager: km,
|
|
|
|
walletInitialized: true,
|
2020-09-17 01:34:42 +00:00
|
|
|
wallet: w,
|
2020-09-04 00:58:36 +00:00
|
|
|
}
|
|
|
|
numAccounts := 5
|
|
|
|
keys := make([][]byte, numAccounts)
|
|
|
|
for i := 0; i < numAccounts; i++ {
|
|
|
|
key, err := km.(*direct.Keymanager).CreateAccount(ctx)
|
|
|
|
require.NoError(t, err)
|
|
|
|
keys[i] = key
|
|
|
|
}
|
|
|
|
resp, err := s.ListAccounts(ctx, &pb.ListAccountsRequest{})
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, len(resp.Accounts), numAccounts)
|
|
|
|
for i := 0; i < numAccounts; i++ {
|
|
|
|
assert.DeepEqual(t, resp.Accounts[i].ValidatingPublicKey, keys[i])
|
|
|
|
}
|
|
|
|
}
|