Skip to content

Commit fa8eaee

Browse files
author
MarcoFalke
committed
test: Run versionbits_sanity for all chains
1 parent faec1e9 commit fa8eaee

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

src/test/versionbits_tests.cpp

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -255,25 +255,6 @@ BOOST_AUTO_TEST_CASE(versionbits_test)
255255
}
256256
}
257257

258-
BOOST_AUTO_TEST_CASE(versionbits_sanity)
259-
{
260-
// Sanity checks of version bit deployments
261-
const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN);
262-
const Consensus::Params &mainnetParams = chainParams->GetConsensus();
263-
for (int i=0; i<(int) Consensus::MAX_VERSION_BITS_DEPLOYMENTS; i++) {
264-
uint32_t bitmask = VersionBitsMask(mainnetParams, static_cast<Consensus::DeploymentPos>(i));
265-
// Make sure that no deployment tries to set an invalid bit.
266-
BOOST_CHECK_EQUAL(bitmask & ~(uint32_t)VERSIONBITS_TOP_MASK, bitmask);
267-
268-
// Check min_activation_height is on a retarget boundary
269-
BOOST_CHECK_EQUAL(mainnetParams.vDeployments[i].min_activation_height % mainnetParams.nMinerConfirmationWindow, 0);
270-
// Check min_activation_height is 0 for ALWAYS_ACTIVE and never active deployments
271-
if (mainnetParams.vDeployments[i].nStartTime == Consensus::BIP9Deployment::ALWAYS_ACTIVE || mainnetParams.vDeployments[i].nStartTime == Consensus::BIP9Deployment::NEVER_ACTIVE) {
272-
BOOST_CHECK_EQUAL(mainnetParams.vDeployments[i].min_activation_height, 0);
273-
}
274-
}
275-
}
276-
277258
/** Check that ComputeBlockVersion will set the appropriate bit correctly */
278259
static void check_computeblockversion(const Consensus::Params& params, Consensus::DeploymentPos dep)
279260
{
@@ -289,17 +270,26 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus
289270
BOOST_CHECK_EQUAL(ComputeBlockVersion(nullptr, params), VERSIONBITS_TOP_BITS);
290271

291272
// always/never active deployments shouldn't need to be tested further
292-
if (nStartTime == Consensus::BIP9Deployment::ALWAYS_ACTIVE) return;
293-
if (nStartTime == Consensus::BIP9Deployment::NEVER_ACTIVE) return;
273+
if (nStartTime == Consensus::BIP9Deployment::ALWAYS_ACTIVE ||
274+
nStartTime == Consensus::BIP9Deployment::NEVER_ACTIVE)
275+
{
276+
BOOST_CHECK_EQUAL(min_activation_height, 0);
277+
return;
278+
}
294279

295280
BOOST_REQUIRE(nStartTime < nTimeout);
296281
BOOST_REQUIRE(nStartTime >= 0);
297282
BOOST_REQUIRE(nTimeout <= std::numeric_limits<uint32_t>::max() || nTimeout == Consensus::BIP9Deployment::NO_TIMEOUT);
298283
BOOST_REQUIRE(0 <= bit && bit < 32);
284+
// Make sure that no deployment tries to set an invalid bit.
299285
BOOST_REQUIRE(((1 << bit) & VERSIONBITS_TOP_MASK) == 0);
300286
BOOST_REQUIRE(min_activation_height >= 0);
287+
// Check min_activation_height is on a retarget boundary
301288
BOOST_REQUIRE_EQUAL(min_activation_height % params.nMinerConfirmationWindow, 0U);
302289

290+
const uint32_t bitmask{VersionBitsMask(params, dep)};
291+
BOOST_CHECK_EQUAL(bitmask, uint32_t{1} << bit);
292+
303293
// In the first chain, test that the bit is set by CBV until it has failed.
304294
// In the second chain, test the bit is set by CBV while STARTED and
305295
// LOCKED-IN, and then no longer set while ACTIVE.

0 commit comments

Comments
 (0)