aboutsummaryrefslogtreecommitdiff
path: root/src/test/versionbits_tests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/versionbits_tests.cpp')
-rw-r--r--src/test/versionbits_tests.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/test/versionbits_tests.cpp b/src/test/versionbits_tests.cpp
index 896840b0f3..29240a45f0 100644
--- a/src/test/versionbits_tests.cpp
+++ b/src/test/versionbits_tests.cpp
@@ -67,6 +67,7 @@ public:
class VersionBitsTester
{
+ FastRandomContext& m_rng;
// A fake blockchain
std::vector<CBlockIndex*> vpblock;
@@ -85,6 +86,8 @@ class VersionBitsTester
int num{1000};
public:
+ VersionBitsTester(FastRandomContext& rng) : m_rng{rng} {}
+
VersionBitsTester& Reset() {
// Have each group of tests be counted by the 1000s part, starting at 1000
num = num - (num % 1000) + 1000;
@@ -128,7 +131,7 @@ public:
{
const CBlockIndex* tip = Tip();
for (int i = 0; i < CHECKERS; i++) {
- if (InsecureRandBits(i) == 0) {
+ if (m_rng.randbits(i) == 0) {
BOOST_CHECK_MESSAGE(checker[i].GetStateSinceHeightFor(tip) == height, strprintf("Test %i for StateSinceHeight", num));
BOOST_CHECK_MESSAGE(checker_delayed[i].GetStateSinceHeightFor(tip) == height_delayed, strprintf("Test %i for StateSinceHeight (delayed)", num));
BOOST_CHECK_MESSAGE(checker_always[i].GetStateSinceHeightFor(tip) == 0, strprintf("Test %i for StateSinceHeight (always active)", num));
@@ -154,7 +157,7 @@ public:
const CBlockIndex* pindex = Tip();
for (int i = 0; i < CHECKERS; i++) {
- if (InsecureRandBits(i) == 0) {
+ if (m_rng.randbits(i) == 0) {
ThresholdState got = checker[i].GetStateFor(pindex);
ThresholdState got_delayed = checker_delayed[i].GetStateFor(pindex);
ThresholdState got_always = checker_always[i].GetStateFor(pindex);
@@ -190,7 +193,7 @@ BOOST_AUTO_TEST_CASE(versionbits_test)
{
for (int i = 0; i < 64; i++) {
// DEFINED -> STARTED after timeout reached -> FAILED
- VersionBitsTester().TestDefined().TestStateSinceHeight(0)
+ VersionBitsTester(m_rng).TestDefined().TestStateSinceHeight(0)
.Mine(1, TestTime(1), 0x100).TestDefined().TestStateSinceHeight(0)
.Mine(11, TestTime(11), 0x100).TestDefined().TestStateSinceHeight(0)
.Mine(989, TestTime(989), 0x100).TestDefined().TestStateSinceHeight(0)
@@ -256,8 +259,9 @@ BOOST_AUTO_TEST_CASE(versionbits_test)
}
}
+struct BlockVersionTest : BasicTestingSetup {
/** Check that ComputeBlockVersion will set the appropriate bit correctly */
-static void check_computeblockversion(VersionBitsCache& versionbitscache, const Consensus::Params& params, Consensus::DeploymentPos dep)
+void check_computeblockversion(VersionBitsCache& versionbitscache, const Consensus::Params& params, Consensus::DeploymentPos dep)
{
// Clear the cache every time
versionbitscache.Clear();
@@ -295,7 +299,7 @@ static void check_computeblockversion(VersionBitsCache& versionbitscache, const
// 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;
+ VersionBitsTester firstChain{m_rng}, secondChain{m_rng};
int64_t nTime = nStartTime;
@@ -412,8 +416,9 @@ static void check_computeblockversion(VersionBitsCache& versionbitscache, const
// Check that we don't signal after activation
BOOST_CHECK_EQUAL(versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit), 0);
}
+}; // struct BlockVersionTest
-BOOST_AUTO_TEST_CASE(versionbits_computeblockversion)
+BOOST_FIXTURE_TEST_CASE(versionbits_computeblockversion, BlockVersionTest)
{
VersionBitsCache vbcache;