| 66 | #define CHECKERS 6 |
| 67 | |
| 68 | class VersionBitsTester |
| 69 | { |
| 70 | // A fake blockchain |
| 71 | std::vector<CBlockIndex*> vpblock; |
| 72 | |
| 73 | // 6 independent checkers for the same bit. |
| 74 | // The first one performs all checks, the second only 50%, the third only 25%, etc... |
| 75 | // This is to test whether lack of cached information leads to the same results. |
| 76 | TestConditionChecker checker[CHECKERS]; |
| 77 | // Another 6 that assume delayed activation |
| 78 | TestDelayedActivationConditionChecker checker_delayed[CHECKERS]; |
| 79 | // Another 6 that assume always active activation |
| 80 | TestAlwaysActiveConditionChecker checker_always[CHECKERS]; |
| 81 | // Another 6 that assume never active activation |
| 82 | TestNeverActiveConditionChecker checker_never[CHECKERS]; |
| 83 | |
| 84 | // Test counter (to identify failures) |
| 85 | int num{1000}; |
| 86 | |
| 87 | public: |
| 88 | VersionBitsTester& Reset() { |
| 89 | // Have each group of tests be counted by the 1000s part, starting at 1000 |
| 90 | num = num - (num % 1000) + 1000; |
| 91 | |
| 92 | for (unsigned int i = 0; i < vpblock.size(); i++) { |
| 93 | delete vpblock[i]; |
| 94 | } |
| 95 | for (unsigned int i = 0; i < CHECKERS; i++) { |
| 96 | checker[i] = TestConditionChecker(); |
| 97 | checker_delayed[i] = TestDelayedActivationConditionChecker(); |
| 98 | checker_always[i] = TestAlwaysActiveConditionChecker(); |
| 99 | checker_never[i] = TestNeverActiveConditionChecker(); |
| 100 | } |
| 101 | vpblock.clear(); |
| 102 | return *this; |
| 103 | } |
| 104 | |
| 105 | ~VersionBitsTester() { |
| 106 | Reset(); |
| 107 | } |
| 108 | |
| 109 | VersionBitsTester& Mine(unsigned int height, int32_t nTime, int32_t nVersion) { |
| 110 | while (vpblock.size() < height) { |
| 111 | CBlockIndex* pindex = new CBlockIndex(); |
| 112 | pindex->nHeight = vpblock.size(); |
| 113 | pindex->pprev = Tip(); |
| 114 | pindex->nTime = nTime; |
| 115 | pindex->nVersion = nVersion; |
| 116 | pindex->BuildSkip(); |
| 117 | vpblock.push_back(pindex); |
| 118 | } |
| 119 | return *this; |
| 120 | } |
| 121 | |
| 122 | VersionBitsTester& TestStateSinceHeight(int height) |
| 123 | { |
| 124 | return TestStateSinceHeight(height, height); |
| 125 | } |