Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/wallet_tests.cpp
Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | // file. | ||||
oldTip, nullptr, reserver)); | oldTip, nullptr, reserver)); | ||||
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", WalletDatabase::CreateDummy()); | std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>( | ||||
AddWallet(&wallet); | Params(), "dummy", WalletDatabase::CreateDummy()); | ||||
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)); | ||||
RemoveWallet(&wallet); | 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 21 Lines | BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
std::string backup_file = | std::string backup_file = | ||||
(SetDataDir("importwallet_rescan") / "wallet.backup").string(); | (SetDataDir("importwallet_rescan") / "wallet.backup").string(); | ||||
// Import key into wallet and call dumpwallet to create backup file. | // Import key into wallet and call dumpwallet to create backup file. | ||||
{ | { | ||||
CWallet wallet(Params(), "dummy", WalletDatabase::CreateDummy()); | std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>( | ||||
LOCK(wallet.cs_wallet); | Params(), "dummy", WalletDatabase::CreateDummy()); | ||||
wallet.mapKeyMetadata[coinbaseKey.GetPubKey().GetID()].nCreateTime = | LOCK(wallet->cs_wallet); | ||||
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(backup_file); | request.params.push_back(backup_file); | ||||
AddWallet(&wallet); | AddWallet(wallet); | ||||
::dumpwallet(GetConfig(), request); | ::dumpwallet(GetConfig(), request); | ||||
RemoveWallet(&wallet); | 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", WalletDatabase::CreateDummy()); | std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>( | ||||
Params(), "dummy", WalletDatabase::CreateDummy()); | |||||
JSONRPCRequest request; | JSONRPCRequest request; | ||||
request.params.setArray(); | request.params.setArray(); | ||||
request.params.push_back(backup_file); | request.params.push_back(backup_file); | ||||
AddWallet(&wallet); | AddWallet(wallet); | ||||
::importwallet(GetConfig(), request); | ::importwallet(GetConfig(), request); | ||||
RemoveWallet(&wallet); | 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); | ||||
} | } | ||||
} | } | ||||
SetMockTime(0); | SetMockTime(0); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 195 Lines • Show Last 20 Lines |