mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Give error message if trying to import into non-imported wallet (#7913)
Co-authored-by: dv8silencer <15720668+dv8silencer@users.noreply.github.com> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
This commit is contained in:
@@ -105,7 +105,7 @@ func ImportAccountsCli(cliCtx *cli.Context) error {
|
||||
}
|
||||
k, ok := km.(*imported.Keymanager)
|
||||
if !ok {
|
||||
return errors.Wrap(err, "Only imported wallets can import more keystores")
|
||||
return errors.New("Only imported wallets can import more keystores")
|
||||
}
|
||||
|
||||
// Check if the user wishes to import a one-off, private key directly
|
||||
|
||||
@@ -141,6 +141,33 @@ func TestImport_DuplicateKeys(t *testing.T) {
|
||||
assert.Equal(t, 1, len(keys))
|
||||
}
|
||||
|
||||
// TestImport_NonImportedWallet is a regression test that ensures non-silent failure when importing to non-imported wallets
|
||||
func TestImport_NonImportedWallet(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.Derived,
|
||||
walletPasswordFile: passwordFilePath,
|
||||
})
|
||||
_, err := CreateWalletWithKeymanager(cliCtx.Context, &CreateWalletConfig{
|
||||
WalletCfg: &wallet.Config{
|
||||
WalletDir: walletDir,
|
||||
KeymanagerKind: keymanager.Derived,
|
||||
WalletPassword: password,
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
// Create a key
|
||||
createKeystore(t, keysDir)
|
||||
require.ErrorContains(t, "Only imported wallets", ImportAccountsCli(cliCtx))
|
||||
}
|
||||
|
||||
func TestImport_Noninteractive_RandomName(t *testing.T) {
|
||||
imported.ResetCaches()
|
||||
walletDir, passwordsDir, passwordFilePath := setupWalletAndPasswordsDir(t)
|
||||
|
||||
Reference in New Issue
Block a user