diff options
author | Anthony Towns <aj@erisian.com.au> | 2021-03-28 00:07:49 +1000 |
---|---|---|
committer | Anthony Towns <aj@erisian.com.au> | 2021-04-12 10:47:42 +1000 |
commit | 9e6b65f6fa205eee5c3b99343988adcb8d320460 (patch) | |
tree | f1521b6fcb51c5dade08169b10a8bb18d545c109 /src/test/versionbits_tests.cpp | |
parent | 593274445004506c921d5d851361aefb3434d744 (diff) | |
download | bitcoin-9e6b65f6fa205eee5c3b99343988adcb8d320460.tar.xz |
tests: clean up versionbits test
Simplify the versionbits unit test slightly to make the next set of
changes a little easier to follow.
Diffstat (limited to 'src/test/versionbits_tests.cpp')
-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. |