@@ -107,20 +107,21 @@ BOOST_FIXTURE_TEST_CASE(chainstate_update_tip, TestChain100Setup)
107
107
108
108
curr_tip = ::g_best_block;
109
109
110
- CChainState* background_cs;
111
-
112
110
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
+ }
116
117
}
117
- }
118
- BOOST_CHECK (background_cs) ;
118
+ assert ( false );
119
+ }()} ;
119
120
120
121
// Create a block to append to the validation chain.
121
122
std::vector<CMutableTransaction> noTxns;
122
123
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);
124
125
auto pblock = std::make_shared<const CBlock>(validation_block);
125
126
BlockValidationState state;
126
127
CBlockIndex* pindex = nullptr ;
@@ -133,15 +134,15 @@ BOOST_FIXTURE_TEST_CASE(chainstate_update_tip, TestChain100Setup)
133
134
LOCK (::cs_main);
134
135
bool checked = CheckBlock (*pblock, state, chainparams.GetConsensus ());
135
136
BOOST_CHECK (checked);
136
- bool accepted = background_cs-> AcceptBlock (
137
+ bool accepted = background_cs. AcceptBlock (
137
138
pblock, state, &pindex, true , nullptr , &newblock);
138
139
BOOST_CHECK (accepted);
139
140
}
140
141
// UpdateTip is called here
141
- bool block_added = background_cs-> ActivateBestChain (state, pblock);
142
+ bool block_added = background_cs. ActivateBestChain (state, pblock);
142
143
143
144
// 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 ());
145
146
146
147
// g_best_block should be unchanged after adding a block to the background
147
148
// validation chain.
0 commit comments