Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/wallet_tests.cpp
Show All 31 Lines | |||||
} | } | ||||
// Note: when backporting PR14957, see PR15321 and ensure both LockAnnotations | // Note: when backporting PR14957, see PR15321 and ensure both LockAnnotations | ||||
// are in place. | // are in place. | ||||
BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup) { | BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup) { | ||||
auto chain = interfaces::MakeChain(); | auto chain = interfaces::MakeChain(); | ||||
// Cap last block file size, and mine new block in a new block file. | // Cap last block file size, and mine new block in a new block file. | ||||
CBlockIndex *const nullBlock = nullptr; | const CBlockIndex *const null_block = nullptr; | ||||
CBlockIndex *oldTip = ::ChainActive().Tip(); | CBlockIndex *oldTip = ::ChainActive().Tip(); | ||||
GetBlockFileInfo(oldTip->GetBlockPos().nFile)->nSize = MAX_BLOCKFILE_SIZE; | GetBlockFileInfo(oldTip->GetBlockPos().nFile)->nSize = MAX_BLOCKFILE_SIZE; | ||||
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); | CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())); | ||||
CBlockIndex *newTip = ::ChainActive().Tip(); | CBlockIndex *newTip = ::ChainActive().Tip(); | ||||
LockAnnotation lock(::cs_main); | LockAnnotation lock(::cs_main); | ||||
auto locked_chain = chain->lock(); | auto locked_chain = chain->lock(); | ||||
// 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(), *chain, WalletLocation(), | CWallet wallet(Params(), *chain, WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
AddKey(wallet, coinbaseKey); | AddKey(wallet, coinbaseKey); | ||||
WalletRescanReserver reserver(&wallet); | WalletRescanReserver reserver(&wallet); | ||||
reserver.reserve(); | reserver.reserve(); | ||||
BOOST_CHECK_EQUAL(nullBlock, wallet.ScanForWalletTransactions( | const CBlockIndex *stop_block; | ||||
oldTip, nullptr, reserver)); | BOOST_CHECK_EQUAL(wallet.ScanForWalletTransactions( | ||||
oldTip, nullptr, reserver, stop_block), | |||||
CWallet::ScanResult::SUCCESS); | |||||
BOOST_CHECK_EQUAL(stop_block, null_block); | |||||
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(), *chain, WalletLocation(), | CWallet wallet(Params(), *chain, WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
AddKey(wallet, coinbaseKey); | AddKey(wallet, coinbaseKey); | ||||
WalletRescanReserver reserver(&wallet); | WalletRescanReserver reserver(&wallet); | ||||
reserver.reserve(); | reserver.reserve(); | ||||
BOOST_CHECK_EQUAL(oldTip, wallet.ScanForWalletTransactions( | const CBlockIndex *stop_block; | ||||
oldTip, nullptr, reserver)); | BOOST_CHECK_EQUAL(wallet.ScanForWalletTransactions( | ||||
oldTip, nullptr, reserver, stop_block), | |||||
CWallet::ScanResult::FAILURE); | |||||
BOOST_CHECK_EQUAL(oldTip, stop_block); | |||||
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. | ||||
{ | { | ||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>( | std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>( | ||||
▲ Show 20 Lines • Show All 221 Lines • ▼ Show 20 Lines | ListCoinsTestingSetup() { | ||||
GetScriptForRawPubKey(coinbaseKey.GetPubKey())); | GetScriptForRawPubKey(coinbaseKey.GetPubKey())); | ||||
wallet = std::make_unique<CWallet>(Params(), *m_chain, WalletLocation(), | wallet = std::make_unique<CWallet>(Params(), *m_chain, WalletLocation(), | ||||
WalletDatabase::CreateMock()); | WalletDatabase::CreateMock()); | ||||
bool firstRun; | bool firstRun; | ||||
wallet->LoadWallet(firstRun); | wallet->LoadWallet(firstRun); | ||||
AddKey(*wallet, coinbaseKey); | AddKey(*wallet, coinbaseKey); | ||||
WalletRescanReserver reserver(wallet.get()); | WalletRescanReserver reserver(wallet.get()); | ||||
reserver.reserve(); | reserver.reserve(); | ||||
wallet->ScanForWalletTransactions(::ChainActive().Genesis(), nullptr, | const CBlockIndex *const null_block = nullptr; | ||||
reserver); | const CBlockIndex *stop_block; | ||||
BOOST_CHECK_EQUAL( | |||||
wallet->ScanForWalletTransactions(ChainActive().Genesis(), nullptr, | |||||
reserver, stop_block), | |||||
CWallet::ScanResult::SUCCESS); | |||||
BOOST_CHECK_EQUAL(stop_block, null_block); | |||||
} | } | ||||
~ListCoinsTestingSetup() { wallet.reset(); } | ~ListCoinsTestingSetup() { wallet.reset(); } | ||||
CWalletTx &AddTx(CRecipient recipient) { | CWalletTx &AddTx(CRecipient recipient) { | ||||
CTransactionRef tx; | CTransactionRef tx; | ||||
CReserveKey reservekey(wallet.get()); | CReserveKey reservekey(wallet.get()); | ||||
Amount fee; | Amount fee; | ||||
▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines |