mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 02:31:19 +00:00
df694aad71
* moving voluntary exit command to prysmctl * fixing linting * fixing imports * removing unused import: * refactoring and adding a new unit test * rolling back some changes * fixing parameters * fixing tests * adding to main prysm ctl * refactoring how wallet function works and ux to validator exit * adding interop support * fixing bazel build * fixing if statement * fixing beaconcha.in printout * fixing web3signer bug, missing signing slot info * fixing deep source issues * fixing bazel package visibility for prysmctl * gaz Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
95 lines
3.0 KiB
Go
95 lines
3.0 KiB
Go
package accounts
|
|
|
|
import (
|
|
"flag"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
"github.com/prysmaticlabs/prysm/v3/cmd/validator/flags"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
|
"github.com/prysmaticlabs/prysm/v3/validator/accounts"
|
|
"github.com/prysmaticlabs/prysm/v3/validator/keymanager"
|
|
"github.com/prysmaticlabs/prysm/v3/validator/keymanager/local"
|
|
"github.com/prysmaticlabs/prysm/v3/validator/node"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
func TestWalletWithKeymanager(t *testing.T) {
|
|
walletDir, passwordsDir, passwordFilePath := setupWalletAndPasswordsDir(t)
|
|
keysDir := filepath.Join(t.TempDir(), "keysDir")
|
|
require.NoError(t, os.MkdirAll(keysDir, os.ModePerm))
|
|
|
|
cliCtx := setupWalletCtx(t, &testWalletConfig{
|
|
walletDir: walletDir,
|
|
passwordsDir: passwordsDir,
|
|
keysDir: keysDir,
|
|
keymanagerKind: keymanager.Local,
|
|
walletPasswordFile: passwordFilePath,
|
|
accountPasswordFile: passwordFilePath,
|
|
})
|
|
|
|
opts := []accounts.Option{
|
|
accounts.WithWalletDir(walletDir),
|
|
accounts.WithKeymanagerType(keymanager.Local),
|
|
accounts.WithWalletPassword(password),
|
|
}
|
|
acc, err := accounts.NewCLIManager(opts...)
|
|
require.NoError(t, err)
|
|
w, err := acc.WalletCreate(cliCtx.Context)
|
|
require.NoError(t, err)
|
|
newKm, err := local.NewKeymanager(
|
|
cliCtx.Context,
|
|
&local.SetupConfig{
|
|
Wallet: w,
|
|
ListenForChanges: false,
|
|
},
|
|
)
|
|
require.NoError(t, err)
|
|
|
|
// Make sure there are no accounts at the start.
|
|
accNames, err := newKm.ValidatingAccountNames()
|
|
require.NoError(t, err)
|
|
require.Equal(t, len(accNames), 0)
|
|
|
|
// Create 2 keys.
|
|
createKeystore(t, keysDir)
|
|
time.Sleep(time.Second)
|
|
createKeystore(t, keysDir)
|
|
require.NoError(t, accountsImport(cliCtx))
|
|
|
|
w, k, err := walletWithKeymanager(cliCtx)
|
|
require.NoError(t, err)
|
|
keys, err := k.FetchValidatingPublicKeys(cliCtx.Context)
|
|
require.NoError(t, err)
|
|
require.Equal(t, len(keys), 2)
|
|
require.Equal(t, w.KeymanagerKind(), keymanager.Local)
|
|
}
|
|
|
|
func TestWalletWithKeymanager_web3signer(t *testing.T) {
|
|
app := cli.App{}
|
|
set := flag.NewFlagSet("test", 0)
|
|
set.String(flags.Web3SignerURLFlag.Name, "http://localhost:12345", "web3signer")
|
|
c := &cli.StringSliceFlag{
|
|
Name: "validators-external-signer-public-keys",
|
|
}
|
|
err := c.Apply(set)
|
|
require.NoError(t, err)
|
|
require.NoError(t, set.Set(flags.Web3SignerURLFlag.Name, "http://localhost:12345"))
|
|
require.NoError(t, set.Set(flags.Web3SignerPublicValidatorKeysFlag.Name, "0xa2b5aaad9c6efefe7bb9b1243a043404f3362937cfb6b31833929833173f476630ea2cfeb0d9ddf15f97ca8685948820"))
|
|
ctx := cli.NewContext(&app, set, nil)
|
|
bytes, err := hexutil.Decode("0xcf8e0d4e9587369b2301d0790347320302cc0943d5a1884560367e8208d920f2")
|
|
require.NoError(t, err)
|
|
config, err := node.Web3SignerConfig(ctx)
|
|
require.NoError(t, err)
|
|
config.GenesisValidatorsRoot = bytes
|
|
w, k, err := walletWithWeb3SignerKeymanager(ctx, config)
|
|
require.NoError(t, err)
|
|
keys, err := k.FetchValidatingPublicKeys(ctx.Context)
|
|
require.NoError(t, err)
|
|
require.Equal(t, len(keys), 1)
|
|
require.Equal(t, w.KeymanagerKind(), keymanager.Web3Signer)
|
|
}
|