Browse Source

Fix importmulti bug when importing an already imported key

Github-Pull: #11483
Rebased-From: a44a215177
0.15
Pedro Branco 7 years ago committed by MarcoFalke
parent
commit
20cdc2b36c
  1. 2
      src/wallet/rpcdump.cpp
  2. 12
      test/functional/importmulti.py

2
src/wallet/rpcdump.cpp

@ -960,7 +960,7 @@ UniValue ProcessImport(CWallet * const pwallet, const UniValue& data, const int6 @@ -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;

12
test/functional/importmulti.py

@ -170,6 +170,18 @@ class ImportMultiTest (BitcoinTestFramework): @@ -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())

Loading…
Cancel
Save