@@ -16,69 +16,59 @@ BOOST_FIXTURE_TEST_SUITE(pow_tests, BasicTestingSetup)
16
16
/* Test calculation of next difficulty target with no constraints applying */
17
17
BOOST_AUTO_TEST_CASE(get_next_work)
18
18
{
19
- SelectParams (CBaseChainParams::MAIN);
20
- const Consensus::Params& params = Params ().GetConsensus ();
21
-
19
+ const auto chainParams = CreateChainParams (CBaseChainParams::MAIN);
22
20
int64_t nLastRetargetTime = 1261130161 ; // Block #30240
23
21
CBlockIndex pindexLast;
24
22
pindexLast.nHeight = 32255 ;
25
23
pindexLast.nTime = 1262152739 ; // Block #32255
26
24
pindexLast.nBits = 0x1d00ffff ;
27
- BOOST_CHECK_EQUAL (CalculateNextWorkRequired (&pindexLast, nLastRetargetTime, params ), 0x1d00d86a );
25
+ BOOST_CHECK_EQUAL (CalculateNextWorkRequired (&pindexLast, nLastRetargetTime, chainParams-> GetConsensus () ), 0x1d00d86a );
28
26
}
29
27
30
28
/* Test the constraint on the upper bound for next work */
31
29
BOOST_AUTO_TEST_CASE (get_next_work_pow_limit)
32
30
{
33
- SelectParams (CBaseChainParams::MAIN);
34
- const Consensus::Params& params = Params ().GetConsensus ();
35
-
31
+ const auto chainParams = CreateChainParams (CBaseChainParams::MAIN);
36
32
int64_t nLastRetargetTime = 1231006505 ; // Block #0
37
33
CBlockIndex pindexLast;
38
34
pindexLast.nHeight = 2015 ;
39
35
pindexLast.nTime = 1233061996 ; // Block #2015
40
36
pindexLast.nBits = 0x1d00ffff ;
41
- BOOST_CHECK_EQUAL (CalculateNextWorkRequired (&pindexLast, nLastRetargetTime, params ), 0x1d00ffff );
37
+ BOOST_CHECK_EQUAL (CalculateNextWorkRequired (&pindexLast, nLastRetargetTime, chainParams-> GetConsensus () ), 0x1d00ffff );
42
38
}
43
39
44
40
/* Test the constraint on the lower bound for actual time taken */
45
41
BOOST_AUTO_TEST_CASE (get_next_work_lower_limit_actual)
46
42
{
47
- SelectParams (CBaseChainParams::MAIN);
48
- const Consensus::Params& params = Params ().GetConsensus ();
49
-
43
+ const auto chainParams = CreateChainParams (CBaseChainParams::MAIN);
50
44
int64_t nLastRetargetTime = 1279008237 ; // Block #66528
51
45
CBlockIndex pindexLast;
52
46
pindexLast.nHeight = 68543 ;
53
47
pindexLast.nTime = 1279297671 ; // Block #68543
54
48
pindexLast.nBits = 0x1c05a3f4 ;
55
- BOOST_CHECK_EQUAL (CalculateNextWorkRequired (&pindexLast, nLastRetargetTime, params ), 0x1c0168fd );
49
+ BOOST_CHECK_EQUAL (CalculateNextWorkRequired (&pindexLast, nLastRetargetTime, chainParams-> GetConsensus () ), 0x1c0168fd );
56
50
}
57
51
58
52
/* Test the constraint on the upper bound for actual time taken */
59
53
BOOST_AUTO_TEST_CASE (get_next_work_upper_limit_actual)
60
54
{
61
- SelectParams (CBaseChainParams::MAIN);
62
- const Consensus::Params& params = Params ().GetConsensus ();
63
-
55
+ const auto chainParams = CreateChainParams (CBaseChainParams::MAIN);
64
56
int64_t nLastRetargetTime = 1263163443 ; // NOTE: Not an actual block time
65
57
CBlockIndex pindexLast;
66
58
pindexLast.nHeight = 46367 ;
67
59
pindexLast.nTime = 1269211443 ; // Block #46367
68
60
pindexLast.nBits = 0x1c387f6f ;
69
- BOOST_CHECK_EQUAL (CalculateNextWorkRequired (&pindexLast, nLastRetargetTime, params ), 0x1d00e1fd );
61
+ BOOST_CHECK_EQUAL (CalculateNextWorkRequired (&pindexLast, nLastRetargetTime, chainParams-> GetConsensus () ), 0x1d00e1fd );
70
62
}
71
63
72
64
BOOST_AUTO_TEST_CASE (GetBlockProofEquivalentTime_test)
73
65
{
74
- SelectParams (CBaseChainParams::MAIN);
75
- const Consensus::Params& params = Params ().GetConsensus ();
76
-
66
+ const auto chainParams = CreateChainParams (CBaseChainParams::MAIN);
77
67
std::vector<CBlockIndex> blocks (10000 );
78
68
for (int i = 0 ; i < 10000 ; i++) {
79
69
blocks[i].pprev = i ? &blocks[i - 1 ] : NULL ;
80
70
blocks[i].nHeight = i;
81
- blocks[i].nTime = 1269211443 + i * params .nPowTargetSpacing ;
71
+ blocks[i].nTime = 1269211443 + i * chainParams-> GetConsensus () .nPowTargetSpacing ;
82
72
blocks[i].nBits = 0x207fffff ; /* target 0x7fffff000... */
83
73
blocks[i].nChainWork = i ? blocks[i - 1 ].nChainWork + GetBlockProof (blocks[i - 1 ]) : arith_uint256 (0 );
84
74
}
@@ -88,7 +78,7 @@ BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
88
78
CBlockIndex *p2 = &blocks[GetRand (10000 )];
89
79
CBlockIndex *p3 = &blocks[GetRand (10000 )];
90
80
91
- int64_t tdiff = GetBlockProofEquivalentTime (*p1, *p2, *p3, params );
81
+ int64_t tdiff = GetBlockProofEquivalentTime (*p1, *p2, *p3, chainParams-> GetConsensus () );
92
82
BOOST_CHECK_EQUAL (tdiff, p1->GetBlockTime () - p2->GetBlockTime ());
93
83
}
94
84
}
0 commit comments