Browse Source

Fix importmulti returning rescan errors for wrong keys

Bug was a missing ++i line in a new range for loop added in commit e2e2f4c
"Return errors from importmulti if complete rescans are not successful"

Github-Pull: #9829
Rebased-From: 306bd72157
0.14
Russell Yanofsky 8 years ago committed by Wladimir J. van der Laan
parent
commit
ad24256a65
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 1
      src/wallet/rpcdump.cpp
  2. 17
      src/wallet/test/wallet_tests.cpp

1
src/wallet/rpcdump.cpp

@ -1098,6 +1098,7 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
result.pushKV("error", JSONRPCError(RPC_MISC_ERROR, strprintf("Failed to rescan before time %d, transactions may be missing.", scannedRange->GetBlockTimeMax()))); result.pushKV("error", JSONRPCError(RPC_MISC_ERROR, strprintf("Failed to rescan before time %d, transactions may be missing.", scannedRange->GetBlockTimeMax())));
response.push_back(std::move(result)); response.push_back(std::move(result));
} }
++i;
} }
} }
} }

17
src/wallet/test/wallet_tests.cpp

@ -395,24 +395,35 @@ BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup)
BOOST_CHECK_EQUAL(wallet.GetImmatureBalance(), 50 * COIN); BOOST_CHECK_EQUAL(wallet.GetImmatureBalance(), 50 * COIN);
} }
// Verify importmulti RPC returns failure for a key whose creation time is
// before the missing block, and success for a key whose creation time is
// after.
{ {
CWallet wallet; CWallet wallet;
CWallet *backup = ::pwalletMain; CWallet *backup = ::pwalletMain;
::pwalletMain = &wallet; ::pwalletMain = &wallet;
UniValue keys;
keys.setArray();
UniValue key; UniValue key;
key.setObject(); key.setObject();
key.pushKV("scriptPubKey", HexStr(GetScriptForRawPubKey(coinbaseKey.GetPubKey()))); key.pushKV("scriptPubKey", HexStr(GetScriptForRawPubKey(coinbaseKey.GetPubKey())));
key.pushKV("timestamp", 0); key.pushKV("timestamp", 0);
key.pushKV("internal", UniValue(true)); key.pushKV("internal", UniValue(true));
UniValue keys; keys.push_back(key);
keys.setArray(); key.clear();
key.setObject();
CKey futureKey;
futureKey.MakeNewKey(true);
key.pushKV("scriptPubKey", HexStr(GetScriptForRawPubKey(futureKey.GetPubKey())));
key.pushKV("timestamp", newTip->GetBlockTimeMax() + 7200);
key.pushKV("internal", UniValue(true));
keys.push_back(key); keys.push_back(key);
JSONRPCRequest request; JSONRPCRequest request;
request.params.setArray(); request.params.setArray();
request.params.push_back(keys); request.params.push_back(keys);
UniValue response = importmulti(request); UniValue response = importmulti(request);
BOOST_CHECK_EQUAL(response.write(), strprintf("[{\"success\":false,\"error\":{\"code\":-1,\"message\":\"Failed to rescan before time %d, transactions may be missing.\"}}]", newTip->GetBlockTimeMax())); BOOST_CHECK_EQUAL(response.write(), strprintf("[{\"success\":false,\"error\":{\"code\":-1,\"message\":\"Failed to rescan before time %d, transactions may be missing.\"}},{\"success\":true}]", newTip->GetBlockTimeMax()));
::pwalletMain = backup; ::pwalletMain = backup;
} }
} }

Loading…
Cancel
Save