MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / VersionBitsTester

Class VersionBitsTester

src/test/versionbits_tests.cpp:37–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35#define CHECKERS 6
36
37class VersionBitsTester
38{
39 // A fake blockchain
40 std::vector<CBlockIndex*> vpblock;
41
42 // 6 independent checkers for the same bit.
43 // The first one performs all checks, the second only 50%, the third only 25%, etc...
44 // This is to test whether lack of cached information leads to the same results.
45 TestConditionChecker checker[CHECKERS];
46
47 // Test counter (to identify failures)
48 int num;
49
50public:
51 VersionBitsTester() : num(0) {}
52
53 VersionBitsTester& Reset() {
54 for (unsigned int i = 0; i < vpblock.size(); i++) {
55 delete vpblock[i];
56 }
57 for (unsigned int i = 0; i < CHECKERS; i++) {
58 checker[i] = TestConditionChecker();
59 }
60 vpblock.clear();
61 return *this;
62 }
63
64 ~VersionBitsTester() {
65 Reset();
66 }
67
68 VersionBitsTester& Mine(unsigned int height, int32_t nTime, int32_t nVersion) {
69 while (vpblock.size() < height) {
70 CBlockIndex* pindex = new CBlockIndex();
71 pindex->nHeight = vpblock.size();
72 pindex->pprev = vpblock.size() > 0 ? vpblock.back() : NULL;
73 pindex->nTime = nTime;
74 pindex->nVersion = nVersion;
75 pindex->BuildSkip();
76 vpblock.push_back(pindex);
77 }
78 return *this;
79 }
80
81 VersionBitsTester& TestDefined() {
82 for (int i = 0; i < CHECKERS; i++) {
83 if ((insecure_rand() & ((1 << i) - 1)) == 0) {
84 BOOST_CHECK_MESSAGE(checker[i].GetStateFor(vpblock.empty() ? NULL : vpblock.back()) == THRESHOLD_DEFINED, strprintf("Test %i for DEFINED", num));
85 }
86 }
87 num++;
88 return *this;
89 }
90
91 VersionBitsTester& TestStarted() {
92 for (int i = 0; i < CHECKERS; i++) {
93 if ((insecure_rand() & ((1 << i) - 1)) == 0) {
94 BOOST_CHECK_MESSAGE(checker[i].GetStateFor(vpblock.empty() ? NULL : vpblock.back()) == THRESHOLD_STARTED, strprintf("Test %i for STARTED", num));

Callers 1

BOOST_AUTO_TEST_CASEFunction · 0.85

Calls 8

insecure_randFunction · 0.85
BuildSkipMethod · 0.80
sizeMethod · 0.45
clearMethod · 0.45
push_backMethod · 0.45
GetStateForMethod · 0.45
emptyMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.68