Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/wallet_tests.cpp
Show First 20 Lines • Show All 469 Lines • ▼ Show 20 Lines | BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
// Verify ScanForWalletTransactions picks up transactions in both the old | // Verify ScanForWalletTransactions picks up transactions in both the old | ||||
// and new block files. | // and new block files. | ||||
{ | { | ||||
CWallet wallet(Params()); | CWallet wallet(Params()); | ||||
AddKey(wallet, coinbaseKey); | AddKey(wallet, coinbaseKey); | ||||
BOOST_CHECK_EQUAL(nullBlock, | WalletRescanReserver reserver(&wallet); | ||||
wallet.ScanForWalletTransactions(oldTip, nullptr)); | reserver.reserve(); | ||||
BOOST_CHECK_EQUAL(nullBlock, wallet.ScanForWalletTransactions( | |||||
oldTip, nullptr, reserver)); | |||||
BOOST_CHECK_EQUAL(wallet.GetImmatureBalance(), 100 * COIN); | BOOST_CHECK_EQUAL(wallet.GetImmatureBalance(), 100 * COIN); | ||||
} | } | ||||
// Prune the older block file. | // Prune the older block file. | ||||
PruneOneBlockFile(oldTip->GetBlockPos().nFile); | PruneOneBlockFile(oldTip->GetBlockPos().nFile); | ||||
UnlinkPrunedFiles({oldTip->GetBlockPos().nFile}); | UnlinkPrunedFiles({oldTip->GetBlockPos().nFile}); | ||||
// Verify ScanForWalletTransactions only picks transactions in the new block | // Verify ScanForWalletTransactions only picks transactions in the new block | ||||
// file. | // file. | ||||
{ | { | ||||
CWallet wallet(Params()); | CWallet wallet(Params()); | ||||
AddKey(wallet, coinbaseKey); | AddKey(wallet, coinbaseKey); | ||||
BOOST_CHECK_EQUAL(oldTip, | WalletRescanReserver reserver(&wallet); | ||||
wallet.ScanForWalletTransactions(oldTip, nullptr)); | reserver.reserve(); | ||||
BOOST_CHECK_EQUAL(oldTip, wallet.ScanForWalletTransactions( | |||||
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()); | CWallet wallet(Params()); | ||||
▲ Show 20 Lines • Show All 210 Lines • ▼ Show 20 Lines | ListCoinsTestingSetup() { | ||||
GetScriptForRawPubKey(coinbaseKey.GetPubKey())); | GetScriptForRawPubKey(coinbaseKey.GetPubKey())); | ||||
::bitdb.MakeMock(); | ::bitdb.MakeMock(); | ||||
wallet.reset(new CWallet( | wallet.reset(new CWallet( | ||||
Params(), std::unique_ptr<CWalletDBWrapper>( | Params(), std::unique_ptr<CWalletDBWrapper>( | ||||
new CWalletDBWrapper(&bitdb, "wallet_test.dat")))); | new CWalletDBWrapper(&bitdb, "wallet_test.dat")))); | ||||
bool firstRun; | bool firstRun; | ||||
wallet->LoadWallet(firstRun); | wallet->LoadWallet(firstRun); | ||||
AddKey(*wallet, coinbaseKey); | AddKey(*wallet, coinbaseKey); | ||||
wallet->ScanForWalletTransactions(chainActive.Genesis(), nullptr); | WalletRescanReserver reserver(wallet.get()); | ||||
reserver.reserve(); | |||||
wallet->ScanForWalletTransactions(chainActive.Genesis(), nullptr, | |||||
reserver); | |||||
} | } | ||||
~ListCoinsTestingSetup() { | ~ListCoinsTestingSetup() { | ||||
wallet.reset(); | wallet.reset(); | ||||
::bitdb.Flush(true); | ::bitdb.Flush(true); | ||||
::bitdb.Reset(); | ::bitdb.Reset(); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 79 Lines • Show Last 20 Lines |