Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/wallet_tests.cpp
Show First 20 Lines • Show All 248 Lines • ▼ Show 20 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)); | ||||
RemoveWallet(wallet); | RemoveWallet(wallet, std::nullopt); | ||||
} | } | ||||
} | } | ||||
// 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 40 Lines | // Import key into wallet and call dumpwallet to create backup file. | ||||
::ChainActive().Height(), | ::ChainActive().Height(), | ||||
::ChainActive().Tip()->GetBlockHash()); | ::ChainActive().Tip()->GetBlockHash()); | ||||
} | } | ||||
util::Ref context; | util::Ref context; | ||||
JSONRPCRequest request(context); | JSONRPCRequest request(context); | ||||
request.params.setArray(); | request.params.setArray(); | ||||
request.params.push_back(backup_file); | request.params.push_back(backup_file); | ||||
::dumpwallet().HandleRequest(GetConfig(), request); | ::dumpwallet().HandleRequest(GetConfig(), request); | ||||
RemoveWallet(wallet); | RemoveWallet(wallet, std::nullopt); | ||||
} | } | ||||
// 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. | ||||
{ | { | ||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>( | std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>( | ||||
chain.get(), WalletLocation(), CreateDummyWalletDatabase()); | chain.get(), WalletLocation(), CreateDummyWalletDatabase()); | ||||
LOCK(wallet->cs_wallet); | LOCK(wallet->cs_wallet); | ||||
wallet->SetupLegacyScriptPubKeyMan(); | wallet->SetupLegacyScriptPubKeyMan(); | ||||
util::Ref context; | util::Ref context; | ||||
JSONRPCRequest request(context); | JSONRPCRequest request(context); | ||||
request.params.setArray(); | request.params.setArray(); | ||||
request.params.push_back(backup_file); | request.params.push_back(backup_file); | ||||
AddWallet(wallet); | AddWallet(wallet); | ||||
wallet->SetLastBlockProcessed(::ChainActive().Height(), | wallet->SetLastBlockProcessed(::ChainActive().Height(), | ||||
::ChainActive().Tip()->GetBlockHash()); | ::ChainActive().Tip()->GetBlockHash()); | ||||
::importwallet().HandleRequest(GetConfig(), request); | ::importwallet().HandleRequest(GetConfig(), request); | ||||
RemoveWallet(wallet); | RemoveWallet(wallet, std::nullopt); | ||||
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 566 Lines • Show Last 20 Lines |