mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 10:41:19 +00:00
89e279f9c8
* initial implementation of command * Add second confirmation step * Merge branch 'origin-master' into voluntary-exit-command * fix variable name * added unit tests * Merge branch 'origin-master' into voluntary-exit-command * add comment about stdin * remove backup-related code from accounts_delete_test * fix comments * move filterPublicKeysFromUserInput to new account helper * remove SkipMnemonicConfirmFlag * Merge refs/heads/master into voluntary-exit-command * Merge refs/heads/master into voluntary-exit-command * Merge refs/heads/master into voluntary-exit-command * Merge refs/heads/master into voluntary-exit-command * Merge refs/heads/master into voluntary-exit-command * Merge refs/heads/master into voluntary-exit-command * Merge refs/heads/master into voluntary-exit-command * code review fixes * removed commented-out code * Merge branch 'voluntary-exit-command' into account-commands-cleanup # Conflicts: # shared/promptutil/prompt.go * Merge branch 'origin-master' into account-commands-cleanup # Conflicts: # shared/promptutil/prompt.go # validator/accounts/v2/BUILD.bazel # validator/accounts/v2/accounts_exit.go # validator/accounts/v2/accounts_exit_test.go * Merge refs/heads/master into account-commands-cleanup
81 lines
2.6 KiB
Go
81 lines
2.6 KiB
Go
package v2
|
|
|
|
import (
|
|
"context"
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
"fmt"
|
|
"math/big"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
"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/direct"
|
|
)
|
|
|
|
func TestDeleteAccounts_Noninteractive(t *testing.T) {
|
|
walletDir, _, passwordFilePath := setupWalletAndPasswordsDir(t)
|
|
randPath, err := rand.Int(rand.Reader, big.NewInt(1000000))
|
|
require.NoError(t, err, "Could not generate random file path")
|
|
// Write a directory where we will import keys from.
|
|
keysDir := filepath.Join(testutil.TempDir(), fmt.Sprintf("/%d", randPath), "keysDir")
|
|
require.NoError(t, os.MkdirAll(keysDir, os.ModePerm))
|
|
|
|
// Create 3 keystore files in the keys directory we can then
|
|
// import from in our wallet.
|
|
k1, _ := createKeystore(t, keysDir)
|
|
time.Sleep(time.Second)
|
|
k2, _ := createKeystore(t, keysDir)
|
|
time.Sleep(time.Second)
|
|
k3, _ := createKeystore(t, keysDir)
|
|
generatedPubKeys := []string{k1.Pubkey, k2.Pubkey, k3.Pubkey}
|
|
// Only delete keys 0 and 1.
|
|
deletePublicKeys := strings.Join(generatedPubKeys[0:2], ",")
|
|
|
|
// We initialize a wallet with a direct keymanager.
|
|
cliCtx := setupWalletCtx(t, &testWalletConfig{
|
|
// Wallet configuration flags.
|
|
walletDir: walletDir,
|
|
keymanagerKind: v2keymanager.Direct,
|
|
walletPasswordFile: passwordFilePath,
|
|
accountPasswordFile: passwordFilePath,
|
|
// Flags required for ImportAccounts to work.
|
|
keysDir: keysDir,
|
|
// Flags required for DeleteAccounts to work.
|
|
deletePublicKeys: deletePublicKeys,
|
|
})
|
|
wallet, err := NewWallet(cliCtx, v2keymanager.Direct)
|
|
require.NoError(t, err)
|
|
require.NoError(t, wallet.SaveWallet())
|
|
ctx := context.Background()
|
|
encodedCfg, err := direct.MarshalConfigFile(ctx, direct.DefaultConfig())
|
|
require.NoError(t, err)
|
|
require.NoError(t, wallet.WriteKeymanagerConfigToDisk(ctx, encodedCfg))
|
|
|
|
// We attempt to import accounts.
|
|
require.NoError(t, ImportAccounts(cliCtx))
|
|
|
|
// We attempt to delete the accounts specified.
|
|
require.NoError(t, DeleteAccount(cliCtx))
|
|
|
|
keymanager, err := direct.NewKeymanager(
|
|
cliCtx,
|
|
wallet,
|
|
direct.DefaultConfig(),
|
|
)
|
|
require.NoError(t, err)
|
|
remainingAccounts, err := keymanager.FetchValidatingPublicKeys(ctx)
|
|
require.NoError(t, err)
|
|
require.Equal(t, len(remainingAccounts), 1)
|
|
remainingPublicKey, err := hex.DecodeString(k3.Pubkey)
|
|
require.NoError(t, err)
|
|
assert.DeepEqual(t, remainingAccounts[0], bytesutil.ToBytes48(remainingPublicKey))
|
|
}
|