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:
dv8silencer
2020-11-22 22:08:07 -06:00
committed by GitHub
parent 658dd95313
commit f871e1f3ef
2 changed files with 28 additions and 1 deletions

View File

@@ -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

View File

@@ -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)