Skip to content

Commit 0c471a5

Browse files
ajtownsSjors
authored andcommitted
tests: check never active versionbits
1 parent 3ba9283 commit 0c471a5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/test/versionbits_tests.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ class TestAlwaysActiveConditionChecker : public TestConditionChecker
5050
int64_t BeginTime(const Consensus::Params& params) const override { return Consensus::BIP9Deployment::ALWAYS_ACTIVE; }
5151
};
5252

53+
class TestNeverActiveConditionChecker : public TestConditionChecker
54+
{
55+
public:
56+
int64_t BeginTime(const Consensus::Params& params) const override { return 0; }
57+
int64_t EndTime(const Consensus::Params& params) const override { return 1230768000; }
58+
};
59+
5360
#define CHECKERS 6
5461

5562
class VersionBitsTester
@@ -63,6 +70,8 @@ class VersionBitsTester
6370
TestConditionChecker checker[CHECKERS];
6471
// Another 6 that assume always active activation
6572
TestAlwaysActiveConditionChecker checker_always[CHECKERS];
73+
// Another 6 that assume never active activation
74+
TestNeverActiveConditionChecker checker_never[CHECKERS];
6675

6776
// Test counter (to identify failures)
6877
int num;
@@ -77,6 +86,7 @@ class VersionBitsTester
7786
for (unsigned int i = 0; i < CHECKERS; i++) {
7887
checker[i] = TestConditionChecker();
7988
checker_always[i] = TestAlwaysActiveConditionChecker();
89+
checker_never[i] = TestNeverActiveConditionChecker();
8090
}
8191
vpblock.clear();
8292
return *this;
@@ -104,6 +114,10 @@ class VersionBitsTester
104114
if (InsecureRandBits(i) == 0) {
105115
BOOST_CHECK_MESSAGE(checker[i].GetStateSinceHeightFor(vpblock.empty() ? nullptr : vpblock.back()) == height, strprintf("Test %i for StateSinceHeight", num));
106116
BOOST_CHECK_MESSAGE(checker_always[i].GetStateSinceHeightFor(vpblock.empty() ? nullptr : vpblock.back()) == 0, strprintf("Test %i for StateSinceHeight (always active)", num));
117+
118+
// never active may go from DEFINED -> FAILED at the first period
119+
const auto never_height = checker_never[i].GetStateSinceHeightFor(vpblock.empty() ? nullptr : vpblock.back());
120+
BOOST_CHECK_MESSAGE(never_height == 0 || never_height == checker_never[i].Period(paramsDummy), strprintf("Test %i for StateSinceHeight (never active)", num));
107121
}
108122
}
109123
num++;
@@ -116,11 +130,13 @@ class VersionBitsTester
116130
const CBlockIndex* pindex = vpblock.empty() ? nullptr : vpblock.back();
117131
ThresholdState got = checker[i].GetStateFor(pindex);
118132
ThresholdState got_always = checker_always[i].GetStateFor(pindex);
133+
ThresholdState got_never = checker_never[i].GetStateFor(pindex);
119134
// nHeight of the next block. If vpblock is empty, the next (ie first)
120135
// block should be the genesis block with nHeight == 0.
121136
int height = pindex == nullptr ? 0 : pindex->nHeight + 1;
122137
BOOST_CHECK_MESSAGE(got == exp, strprintf("Test %i for %s height %d (got %s)", num, StateName(exp), height, StateName(got)));
123138
BOOST_CHECK_MESSAGE(got_always == ThresholdState::ACTIVE, strprintf("Test %i for ACTIVE height %d (got %s; always active case)", num, height, StateName(got_always)));
139+
BOOST_CHECK_MESSAGE(got_never == ThresholdState::DEFINED|| got_never == ThresholdState::FAILED, strprintf("Test %i for DEFINED/FAILED height %d (got %s; never active case)", num, height, StateName(got_never)));
124140
}
125141
}
126142
num++;

0 commit comments

Comments
 (0)