aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Branco <branco@uphold.com>2017-10-11 11:12:59 +0100
committerMarcoFalke <falke.marco@gmail.com>2017-10-17 21:44:23 +0200
commit20cdc2b36c40221a0eec942a1fbdf38ca7c4e005 (patch)
tree0aa67d9446e49456d0cd4635a44f7b9e3a93e295
parent405e069d3b8c71b0f5161d9dfb2334a0bb988f2e (diff)
downloadbitcoin-20cdc2b36c40221a0eec942a1fbdf38ca7c4e005.tar.xz
Fix importmulti bug when importing an already imported key
Github-Pull: #11483 Rebased-From: a44a215177ab55b4a3b36a7980c313e908e2dd18
-rw-r--r--src/wallet/rpcdump.cpp2
-rwxr-xr-xtest/functional/importmulti.py12
2 files changed, 13 insertions, 1 deletions
diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp
index 8e0e4a8e14..6c8ff7fc3b 100644
--- a/src/wallet/rpcdump.cpp
+++ b/src/wallet/rpcdump.cpp
@@ -960,7 +960,7 @@ UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int6
pwallet->SetAddressBook(vchAddress, label, "receive");
if (pwallet->HaveKey(vchAddress)) {
- return false;
+ throw JSONRPCError(RPC_WALLET_ERROR, "The wallet already contains the private key for this address or script");
}
pwallet->mapKeyMetadata[vchAddress].nCreateTime = timestamp;
diff --git a/test/functional/importmulti.py b/test/functional/importmulti.py
index e83e85de13..783f06f912 100755
--- a/test/functional/importmulti.py
+++ b/test/functional/importmulti.py
@@ -170,6 +170,18 @@ class ImportMultiTest (BitcoinTestFramework):
assert_equal(address_assert['ismine'], True)
assert_equal(address_assert['timestamp'], timestamp)
+ self.log.info("Should not import an address with private key if is already imported")
+ result = self.nodes[1].importmulti([{
+ "scriptPubKey": {
+ "address": address['address']
+ },
+ "timestamp": "now",
+ "keys": [ self.nodes[0].dumpprivkey(address['address']) ]
+ }])
+ assert_equal(result[0]['success'], False)
+ assert_equal(result[0]['error']['code'], -4)
+ assert_equal(result[0]['error']['message'], 'The wallet already contains the private key for this address or script')
+
# Address + Private key + watchonly
self.log.info("Should not import an address with private key and with watchonly")
address = self.nodes[0].validateaddress(self.nodes[0].getnewaddress())