diff --git a/src/test/versionbits_tests.cpp b/src/test/versionbits_tests.cpp index b09827ffe5d..7e96ef923ea 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; + + CBlockIndex *lastBlock = nullptr; // 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()