Merge bitcoin/bitcoin#23132: test: Change background_cs from pointer to reference in validation_chainstate_tests

fa4d0aacf2bbddaf1709660ffd8d520570533aa8 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 fa4d0aacf2bbddaf1709660ffd8d520570533aa8
  jamesob:
    ACK fa4d0aacf2
  hebasto:
    ACK fa4d0aacf2bbddaf1709660ffd8d520570533aa8, tested on Linux Mint 20.2 (x86_64) by merging this PR on top of the current master.

Tree-SHA512: 93a0d8859201f7074bea52fab8f6701409148bc50cfbb142cacfa6c991fc12c07584df04fead645f11703883df99535423d154f9945202e1c5aff49540d9b607
This commit is contained in:
MarcoFalke 2021-10-12 08:50:53 +02:00 committed by pasta
parent 5e0c67cb94
commit cc9d00a56d
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984

View File

@ -109,20 +109,21 @@ BOOST_FIXTURE_TEST_CASE(chainstate_update_tip, TestChain100Setup)
curr_tip = ::g_best_block;
CChainState* background_cs;
BOOST_CHECK_EQUAL(chainman.GetAll().size(), 2);
for (CChainState* cs : chainman.GetAll()) {
if (cs != &chainman.ActiveChainstate()) {
background_cs = cs;
CChainState& background_cs{*[&] {
for (CChainState* cs : chainman.GetAll()) {
if (cs != &chainman.ActiveChainstate()) {
return cs;
}
}
}
BOOST_CHECK(background_cs);
assert(false);
}()};
// Create a block to append to the validation chain.
std::vector<CMutableTransaction> noTxns;
CScript scriptPubKey = CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG;
CBlock validation_block = this->CreateBlock(noTxns, scriptPubKey, *background_cs);
CBlock validation_block = this->CreateBlock(noTxns, scriptPubKey, background_cs);
auto pblock = std::make_shared<const CBlock>(validation_block);
BlockValidationState state;
CBlockIndex* pindex = nullptr;
@ -135,15 +136,15 @@ BOOST_FIXTURE_TEST_CASE(chainstate_update_tip, TestChain100Setup)
LOCK(::cs_main);
bool checked = CheckBlock(*pblock, state, chainparams.GetConsensus());
BOOST_CHECK(checked);
bool accepted = background_cs->AcceptBlock(
bool accepted = background_cs.AcceptBlock(
pblock, state, &pindex, true, nullptr, &newblock);
BOOST_CHECK(accepted);
}
// UpdateTip is called here
bool block_added = background_cs->ActivateBestChain(state, pblock);
bool block_added = background_cs.ActivateBestChain(state, pblock);
// Ensure tip is as expected
BOOST_CHECK_EQUAL(background_cs->m_chain.Tip()->GetBlockHash(), validation_block.GetHash());
BOOST_CHECK_EQUAL(background_cs.m_chain.Tip()->GetBlockHash(), validation_block.GetHash());
// g_best_block should be unchanged after adding a block to the background
// validation chain.