diff options
author | Anthony Towns <aj@erisian.com.au> | 2021-03-28 00:07:49 +1000 |
---|---|---|
committer | Andrew Chow <achow101-github@achow101.com> | 2021-04-15 12:03:25 -0400 |
commit | f9517e6014ccfe91d5a77e2bacca928bdce7c285 (patch) | |
tree | b5c1276c4bb1528e2a1c90c8344685cada7ecaf4 /src/test | |
parent | 1c0164544c66b691f93b3b1114eee97cbabd99b2 (diff) |
tests: clean up versionbits test
Simplify the versionbits unit test slightly to make the next set of
changes a little easier to follow.
Github-Pull: #21377
Rebased-From: 9e6b65f6fa205eee5c3b99343988adcb8d320460
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/versionbits_tests.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/test/versionbits_tests.cpp b/src/test/versionbits_tests.cpp index 7e96ef923e..b42aaff9ad 100644 --- a/src/test/versionbits_tests.cpp +++ b/src/test/versionbits_tests.cpp @@ -100,7 +100,7 @@ public: while (vpblock.size() < height) { CBlockIndex* pindex = new CBlockIndex(); pindex->nHeight = vpblock.size(); - pindex->pprev = vpblock.size() > 0 ? vpblock.back() : nullptr; + pindex->pprev = Tip(); pindex->nTime = nTime; pindex->nVersion = nVersion; pindex->BuildSkip(); @@ -110,13 +110,14 @@ public: } VersionBitsTester& TestStateSinceHeight(int height) { + const CBlockIndex* tip = Tip(); for (int i = 0; i < CHECKERS; i++) { if (InsecureRandBits(i) == 0) { - BOOST_CHECK_MESSAGE(checker[i].GetStateSinceHeightFor(vpblock.empty() ? nullptr : vpblock.back()) == height, strprintf("Test %i for StateSinceHeight", num)); - BOOST_CHECK_MESSAGE(checker_always[i].GetStateSinceHeightFor(vpblock.empty() ? nullptr : vpblock.back()) == 0, strprintf("Test %i for StateSinceHeight (always active)", num)); + BOOST_CHECK_MESSAGE(checker[i].GetStateSinceHeightFor(tip) == height, strprintf("Test %i for StateSinceHeight", num)); + BOOST_CHECK_MESSAGE(checker_always[i].GetStateSinceHeightFor(tip) == 0, strprintf("Test %i for StateSinceHeight (always active)", num)); // never active may go from DEFINED -> FAILED at the first period - const auto never_height = checker_never[i].GetStateSinceHeightFor(vpblock.empty() ? nullptr : vpblock.back()); + const auto never_height = checker_never[i].GetStateSinceHeightFor(tip); BOOST_CHECK_MESSAGE(never_height == 0 || never_height == checker_never[i].Period(paramsDummy), strprintf("Test %i for StateSinceHeight (never active)", num)); } } @@ -125,9 +126,9 @@ public: } VersionBitsTester& TestState(ThresholdState exp) { + const CBlockIndex* pindex = Tip(); for (int i = 0; i < CHECKERS; i++) { if (InsecureRandBits(i) == 0) { - const CBlockIndex* pindex = vpblock.empty() ? nullptr : vpblock.back(); ThresholdState got = checker[i].GetStateFor(pindex); ThresholdState got_always = checker_always[i].GetStateFor(pindex); ThresholdState got_never = checker_never[i].GetStateFor(pindex); @@ -149,7 +150,7 @@ public: VersionBitsTester& TestActive() { return TestState(ThresholdState::ACTIVE); } VersionBitsTester& TestFailed() { return TestState(ThresholdState::FAILED); } - CBlockIndex * Tip() { return vpblock.size() ? vpblock.back() : nullptr; } + CBlockIndex* Tip() { return vpblock.empty() ? nullptr : vpblock.back(); } }; BOOST_FIXTURE_TEST_SUITE(versionbits_tests, TestingSetup) @@ -217,7 +218,10 @@ BOOST_AUTO_TEST_CASE(versionbits_test) .Mine(6000, TestTime(20000), 0).TestFailed().TestStateSinceHeight(6000) .Mine(7000, TestTime(20000), 0x100).TestFailed().TestStateSinceHeight(6000); } +} +BOOST_AUTO_TEST_CASE(versionbits_sanity) +{ // Sanity checks of version bit deployments const auto chainParams = CreateChainParams(*m_node.args, CBaseChainParams::MAIN); const Consensus::Params &mainnetParams = chainParams->GetConsensus(); @@ -271,7 +275,7 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus int64_t nTime = nStartTime; - CBlockIndex *lastBlock = nullptr; + const CBlockIndex *lastBlock = nullptr; // Before MedianTimePast of the chain has crossed nStartTime, the bit // should not be set. |