mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 13:18:57 +00:00
7449eba612
* begin hd wallet refactor * further simplify the new derived keymanager * make it almost a full wrapper around an imported keymanager * fix up the EIP test * deprecated derived * fixing keymanager tests * fix up derived tests * refactor initialize keymanager * simplify hd * pass some tests * pass accounts list test * gaz * regenerate protos without create account privilege * enforce account recovery on wallet create * allow accounts delete to work * remove mentions of accounts create * resolve comments and go mod * fix up tests * build fixes * remove insecure warning * revert * fix proto file * remove create account message * gaz * remove account create * update web api protos * fix up imports * change func sig * tidy Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
88 lines
2.5 KiB
Go
88 lines
2.5 KiB
Go
package rpc
|
|
|
|
import (
|
|
"context"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
pb "github.com/prysmaticlabs/prysm/proto/validator/accounts/v2"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
"github.com/prysmaticlabs/prysm/validator/accounts"
|
|
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
|
"github.com/prysmaticlabs/prysm/validator/flags"
|
|
"github.com/prysmaticlabs/prysm/validator/keymanager"
|
|
"github.com/prysmaticlabs/prysm/validator/keymanager/derived"
|
|
)
|
|
|
|
var (
|
|
defaultWalletPath = filepath.Join(flags.DefaultValidatorDir(), flags.WalletDefaultDirName)
|
|
testMnemonic = "tumble turn jewel sudden social great water general cabin jacket bounce dry flip monster advance problem social half flee inform century chicken hard reason"
|
|
)
|
|
|
|
func TestServer_ListAccounts(t *testing.T) {
|
|
ctx := context.Background()
|
|
localWalletDir := setupWalletDir(t)
|
|
defaultWalletPath = localWalletDir
|
|
strongPass := "29384283xasjasd32%%&*@*#*"
|
|
// We attempt to create the wallet.
|
|
w, err := accounts.CreateWalletWithKeymanager(ctx, &accounts.CreateWalletConfig{
|
|
WalletCfg: &wallet.Config{
|
|
WalletDir: defaultWalletPath,
|
|
KeymanagerKind: keymanager.Derived,
|
|
WalletPassword: strongPass,
|
|
},
|
|
SkipMnemonicConfirm: true,
|
|
})
|
|
require.NoError(t, err)
|
|
km, err := w.InitializeKeymanager(ctx)
|
|
require.NoError(t, err)
|
|
s := &Server{
|
|
keymanager: km,
|
|
walletInitialized: true,
|
|
wallet: w,
|
|
}
|
|
numAccounts := 50
|
|
dr, ok := km.(*derived.Keymanager)
|
|
require.Equal(t, true, ok)
|
|
err = dr.RecoverAccountsFromMnemonic(ctx, testMnemonic, "", numAccounts)
|
|
require.NoError(t, err)
|
|
resp, err := s.ListAccounts(ctx, &pb.ListAccountsRequest{
|
|
PageSize: int32(numAccounts),
|
|
})
|
|
require.NoError(t, err)
|
|
require.Equal(t, len(resp.Accounts), numAccounts)
|
|
|
|
tests := []struct {
|
|
req *pb.ListAccountsRequest
|
|
res *pb.ListAccountsResponse
|
|
}{
|
|
{
|
|
req: &pb.ListAccountsRequest{
|
|
PageSize: 5,
|
|
},
|
|
res: &pb.ListAccountsResponse{
|
|
Accounts: resp.Accounts[0:5],
|
|
NextPageToken: "1",
|
|
TotalSize: int32(numAccounts),
|
|
},
|
|
},
|
|
{
|
|
req: &pb.ListAccountsRequest{
|
|
PageSize: 5,
|
|
PageToken: "1",
|
|
},
|
|
res: &pb.ListAccountsResponse{
|
|
Accounts: resp.Accounts[5:10],
|
|
NextPageToken: "2",
|
|
TotalSize: int32(numAccounts),
|
|
},
|
|
},
|
|
}
|
|
for _, test := range tests {
|
|
res, err := s.ListAccounts(context.Background(), test.req)
|
|
require.NoError(t, err)
|
|
assert.DeepEqual(t, res, test.res)
|
|
}
|
|
}
|