Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/wallet_tests.cpp
Show First 20 Lines • Show All 68 Lines • ▼ Show 20 Lines | // file. | ||||
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 | // 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 | // before the missing block, and success for a key whose creation time is | ||||
// after. | // after. | ||||
{ | { | ||||
CWallet wallet(Params(), "dummy", CWalletDBWrapper::CreateDummy()); | CWallet wallet(Params(), "dummy", CWalletDBWrapper::CreateDummy()); | ||||
vpwallets.insert(vpwallets.begin(), &wallet); | AddWallet(&wallet); | ||||
UniValue keys; | UniValue keys; | ||||
keys.setArray(); | keys.setArray(); | ||||
UniValue key; | UniValue key; | ||||
key.setObject(); | key.setObject(); | ||||
key.pushKV("scriptPubKey", | key.pushKV("scriptPubKey", | ||||
HexStr(GetScriptForRawPubKey(coinbaseKey.GetPubKey()))); | HexStr(GetScriptForRawPubKey(coinbaseKey.GetPubKey()))); | ||||
key.pushKV("timestamp", 0); | key.pushKV("timestamp", 0); | ||||
key.pushKV("internal", UniValue(true)); | key.pushKV("internal", UniValue(true)); | ||||
Show All 22 Lines | // after. | ||||
"could contain transactions pertaining to the key. As a " | "could contain transactions pertaining to the key. As a " | ||||
"result, transactions and coins using this key may not " | "result, transactions and coins using this key may not " | ||||
"appear in the wallet. This error could be caused by " | "appear in the wallet. This error could be caused by " | ||||
"pruning or data corruption (see bitcoind log for " | "pruning or data corruption (see bitcoind log for " | ||||
"details) and could be dealt with by downloading and " | "details) and could be dealt with by downloading and " | ||||
"rescanning the relevant blocks (see -reindex and " | "rescanning the relevant blocks (see -reindex and " | ||||
"-rescan options).\"}},{\"success\":true}]", | "-rescan options).\"}},{\"success\":true}]", | ||||
0, oldTip->GetBlockTimeMax(), TIMESTAMP_WINDOW)); | 0, oldTip->GetBlockTimeMax(), TIMESTAMP_WINDOW)); | ||||
vpwallets.erase(vpwallets.begin()); | RemoveWallet(&wallet); | ||||
} | } | ||||
} | } | ||||
// Verify importwallet RPC starts rescan at earliest block with timestamp | // Verify importwallet RPC starts rescan at earliest block with timestamp | ||||
// greater or equal than key birthday. Previously there was a bug where | // greater or equal than key birthday. Previously there was a bug where | ||||
// importwallet RPC would start the scan at the latest block with timestamp less | // importwallet RPC would start the scan at the latest block with timestamp less | ||||
// than or equal to key birthday. | // than or equal to key birthday. | ||||
BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup) { | BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup) { | ||||
Show All 27 Lines | // Import key into wallet and call dumpwallet to create backup file. | ||||
LOCK(wallet.cs_wallet); | LOCK(wallet.cs_wallet); | ||||
wallet.mapKeyMetadata[coinbaseKey.GetPubKey().GetID()].nCreateTime = | wallet.mapKeyMetadata[coinbaseKey.GetPubKey().GetID()].nCreateTime = | ||||
KEY_TIME; | KEY_TIME; | ||||
wallet.AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey()); | wallet.AddKeyPubKey(coinbaseKey, coinbaseKey.GetPubKey()); | ||||
JSONRPCRequest request; | JSONRPCRequest request; | ||||
request.params.setArray(); | request.params.setArray(); | ||||
request.params.push_back((pathTemp / "wallet.backup").string()); | request.params.push_back((pathTemp / "wallet.backup").string()); | ||||
vpwallets.insert(vpwallets.begin(), &wallet); | AddWallet(&wallet); | ||||
::dumpwallet(GetConfig(), request); | ::dumpwallet(GetConfig(), request); | ||||
vpwallets.erase(vpwallets.begin()); | RemoveWallet(&wallet); | ||||
} | } | ||||
// Call importwallet RPC and verify all blocks with timestamps >= BLOCK_TIME | // Call importwallet RPC and verify all blocks with timestamps >= BLOCK_TIME | ||||
// were scanned, and no prior blocks were scanned. | // were scanned, and no prior blocks were scanned. | ||||
{ | { | ||||
CWallet wallet(Params(), "dummy", CWalletDBWrapper::CreateDummy()); | CWallet wallet(Params(), "dummy", CWalletDBWrapper::CreateDummy()); | ||||
JSONRPCRequest request; | JSONRPCRequest request; | ||||
request.params.setArray(); | request.params.setArray(); | ||||
request.params.push_back((pathTemp / "wallet.backup").string()); | request.params.push_back((pathTemp / "wallet.backup").string()); | ||||
vpwallets.insert(vpwallets.begin(), &wallet); | AddWallet(&wallet); | ||||
::importwallet(GetConfig(), request); | ::importwallet(GetConfig(), request); | ||||
vpwallets.erase(vpwallets.begin()); | RemoveWallet(&wallet); | ||||
LOCK(wallet.cs_wallet); | LOCK(wallet.cs_wallet); | ||||
BOOST_CHECK_EQUAL(wallet.mapWallet.size(), 3U); | BOOST_CHECK_EQUAL(wallet.mapWallet.size(), 3U); | ||||
BOOST_CHECK_EQUAL(m_coinbase_txns.size(), 103U); | BOOST_CHECK_EQUAL(m_coinbase_txns.size(), 103U); | ||||
for (size_t i = 0; i < m_coinbase_txns.size(); ++i) { | for (size_t i = 0; i < m_coinbase_txns.size(); ++i) { | ||||
bool found = wallet.GetWalletTx(m_coinbase_txns[i]->GetId()); | bool found = wallet.GetWalletTx(m_coinbase_txns[i]->GetId()); | ||||
bool expected = i >= 100; | bool expected = i >= 100; | ||||
BOOST_CHECK_EQUAL(found, expected); | BOOST_CHECK_EQUAL(found, expected); | ||||
▲ Show 20 Lines • Show All 201 Lines • Show Last 20 Lines |