Skip to content

Commit e48826a

Browse files
committed
tests: remove ComputeBlockVersion shortcut from versionbits tests
1 parent c5f3672 commit e48826a

File tree

1 file changed

+18
-23
lines changed

1 file changed

+18
-23
lines changed

src/test/versionbits_tests.cpp

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
/* Define a virtual block time, one block per 10 minutes after Nov 14 2014, 0:55:36am */
1616
static int32_t TestTime(int nHeight) { return 1415926536 + 600 * nHeight; }
1717

18-
static int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params)
19-
{
20-
return g_versionbitscache.ComputeBlockVersion(pindexPrev, params);
21-
}
22-
2318
static const std::string StateName(ThresholdState state)
2419
{
2520
switch (state) {
@@ -273,7 +268,7 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus
273268
int min_activation_height = params.vDeployments[dep].min_activation_height;
274269

275270
// should not be any signalling for first block
276-
BOOST_CHECK_EQUAL(ComputeBlockVersion(nullptr, params), VERSIONBITS_TOP_BITS);
271+
BOOST_CHECK_EQUAL(g_versionbitscache.ComputeBlockVersion(nullptr, params), VERSIONBITS_TOP_BITS);
277272

278273
// always/never active deployments shouldn't need to be tested further
279274
if (nStartTime == Consensus::BIP9Deployment::ALWAYS_ACTIVE ||
@@ -312,38 +307,38 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus
312307
// earlier time, so will transition from DEFINED to STARTED at the
313308
// end of the first period by mining blocks at nTime == 0
314309
lastBlock = firstChain.Mine(params.nMinerConfirmationWindow - 1, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
315-
BOOST_CHECK_EQUAL(ComputeBlockVersion(lastBlock, params) & (1<<bit), 0);
310+
BOOST_CHECK_EQUAL(g_versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit), 0);
316311
lastBlock = firstChain.Mine(params.nMinerConfirmationWindow, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
317-
BOOST_CHECK((ComputeBlockVersion(lastBlock, params) & (1<<bit)) != 0);
312+
BOOST_CHECK((g_versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
318313
// then we'll keep mining at nStartTime...
319314
} else {
320315
// use a time 1s earlier than start time to check we stay DEFINED
321316
--nTime;
322317

323318
// Start generating blocks before nStartTime
324319
lastBlock = firstChain.Mine(params.nMinerConfirmationWindow, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
325-
BOOST_CHECK_EQUAL(ComputeBlockVersion(lastBlock, params) & (1<<bit), 0);
320+
BOOST_CHECK_EQUAL(g_versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit), 0);
326321

327322
// Mine more blocks (4 less than the adjustment period) at the old time, and check that CBV isn't setting the bit yet.
328323
for (uint32_t i = 1; i < params.nMinerConfirmationWindow - 4; i++) {
329324
lastBlock = firstChain.Mine(params.nMinerConfirmationWindow + i, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
330-
BOOST_CHECK_EQUAL(ComputeBlockVersion(lastBlock, params) & (1<<bit), 0);
325+
BOOST_CHECK_EQUAL(g_versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit), 0);
331326
}
332327
// Now mine 5 more blocks at the start time -- MTP should not have passed yet, so
333328
// CBV should still not yet set the bit.
334329
nTime = nStartTime;
335330
for (uint32_t i = params.nMinerConfirmationWindow - 4; i <= params.nMinerConfirmationWindow; i++) {
336331
lastBlock = firstChain.Mine(params.nMinerConfirmationWindow + i, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
337-
BOOST_CHECK_EQUAL(ComputeBlockVersion(lastBlock, params) & (1<<bit), 0);
332+
BOOST_CHECK_EQUAL(g_versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit), 0);
338333
}
339334
// Next we will advance to the next period and transition to STARTED,
340335
}
341336

342337
lastBlock = firstChain.Mine(params.nMinerConfirmationWindow * 3, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
343338
// so ComputeBlockVersion should now set the bit,
344-
BOOST_CHECK((ComputeBlockVersion(lastBlock, params) & (1<<bit)) != 0);
339+
BOOST_CHECK((g_versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
345340
// and should also be using the VERSIONBITS_TOP_BITS.
346-
BOOST_CHECK_EQUAL(ComputeBlockVersion(lastBlock, params) & VERSIONBITS_TOP_MASK, VERSIONBITS_TOP_BITS);
341+
BOOST_CHECK_EQUAL(g_versionbitscache.ComputeBlockVersion(lastBlock, params) & VERSIONBITS_TOP_MASK, VERSIONBITS_TOP_BITS);
347342

348343
// Check that ComputeBlockVersion will set the bit until nTimeout
349344
nTime += 600;
@@ -352,8 +347,8 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus
352347
// These blocks are all before nTimeout is reached.
353348
while (nTime < nTimeout && blocksToMine > 0) {
354349
lastBlock = firstChain.Mine(nHeight+1, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
355-
BOOST_CHECK((ComputeBlockVersion(lastBlock, params) & (1<<bit)) != 0);
356-
BOOST_CHECK_EQUAL(ComputeBlockVersion(lastBlock, params) & VERSIONBITS_TOP_MASK, VERSIONBITS_TOP_BITS);
350+
BOOST_CHECK((g_versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
351+
BOOST_CHECK_EQUAL(g_versionbitscache.ComputeBlockVersion(lastBlock, params) & VERSIONBITS_TOP_MASK, VERSIONBITS_TOP_BITS);
357352
blocksToMine--;
358353
nTime += 600;
359354
nHeight += 1;
@@ -367,20 +362,20 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus
367362
// finish the last period before we start timing out
368363
while (nHeight % params.nMinerConfirmationWindow != 0) {
369364
lastBlock = firstChain.Mine(nHeight+1, nTime - 1, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
370-
BOOST_CHECK((ComputeBlockVersion(lastBlock, params) & (1<<bit)) != 0);
365+
BOOST_CHECK((g_versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
371366
nHeight += 1;
372367
}
373368

374369
// FAILED is only triggered at the end of a period, so CBV should be setting
375370
// the bit until the period transition.
376371
for (uint32_t i = 0; i < params.nMinerConfirmationWindow - 1; i++) {
377372
lastBlock = firstChain.Mine(nHeight+1, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
378-
BOOST_CHECK((ComputeBlockVersion(lastBlock, params) & (1<<bit)) != 0);
373+
BOOST_CHECK((g_versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
379374
nHeight += 1;
380375
}
381376
// The next block should trigger no longer setting the bit.
382377
lastBlock = firstChain.Mine(nHeight+1, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
383-
BOOST_CHECK_EQUAL(ComputeBlockVersion(lastBlock, params) & (1<<bit), 0);
378+
BOOST_CHECK_EQUAL(g_versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit), 0);
384379
}
385380

386381
// On a new chain:
@@ -391,30 +386,30 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus
391386
// Mine one period worth of blocks, and check that the bit will be on for the
392387
// next period.
393388
lastBlock = secondChain.Mine(params.nMinerConfirmationWindow, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
394-
BOOST_CHECK((ComputeBlockVersion(lastBlock, params) & (1<<bit)) != 0);
389+
BOOST_CHECK((g_versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
395390

396391
// Mine another period worth of blocks, signaling the new bit.
397392
lastBlock = secondChain.Mine(params.nMinerConfirmationWindow * 2, nTime, VERSIONBITS_TOP_BITS | (1<<bit)).Tip();
398393
// After one period of setting the bit on each block, it should have locked in.
399394
// We keep setting the bit for one more period though, until activation.
400-
BOOST_CHECK((ComputeBlockVersion(lastBlock, params) & (1<<bit)) != 0);
395+
BOOST_CHECK((g_versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
401396

402397
// Now check that we keep mining the block until the end of this period, and
403398
// then stop at the beginning of the next period.
404399
lastBlock = secondChain.Mine((params.nMinerConfirmationWindow * 3) - 1, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
405-
BOOST_CHECK((ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
400+
BOOST_CHECK((g_versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
406401
lastBlock = secondChain.Mine(params.nMinerConfirmationWindow * 3, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
407402

408403
if (lastBlock->nHeight + 1 < min_activation_height) {
409404
// check signalling continues while min_activation_height is not reached
410405
lastBlock = secondChain.Mine(min_activation_height - 1, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
411-
BOOST_CHECK((ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
406+
BOOST_CHECK((g_versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit)) != 0);
412407
// then reach min_activation_height, which was already REQUIRE'd to start a new period
413408
lastBlock = secondChain.Mine(min_activation_height, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip();
414409
}
415410

416411
// Check that we don't signal after activation
417-
BOOST_CHECK_EQUAL(ComputeBlockVersion(lastBlock, params) & (1<<bit), 0);
412+
BOOST_CHECK_EQUAL(g_versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit), 0);
418413
}
419414

420415
BOOST_AUTO_TEST_CASE(versionbits_computeblockversion)

0 commit comments

Comments
 (0)