mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
5a66807989
* First take at updating everything to v5 * Patch gRPC gateway to use prysm v5 Fix patch * Update go ssz --------- Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com>
79 lines
2.2 KiB
Go
79 lines
2.2 KiB
Go
package accounts
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
|
"github.com/prysmaticlabs/prysm/v5/crypto/bls"
|
|
"github.com/prysmaticlabs/prysm/v5/testing/assert"
|
|
"github.com/prysmaticlabs/prysm/v5/testing/require"
|
|
"github.com/prysmaticlabs/prysm/v5/validator/keymanager"
|
|
"github.com/prysmaticlabs/prysm/v5/validator/keymanager/local"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
func TestDelete(t *testing.T) {
|
|
hook := logTest.NewGlobal()
|
|
ctx := context.Background()
|
|
// import keys
|
|
numAccounts := 5
|
|
keystores := make([]*keymanager.Keystore, numAccounts)
|
|
passwords := make([]string, numAccounts)
|
|
for i := 0; i < numAccounts; i++ {
|
|
keystores[i] = createRandomKeystore(t, password)
|
|
passwords[i] = password
|
|
}
|
|
pubkey1, err := hexutil.Decode("0x" + keystores[0].Pubkey)
|
|
require.NoError(t, err)
|
|
p1, err := bls.PublicKeyFromBytes(pubkey1)
|
|
require.NoError(t, err)
|
|
pubkey2, err := hexutil.Decode("0x" + keystores[1].Pubkey)
|
|
require.NoError(t, err)
|
|
p2, err := bls.PublicKeyFromBytes(pubkey2)
|
|
require.NoError(t, err)
|
|
|
|
walletDir, passwordsDir, walletPasswordFile := setupWalletAndPasswordsDir(t)
|
|
cliCtx := setupWalletCtx(t, &testWalletConfig{
|
|
walletDir: walletDir,
|
|
passwordsDir: passwordsDir,
|
|
keymanagerKind: keymanager.Local,
|
|
walletPasswordFile: walletPasswordFile,
|
|
})
|
|
|
|
var stdin bytes.Buffer
|
|
stdin.Write([]byte("Y"))
|
|
opts := []Option{
|
|
WithWalletDir(walletDir),
|
|
WithKeymanagerType(keymanager.Local),
|
|
WithWalletPassword("Passwordz0320$"),
|
|
WithCustomReader(&stdin),
|
|
WithFilteredPubKeys([]bls.PublicKey{p1, p2}),
|
|
}
|
|
acc, err := NewCLIManager(opts...)
|
|
require.NoError(t, err)
|
|
w, err := acc.WalletCreate(cliCtx.Context)
|
|
require.NoError(t, err)
|
|
km, err := local.NewKeymanager(
|
|
cliCtx.Context,
|
|
&local.SetupConfig{
|
|
Wallet: w,
|
|
ListenForChanges: false,
|
|
},
|
|
)
|
|
require.NoError(t, err)
|
|
acc.keymanager = km
|
|
|
|
_, err = km.ImportKeystores(cliCtx.Context, keystores, passwords)
|
|
require.NoError(t, err)
|
|
|
|
// test delete
|
|
err = acc.Delete(ctx)
|
|
require.NoError(t, err)
|
|
keys, err := km.FetchValidatingPublicKeys(cliCtx.Context)
|
|
require.NoError(t, err)
|
|
require.Equal(t, len(keys), 3)
|
|
assert.LogsContain(t, hook, "Attempted to delete accounts.")
|
|
}
|