From 1c0164544c66b691f93b3b1114eee97cbabd99b2 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sun, 28 Mar 2021 03:10:48 +1000 Subject: tests: test ComputeBlockVersion for all deployments This generalises the ComputeBlockVersion test so that it can apply to any activation parameters we might set, and checks all the parameters set for each deployment on each chain, to simultaneously ensure that the deployments we have configured work sensibly, and that the test code does not suffer bitrot in the event that all interesting deployments are buried. Github-Pull: #21377 Rebased-From: 593274445004506c921d5d851361aefb3434d744 --- src/test/versionbits_tests.cpp | 106 +++++++++++++++++++++++++++-------------- 1 file changed, 71 insertions(+), 35 deletions(-) (limited to 'src') diff --git a/src/test/versionbits_tests.cpp b/src/test/versionbits_tests.cpp index b09827ffe5..7e96ef923e 100644 --- a/src/test/versionbits_tests.cpp +++ b/src/test/versionbits_tests.cpp @@ -252,38 +252,61 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus int64_t nStartTime = params.vDeployments[dep].nStartTime; int64_t nTimeout = params.vDeployments[dep].nTimeout; - assert(nStartTime < nTimeout); + // should not be any signalling for first block + BOOST_CHECK_EQUAL(ComputeBlockVersion(nullptr, params), VERSIONBITS_TOP_BITS); + + // always active deployments shouldn't need to be tested further + if (nStartTime == Consensus::BIP9Deployment::ALWAYS_ACTIVE) return; + + BOOST_REQUIRE(nStartTime < nTimeout); + BOOST_REQUIRE(nStartTime >= 0); + BOOST_REQUIRE(nTimeout <= std::numeric_limits::max() || nTimeout == Consensus::BIP9Deployment::NO_TIMEOUT); + BOOST_REQUIRE(0 <= bit && bit < 32); + BOOST_REQUIRE(((1 << bit) & VERSIONBITS_TOP_MASK) == 0); // In the first chain, test that the bit is set by CBV until it has failed. // In the second chain, test the bit is set by CBV while STARTED and // LOCKED-IN, and then no longer set while ACTIVE. VersionBitsTester firstChain, secondChain; - // Start generating blocks before nStartTime - int64_t nTime = nStartTime - 1; + int64_t nTime = nStartTime; - // Before MedianTimePast of the chain has crossed nStartTime, the bit - // should not be set. CBlockIndex *lastBlock = nullptr; - lastBlock = firstChain.Mine(params.nMinerConfirmationWindow, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip(); - BOOST_CHECK_EQUAL(ComputeBlockVersion(lastBlock, params) & (1<GetConsensus(), Consensus::DEPLOYMENT_TESTDUMMY); + // check that any deployment on any chain can conceivably reach both + // ACTIVE and FAILED states in roughly the way we expect + for (const auto& chain_name : {CBaseChainParams::MAIN, CBaseChainParams::TESTNET, CBaseChainParams::SIGNET, CBaseChainParams::REGTEST}) { + const auto chainParams = CreateChainParams(*m_node.args, chain_name); + for (int i = 0; i < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++i) { + check_computeblockversion(chainParams->GetConsensus(), static_cast(i)); + } + } } BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3