@@ -50,6 +50,13 @@ class TestAlwaysActiveConditionChecker : public TestConditionChecker
50
50
int64_t BeginTime (const Consensus::Params& params) const override { return Consensus::BIP9Deployment::ALWAYS_ACTIVE; }
51
51
};
52
52
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
+
53
60
#define CHECKERS 6
54
61
55
62
class VersionBitsTester
@@ -63,6 +70,8 @@ class VersionBitsTester
63
70
TestConditionChecker checker[CHECKERS];
64
71
// Another 6 that assume always active activation
65
72
TestAlwaysActiveConditionChecker checker_always[CHECKERS];
73
+ // Another 6 that assume never active activation
74
+ TestNeverActiveConditionChecker checker_never[CHECKERS];
66
75
67
76
// Test counter (to identify failures)
68
77
int num;
@@ -77,6 +86,7 @@ class VersionBitsTester
77
86
for (unsigned int i = 0 ; i < CHECKERS; i++) {
78
87
checker[i] = TestConditionChecker ();
79
88
checker_always[i] = TestAlwaysActiveConditionChecker ();
89
+ checker_never[i] = TestNeverActiveConditionChecker ();
80
90
}
81
91
vpblock.clear ();
82
92
return *this ;
@@ -104,6 +114,10 @@ class VersionBitsTester
104
114
if (InsecureRandBits (i) == 0 ) {
105
115
BOOST_CHECK_MESSAGE (checker[i].GetStateSinceHeightFor (vpblock.empty () ? nullptr : vpblock.back ()) == height, strprintf (" Test %i for StateSinceHeight" , num));
106
116
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));
107
121
}
108
122
}
109
123
num++;
@@ -116,11 +130,13 @@ class VersionBitsTester
116
130
const CBlockIndex* pindex = vpblock.empty () ? nullptr : vpblock.back ();
117
131
ThresholdState got = checker[i].GetStateFor (pindex);
118
132
ThresholdState got_always = checker_always[i].GetStateFor (pindex);
133
+ ThresholdState got_never = checker_never[i].GetStateFor (pindex);
119
134
// nHeight of the next block. If vpblock is empty, the next (ie first)
120
135
// block should be the genesis block with nHeight == 0.
121
136
int height = pindex == nullptr ? 0 : pindex->nHeight + 1 ;
122
137
BOOST_CHECK_MESSAGE (got == exp, strprintf (" Test %i for %s height %d (got %s)" , num, StateName (exp), height, StateName (got)));
123
138
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)));
124
140
}
125
141
}
126
142
num++;
0 commit comments