From 2e9e7f4329fc313adf9ba2394edbaf2a69b59bc1 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Sat, 27 Mar 2021 20:17:56 +1000 Subject: tests: pull ComputeBlockVersion test into its own function The intent here is to allow checking ComputeBlockVersion behaviour with each deployment, rather than only testdummy on mainnet. This commit does the trivial refactoring component of that change. Github-Pull: #21377 Rebased-From: 63879f0a4760c0c0f784029849cb5d21ee088abb --- src/test/versionbits_tests.cpp | 74 ++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 35 deletions(-) (limited to 'src/test') diff --git a/src/test/versionbits_tests.cpp b/src/test/versionbits_tests.cpp index 8841a540f2..b09827ffe5 100644 --- a/src/test/versionbits_tests.cpp +++ b/src/test/versionbits_tests.cpp @@ -242,17 +242,15 @@ BOOST_AUTO_TEST_CASE(versionbits_test) } } -BOOST_AUTO_TEST_CASE(versionbits_computeblockversion) +/** Check that ComputeBlockVersion will set the appropriate bit correctly */ +static void check_computeblockversion(const Consensus::Params& params, Consensus::DeploymentPos dep) { - // Check that ComputeBlockVersion will set the appropriate bit correctly - // on mainnet. - const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN); - const Consensus::Params &mainnetParams = chainParams->GetConsensus(); + // This implicitly uses versionbitscache, so clear it every time + versionbitscache.Clear(); - // Use the TESTDUMMY deployment for testing purposes. - int64_t bit = mainnetParams.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].bit; - int64_t nStartTime = mainnetParams.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nStartTime; - int64_t nTimeout = mainnetParams.vDeployments[Consensus::DEPLOYMENT_TESTDUMMY].nTimeout; + int64_t bit = params.vDeployments[dep].bit; + int64_t nStartTime = params.vDeployments[dep].nStartTime; + int64_t nTimeout = params.vDeployments[dep].nTimeout; assert(nStartTime < nTimeout); @@ -267,40 +265,40 @@ BOOST_AUTO_TEST_CASE(versionbits_computeblockversion) // Before MedianTimePast of the chain has crossed nStartTime, the bit // should not be set. CBlockIndex *lastBlock = nullptr; - lastBlock = firstChain.Mine(mainnetParams.nMinerConfirmationWindow, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip(); - BOOST_CHECK_EQUAL(ComputeBlockVersion(lastBlock, mainnetParams) & (1< 0) { lastBlock = firstChain.Mine(nHeight+1, nTime, VERSIONBITS_LAST_OLD_BLOCK_VERSION).Tip(); - BOOST_CHECK((ComputeBlockVersion(lastBlock, mainnetParams) & (1<GetConsensus(), Consensus::DEPLOYMENT_TESTDUMMY); +} BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3