@@ -100,7 +100,7 @@ class VersionBitsTester
100
100
while (vpblock.size () < height) {
101
101
CBlockIndex* pindex = new CBlockIndex ();
102
102
pindex->nHeight = vpblock.size ();
103
- pindex->pprev = vpblock. size () > 0 ? vpblock. back () : nullptr ;
103
+ pindex->pprev = Tip () ;
104
104
pindex->nTime = nTime;
105
105
pindex->nVersion = nVersion;
106
106
pindex->BuildSkip ();
@@ -110,13 +110,14 @@ class VersionBitsTester
110
110
}
111
111
112
112
VersionBitsTester& TestStateSinceHeight (int height) {
113
+ const CBlockIndex* tip = Tip ();
113
114
for (int i = 0 ; i < CHECKERS; i++) {
114
115
if (InsecureRandBits (i) == 0 ) {
115
- BOOST_CHECK_MESSAGE (checker[i].GetStateSinceHeightFor (vpblock. empty () ? nullptr : vpblock. back () ) == height, strprintf (" Test %i for StateSinceHeight" , num));
116
- BOOST_CHECK_MESSAGE (checker_always[i].GetStateSinceHeightFor (vpblock. empty () ? nullptr : vpblock. back () ) == 0 , strprintf (" Test %i for StateSinceHeight (always active)" , num));
116
+ BOOST_CHECK_MESSAGE (checker[i].GetStateSinceHeightFor (tip ) == height, strprintf (" Test %i for StateSinceHeight" , num));
117
+ BOOST_CHECK_MESSAGE (checker_always[i].GetStateSinceHeightFor (tip ) == 0 , strprintf (" Test %i for StateSinceHeight (always active)" , num));
117
118
118
119
// never active may go from DEFINED -> FAILED at the first period
119
- const auto never_height = checker_never[i].GetStateSinceHeightFor (vpblock. empty () ? nullptr : vpblock. back () );
120
+ const auto never_height = checker_never[i].GetStateSinceHeightFor (tip );
120
121
BOOST_CHECK_MESSAGE (never_height == 0 || never_height == checker_never[i].Period (paramsDummy), strprintf (" Test %i for StateSinceHeight (never active)" , num));
121
122
}
122
123
}
@@ -125,9 +126,9 @@ class VersionBitsTester
125
126
}
126
127
127
128
VersionBitsTester& TestState (ThresholdState exp) {
129
+ const CBlockIndex* pindex = Tip ();
128
130
for (int i = 0 ; i < CHECKERS; i++) {
129
131
if (InsecureRandBits (i) == 0 ) {
130
- const CBlockIndex* pindex = vpblock.empty () ? nullptr : vpblock.back ();
131
132
ThresholdState got = checker[i].GetStateFor (pindex);
132
133
ThresholdState got_always = checker_always[i].GetStateFor (pindex);
133
134
ThresholdState got_never = checker_never[i].GetStateFor (pindex);
@@ -149,7 +150,7 @@ class VersionBitsTester
149
150
VersionBitsTester& TestActive () { return TestState (ThresholdState::ACTIVE); }
150
151
VersionBitsTester& TestFailed () { return TestState (ThresholdState::FAILED); }
151
152
152
- CBlockIndex * Tip () { return vpblock.size () ? vpblock.back () : nullptr ; }
153
+ CBlockIndex* Tip () { return vpblock.empty () ? nullptr : vpblock.back (); }
153
154
};
154
155
155
156
BOOST_FIXTURE_TEST_SUITE (versionbits_tests, TestingSetup)
@@ -217,7 +218,10 @@ BOOST_AUTO_TEST_CASE(versionbits_test)
217
218
.Mine (6000 , TestTime (20000 ), 0 ).TestFailed ().TestStateSinceHeight (6000 )
218
219
.Mine (7000 , TestTime (20000 ), 0x100 ).TestFailed ().TestStateSinceHeight (6000 );
219
220
}
221
+ }
220
222
223
+ BOOST_AUTO_TEST_CASE (versionbits_sanity)
224
+ {
221
225
// Sanity checks of version bit deployments
222
226
const auto chainParams = CreateChainParams (*m_node.args , CBaseChainParams::MAIN);
223
227
const Consensus::Params &mainnetParams = chainParams->GetConsensus ();
@@ -271,7 +275,7 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus
271
275
272
276
int64_t nTime = nStartTime;
273
277
274
- CBlockIndex *lastBlock = nullptr ;
278
+ const CBlockIndex *lastBlock = nullptr ;
275
279
276
280
// Before MedianTimePast of the chain has crossed nStartTime, the bit
277
281
// should not be set.
0 commit comments