MCPcopy Create free account
hub / github.com/ElementsProject/elements / BOOST_FIXTURE_TEST_CASE

Function BOOST_FIXTURE_TEST_CASE

src/wallet/test/wallet_tests.cpp:101–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99}
100
101BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
102{
103 // Cap last block file size, and mine new block in a new block file.
104 CBlockIndex* oldTip = m_node.chainman->ActiveChain().Tip();
105 WITH_LOCK(::cs_main, m_node.chainman->m_blockman.GetBlockFileInfo(oldTip->GetBlockPos().nFile)->nSize = MAX_BLOCKFILE_SIZE);
106 CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
107 CBlockIndex* newTip = m_node.chainman->ActiveChain().Tip();
108
109 // Verify ScanForWalletTransactions fails to read an unknown start block.
110 {
111 CWallet wallet(m_node.chain.get(), "", m_args, CreateDummyWalletDatabase());
112 {
113 LOCK(wallet.cs_wallet);
114 wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
115 wallet.SetLastBlockProcessed(m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash());
116 }
117 AddKey(wallet, coinbaseKey);
118 WalletRescanReserver reserver(wallet);
119 reserver.reserve();
120 CWallet::ScanResult result = wallet.ScanForWalletTransactions({} /* start_block */, 0 /* start_height */, {} /* max_height */, reserver, false /* update */);
121 BOOST_CHECK_EQUAL(result.status, CWallet::ScanResult::FAILURE);
122 BOOST_CHECK(result.last_failed_block.IsNull());
123 BOOST_CHECK(result.last_scanned_block.IsNull());
124 BOOST_CHECK(!result.last_scanned_height);
125 BOOST_CHECK_EQUAL(GetBalance(wallet).m_mine_immature[CAsset()], 0);
126 }
127
128 // Verify ScanForWalletTransactions picks up transactions in both the old
129 // and new block files.
130 {
131 CWallet wallet(m_node.chain.get(), "", m_args, CreateDummyWalletDatabase());
132 {
133 LOCK(wallet.cs_wallet);
134 wallet.SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
135 wallet.SetLastBlockProcessed(m_node.chainman->ActiveChain().Height(), m_node.chainman->ActiveChain().Tip()->GetBlockHash());
136 }
137 AddKey(wallet, coinbaseKey);
138 WalletRescanReserver reserver(wallet);
139 reserver.reserve();
140 CWallet::ScanResult result = wallet.ScanForWalletTransactions(oldTip->GetBlockHash(), oldTip->nHeight, {} /* max_height */, reserver, false /* update */);
141 BOOST_CHECK_EQUAL(result.status, CWallet::ScanResult::SUCCESS);
142 BOOST_CHECK(result.last_failed_block.IsNull());
143 BOOST_CHECK_EQUAL(result.last_scanned_block, newTip->GetBlockHash());
144 BOOST_CHECK_EQUAL(*result.last_scanned_height, newTip->nHeight);
145 BOOST_CHECK_EQUAL(GetBalance(wallet).m_mine_immature[CAsset()], 100 * COIN);
146 }
147
148 // Prune the older block file.
149 int file_number;
150 {
151 LOCK(cs_main);
152 file_number = oldTip->GetBlockPos().nFile;
153 Assert(m_node.chainman)->m_blockman.PruneOneBlockFile(file_number);
154 }
155 UnlinkPrunedFiles({file_number});
156
157 // Verify ScanForWalletTransactions only picks transactions in the new block
158 // file.

Callers

nothing calls this directly

Calls 15

GetScriptForRawPubKeyFunction · 0.85
AddKeyFunction · 0.85
GetBalanceFunction · 0.85
CAssetClass · 0.85
UnlinkPrunedFilesFunction · 0.85
AddWalletFunction · 0.85
importmultiFunction · 0.85
RemoveWalletFunction · 0.85
SetMockTimeFunction · 0.85
PathToStringFunction · 0.85
dumpwalletFunction · 0.85

Tested by

no test coverage detected