Skip to content

Commit fa4d0aa

Browse files
author
MarcoFalke
committed
test: * -> &
This changes background_cs from being a pointer to a reference to work around a gcc false warning. Also, this makes the test easier to read. Fixes bitcoin/bitcoin#23101 Can be reviewed with --ignore-all-space.
1 parent d648bbb commit fa4d0aa

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/test/validation_chainstate_tests.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,21 @@ BOOST_FIXTURE_TEST_CASE(chainstate_update_tip, TestChain100Setup)
107107

108108
curr_tip = ::g_best_block;
109109

110-
CChainState* background_cs;
111-
112110
BOOST_CHECK_EQUAL(chainman.GetAll().size(), 2);
113-
for (CChainState* cs : chainman.GetAll()) {
114-
if (cs != &chainman.ActiveChainstate()) {
115-
background_cs = cs;
111+
112+
CChainState& background_cs{*[&] {
113+
for (CChainState* cs : chainman.GetAll()) {
114+
if (cs != &chainman.ActiveChainstate()) {
115+
return cs;
116+
}
116117
}
117-
}
118-
BOOST_CHECK(background_cs);
118+
assert(false);
119+
}()};
119120

120121
// Create a block to append to the validation chain.
121122
std::vector<CMutableTransaction> noTxns;
122123
CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
123-
CBlock validation_block = this->CreateBlock(noTxns, scriptPubKey, *background_cs);
124+
CBlock validation_block = this->CreateBlock(noTxns, scriptPubKey, background_cs);
124125
auto pblock = std::make_shared<const CBlock>(validation_block);
125126
BlockValidationState state;
126127
CBlockIndex* pindex = nullptr;
@@ -133,15 +134,15 @@ BOOST_FIXTURE_TEST_CASE(chainstate_update_tip, TestChain100Setup)
133134
LOCK(::cs_main);
134135
bool checked = CheckBlock(*pblock, state, chainparams.GetConsensus());
135136
BOOST_CHECK(checked);
136-
bool accepted = background_cs->AcceptBlock(
137+
bool accepted = background_cs.AcceptBlock(
137138
pblock, state, &pindex, true, nullptr, &newblock);
138139
BOOST_CHECK(accepted);
139140
}
140141
// UpdateTip is called here
141-
bool block_added = background_cs->ActivateBestChain(state, pblock);
142+
bool block_added = background_cs.ActivateBestChain(state, pblock);
142143

143144
// Ensure tip is as expected
144-
BOOST_CHECK_EQUAL(background_cs->m_chain.Tip()->GetBlockHash(), validation_block.GetHash());
145+
BOOST_CHECK_EQUAL(background_cs.m_chain.Tip()->GetBlockHash(), validation_block.GetHash());
145146

146147
// g_best_block should be unchanged after adding a block to the background
147148
// validation chain.

0 commit comments

Comments
 (0)