Skip to content

Commit 8df7eee

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#23132: test: Change background_cs from pointer to reference in validation_chainstate_tests
fa4d0aa test: * -> & (MarcoFalke) Pull request description: 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#23101 Can be reviewed with --ignore-all-space. ACKs for top commit: practicalswift: cr ACK fa4d0aa jamesob: ACK bitcoin/bitcoin@fa4d0aa hebasto: ACK fa4d0aa, tested on Linux Mint 20.2 (x86_64) by merging this PR on top of the current master. Tree-SHA512: 93a0d8859201f7074bea52fab8f6701409148bc50cfbb142cacfa6c991fc12c07584df04fead645f11703883df99535423d154f9945202e1c5aff49540d9b607
2 parents fbbbc59 + fa4d0aa commit 8df7eee

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)