mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
8b2b109939
* imported -> local * reverting to the state of the PR at eb1e3c3d1 * use changes from develop * del * rem patch * patch * rename to local * gazelle * add back build * imported rename * gaz * local * merge fix + remove proto changes * comment revert * build * gofmt and one new reference * gofmt pt2 * Update validator/accounts/wallet_edit.go Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * Update validator/rpc/accounts.go * rename * gaz Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> Co-authored-by: james-prysm <90280386+james-prysm@users.noreply.github.com>
78 lines
2.4 KiB
Go
78 lines
2.4 KiB
Go
package accounts
|
|
|
|
import (
|
|
"encoding/hex"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
|
"github.com/prysmaticlabs/prysm/testing/assert"
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
"github.com/prysmaticlabs/prysm/validator/accounts/wallet"
|
|
"github.com/prysmaticlabs/prysm/validator/keymanager"
|
|
"github.com/prysmaticlabs/prysm/validator/keymanager/local"
|
|
)
|
|
|
|
func TestDeleteAccounts_Noninteractive(t *testing.T) {
|
|
walletDir, _, passwordFilePath := setupWalletAndPasswordsDir(t)
|
|
// Write a directory where we will import keys from.
|
|
keysDir := filepath.Join(t.TempDir(), "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 local keymanager.
|
|
cliCtx := setupWalletCtx(t, &testWalletConfig{
|
|
// Wallet configuration flags.
|
|
walletDir: walletDir,
|
|
keymanagerKind: keymanager.Local,
|
|
walletPasswordFile: passwordFilePath,
|
|
accountPasswordFile: passwordFilePath,
|
|
// Flags required for ImportAccounts to work.
|
|
keysDir: keysDir,
|
|
// Flags required for DeleteAccounts to work.
|
|
deletePublicKeys: deletePublicKeys,
|
|
})
|
|
w, err := CreateWalletWithKeymanager(cliCtx.Context, &CreateWalletConfig{
|
|
WalletCfg: &wallet.Config{
|
|
WalletDir: walletDir,
|
|
KeymanagerKind: keymanager.Local,
|
|
WalletPassword: password,
|
|
},
|
|
})
|
|
require.NoError(t, err)
|
|
|
|
// We attempt to import accounts.
|
|
require.NoError(t, ImportAccountsCli(cliCtx))
|
|
|
|
// We attempt to delete the accounts specified.
|
|
require.NoError(t, DeleteAccountCli(cliCtx))
|
|
|
|
keymanager, err := local.NewKeymanager(
|
|
cliCtx.Context,
|
|
&local.SetupConfig{
|
|
Wallet: w,
|
|
ListenForChanges: false,
|
|
},
|
|
)
|
|
require.NoError(t, err)
|
|
remainingAccounts, err := keymanager.FetchValidatingPublicKeys(cliCtx.Context)
|
|
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))
|
|
}
|