Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/test/wallet_tests.cpp
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | BOOST_FIXTURE_TEST_CASE(rescan, TestChain100Setup) { | ||||
// 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(); | ||||
const CBlockIndex *stop_block; | const CBlockIndex *stop_block, *failed_block; | ||||
BOOST_CHECK_EQUAL(wallet.ScanForWalletTransactions( | BOOST_CHECK_EQUAL( | ||||
oldTip, nullptr, reserver, stop_block), | wallet.ScanForWalletTransactions(oldTip, nullptr, reserver, | ||||
failed_block, stop_block), | |||||
CWallet::ScanResult::SUCCESS); | CWallet::ScanResult::SUCCESS); | ||||
BOOST_CHECK_EQUAL(stop_block, null_block); | BOOST_CHECK_EQUAL(failed_block, null_block); | ||||
BOOST_CHECK_EQUAL(stop_block, newTip); | |||||
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(); | ||||
const CBlockIndex *stop_block; | const CBlockIndex *stop_block, *failed_block; | ||||
BOOST_CHECK_EQUAL(wallet.ScanForWalletTransactions( | BOOST_CHECK_EQUAL( | ||||
oldTip, nullptr, reserver, stop_block), | wallet.ScanForWalletTransactions(oldTip, nullptr, reserver, | ||||
failed_block, stop_block), | |||||
CWallet::ScanResult::FAILURE); | CWallet::ScanResult::FAILURE); | ||||
BOOST_CHECK_EQUAL(oldTip, stop_block); | BOOST_CHECK_EQUAL(failed_block, oldTip); | ||||
BOOST_CHECK_EQUAL(stop_block, newTip); | |||||
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 223 Lines • ▼ Show 20 Lines | ListCoinsTestingSetup() { | ||||
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(); | ||||
const CBlockIndex *const null_block = nullptr; | const CBlockIndex *const null_block = nullptr; | ||||
const CBlockIndex *stop_block; | const CBlockIndex *stop_block, *failed_block; | ||||
BOOST_CHECK_EQUAL( | BOOST_CHECK_EQUAL(wallet->ScanForWalletTransactions( | ||||
wallet->ScanForWalletTransactions(ChainActive().Genesis(), nullptr, | ChainActive().Genesis(), nullptr, reserver, | ||||
reserver, stop_block), | failed_block, stop_block), | ||||
CWallet::ScanResult::SUCCESS); | CWallet::ScanResult::SUCCESS); | ||||
BOOST_CHECK_EQUAL(stop_block, null_block); | BOOST_CHECK_EQUAL(stop_block, ChainActive().Tip()); | ||||
BOOST_CHECK_EQUAL(failed_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 |