Skip to content

Commit fa34587

Browse files
author
MarcoFalke
committed
scripted-diff: Replace EnsureChainman with Assert in unit tests
-BEGIN VERIFY SCRIPT- sed --regexp-extended -i -e 's/EnsureChainman\((m?_?node)\)\./Assert(\1.chainman)->/g' $(git grep -l EnsureChainman) -END VERIFY SCRIPT-
1 parent fa6ef70 commit fa34587

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

src/test/blockfilter_index_tests.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ bool BuildChainTestingSetup::BuildChain(const CBlockIndex* pindex,
9494
CBlockHeader header = block->GetBlockHeader();
9595

9696
BlockValidationState state;
97-
if (!EnsureChainman(m_node).ProcessNewBlockHeaders({header}, state, Params(), &pindex)) {
97+
if (!Assert(m_node.chainman)->ProcessNewBlockHeaders({header}, state, Params(), &pindex)) {
9898
return false;
9999
}
100100
}
@@ -171,7 +171,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
171171
uint256 chainA_last_header = last_header;
172172
for (size_t i = 0; i < 2; i++) {
173173
const auto& block = chainA[i];
174-
BOOST_REQUIRE(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr));
174+
BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
175175
}
176176
for (size_t i = 0; i < 2; i++) {
177177
const auto& block = chainA[i];
@@ -189,7 +189,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
189189
uint256 chainB_last_header = last_header;
190190
for (size_t i = 0; i < 3; i++) {
191191
const auto& block = chainB[i];
192-
BOOST_REQUIRE(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr));
192+
BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
193193
}
194194
for (size_t i = 0; i < 3; i++) {
195195
const auto& block = chainB[i];
@@ -220,7 +220,7 @@ BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, BuildChainTestingSetup)
220220
// Reorg back to chain A.
221221
for (size_t i = 2; i < 4; i++) {
222222
const auto& block = chainA[i];
223-
BOOST_REQUIRE(EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, nullptr));
223+
BOOST_REQUIRE(Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, nullptr));
224224
}
225225

226226
// Check that chain A and B blocks can be retrieved.

src/test/miner_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
253253
pblock->nNonce = blockinfo[i].nonce;
254254
}
255255
std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(*pblock);
256-
BOOST_CHECK(EnsureChainman(m_node).ProcessNewBlock(chainparams, shared_pblock, true, nullptr));
256+
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlock(chainparams, shared_pblock, true, nullptr));
257257
pblock->hashPrevBlock = pblock->GetHash();
258258
}
259259

src/test/util/mining.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ CTxIn MineBlock(const NodeContext& node, const CScript& coinbase_scriptPubKey)
3232
assert(block->nNonce);
3333
}
3434

35-
bool processed{EnsureChainman(node).ProcessNewBlock(Params(), block, true, nullptr)};
35+
bool processed{Assert(node.chainman)->ProcessNewBlock(Params(), block, true, nullptr)};
3636
assert(processed);
3737

3838
return CTxIn{block->vtx[0]->GetHash(), 0};

src/test/util/setup_common.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ CBlock TestChain100Setup::CreateAndProcessBlock(const std::vector<CMutableTransa
228228
while (!CheckProofOfWork(block.GetHash(), block.nBits, chainparams.GetConsensus())) ++block.nNonce;
229229

230230
std::shared_ptr<const CBlock> shared_pblock = std::make_shared<const CBlock>(block);
231-
EnsureChainman(m_node).ProcessNewBlock(chainparams, shared_pblock, true, nullptr);
231+
Assert(m_node.chainman)->ProcessNewBlock(chainparams, shared_pblock, true, nullptr);
232232

233233
CBlock result = block;
234234
return result;

src/test/validation_block_tests.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
163163
std::transform(blocks.begin(), blocks.end(), std::back_inserter(headers), [](std::shared_ptr<const CBlock> b) { return b->GetBlockHeader(); });
164164

165165
// Process all the headers so we understand the toplogy of the chain
166-
BOOST_CHECK(EnsureChainman(m_node).ProcessNewBlockHeaders(headers, state, Params()));
166+
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlockHeaders(headers, state, Params()));
167167

168168
// Connect the genesis block and drain any outstanding events
169-
BOOST_CHECK(EnsureChainman(m_node).ProcessNewBlock(Params(), std::make_shared<CBlock>(Params().GenesisBlock()), true, &ignored));
169+
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlock(Params(), std::make_shared<CBlock>(Params().GenesisBlock()), true, &ignored));
170170
SyncWithValidationInterfaceQueue();
171171

172172
// subscribe to events (this subscriber will validate event ordering)
@@ -188,13 +188,13 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
188188
FastRandomContext insecure;
189189
for (int i = 0; i < 1000; i++) {
190190
auto block = blocks[insecure.randrange(blocks.size() - 1)];
191-
EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, &ignored);
191+
Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, &ignored);
192192
}
193193

194194
// to make sure that eventually we process the full chain - do it here
195195
for (auto block : blocks) {
196196
if (block->vtx.size() == 1) {
197-
bool processed = EnsureChainman(m_node).ProcessNewBlock(Params(), block, true, &ignored);
197+
bool processed = Assert(m_node.chainman)->ProcessNewBlock(Params(), block, true, &ignored);
198198
assert(processed);
199199
}
200200
}
@@ -233,7 +233,7 @@ BOOST_AUTO_TEST_CASE(mempool_locks_reorg)
233233
{
234234
bool ignored;
235235
auto ProcessBlock = [&](std::shared_ptr<const CBlock> block) -> bool {
236-
return EnsureChainman(m_node).ProcessNewBlock(Params(), block, /* fForceProcessing */ true, /* fNewBlock */ &ignored);
236+
return Assert(m_node.chainman)->ProcessNewBlock(Params(), block, /* fForceProcessing */ true, /* fNewBlock */ &ignored);
237237
};
238238

239239
// Process all mined blocks

src/wallet/test/wallet_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
118118
// Prune the older block file.
119119
{
120120
LOCK(cs_main);
121-
EnsureChainman(m_node).PruneOneBlockFile(oldTip->GetBlockPos().nFile);
121+
Assert(m_node.chainman)->PruneOneBlockFile(oldTip->GetBlockPos().nFile);
122122
}
123123
UnlinkPrunedFiles({oldTip->GetBlockPos().nFile});
124124

@@ -144,7 +144,7 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
144144
// Prune the remaining block file.
145145
{
146146
LOCK(cs_main);
147-
EnsureChainman(m_node).PruneOneBlockFile(newTip->GetBlockPos().nFile);
147+
Assert(m_node.chainman)->PruneOneBlockFile(newTip->GetBlockPos().nFile);
148148
}
149149
UnlinkPrunedFiles({newTip->GetBlockPos().nFile});
150150

@@ -181,7 +181,7 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup)
181181
// Prune the older block file.
182182
{
183183
LOCK(cs_main);
184-
EnsureChainman(m_node).PruneOneBlockFile(oldTip->GetBlockPos().nFile);
184+
Assert(m_node.chainman)->PruneOneBlockFile(oldTip->GetBlockPos().nFile);
185185
}
186186
UnlinkPrunedFiles({oldTip->GetBlockPos().nFile});
187187

0 commit comments

Comments
 (0)