mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-12 04:30:04 +00:00
6e731bdedd
* start api * keystores list * gaz Co-authored-by: Radosław Kapka <rkapka@wp.pl>
74 lines
2.2 KiB
Go
74 lines
2.2 KiB
Go
package rpc
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/golang/protobuf/ptypes/empty"
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
"github.com/prysmaticlabs/prysm/validator/accounts"
|
|
"github.com/prysmaticlabs/prysm/validator/accounts/iface"
|
|
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
|
"github.com/prysmaticlabs/prysm/validator/keymanager"
|
|
"github.com/prysmaticlabs/prysm/validator/keymanager/derived"
|
|
constant "github.com/prysmaticlabs/prysm/validator/testing"
|
|
)
|
|
|
|
func TestServer_ListKeystores(t *testing.T) {
|
|
t.Run("wallet not ready", func(t *testing.T) {
|
|
s := Server{}
|
|
_, err := s.ListKeystores(context.Background(), &empty.Empty{})
|
|
require.ErrorContains(t, "Wallet not ready", err)
|
|
})
|
|
|
|
ctx := context.Background()
|
|
localWalletDir := setupWalletDir(t)
|
|
defaultWalletPath = localWalletDir
|
|
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, iface.InitKeymanagerConfig{ListenForChanges: false})
|
|
require.NoError(t, err)
|
|
|
|
s := &Server{
|
|
keymanager: km,
|
|
walletInitialized: true,
|
|
wallet: w,
|
|
}
|
|
|
|
t.Run("no keystores found", func(t *testing.T) {
|
|
resp, err := s.ListKeystores(context.Background(), &empty.Empty{})
|
|
require.NoError(t, err)
|
|
require.Equal(t, true, len(resp.Keystores) == 0)
|
|
})
|
|
|
|
numAccounts := 50
|
|
dr, ok := km.(*derived.Keymanager)
|
|
require.Equal(t, true, ok)
|
|
err = dr.RecoverAccountsFromMnemonic(ctx, constant.TestMnemonic, "", numAccounts)
|
|
require.NoError(t, err)
|
|
expectedKeys, err := dr.FetchValidatingPublicKeys(ctx)
|
|
require.NoError(t, err)
|
|
|
|
t.Run("returns proper data with existing keystores", func(t *testing.T) {
|
|
resp, err := s.ListKeystores(context.Background(), &empty.Empty{})
|
|
require.NoError(t, err)
|
|
require.Equal(t, numAccounts, len(resp.Keystores))
|
|
for i := 0; i < numAccounts; i++ {
|
|
require.DeepEqual(t, expectedKeys[i][:], resp.Keystores[i].ValidatingPubkey)
|
|
require.Equal(
|
|
t,
|
|
fmt.Sprintf(derived.ValidatingKeyDerivationPathTemplate, i),
|
|
resp.Keystores[i].DerivationPath,
|
|
)
|
|
}
|
|
})
|
|
}
|