Skip to content

Commit c1082a7

Browse files
committed
Chainparams: Use the factory for pow tests
1 parent 2351a06 commit c1082a7

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

src/test/pow_tests.cpp

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,69 +16,59 @@ BOOST_FIXTURE_TEST_SUITE(pow_tests, BasicTestingSetup)
1616
/* Test calculation of next difficulty target with no constraints applying */
1717
BOOST_AUTO_TEST_CASE(get_next_work)
1818
{
19-
SelectParams(CBaseChainParams::MAIN);
20-
const Consensus::Params& params = Params().GetConsensus();
21-
19+
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
2220
int64_t nLastRetargetTime = 1261130161; // Block #30240
2321
CBlockIndex pindexLast;
2422
pindexLast.nHeight = 32255;
2523
pindexLast.nTime = 1262152739; // Block #32255
2624
pindexLast.nBits = 0x1d00ffff;
27-
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1d00d86a);
25+
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, chainParams->GetConsensus()), 0x1d00d86a);
2826
}
2927

3028
/* Test the constraint on the upper bound for next work */
3129
BOOST_AUTO_TEST_CASE(get_next_work_pow_limit)
3230
{
33-
SelectParams(CBaseChainParams::MAIN);
34-
const Consensus::Params& params = Params().GetConsensus();
35-
31+
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
3632
int64_t nLastRetargetTime = 1231006505; // Block #0
3733
CBlockIndex pindexLast;
3834
pindexLast.nHeight = 2015;
3935
pindexLast.nTime = 1233061996; // Block #2015
4036
pindexLast.nBits = 0x1d00ffff;
41-
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1d00ffff);
37+
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, chainParams->GetConsensus()), 0x1d00ffff);
4238
}
4339

4440
/* Test the constraint on the lower bound for actual time taken */
4541
BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual)
4642
{
47-
SelectParams(CBaseChainParams::MAIN);
48-
const Consensus::Params& params = Params().GetConsensus();
49-
43+
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
5044
int64_t nLastRetargetTime = 1279008237; // Block #66528
5145
CBlockIndex pindexLast;
5246
pindexLast.nHeight = 68543;
5347
pindexLast.nTime = 1279297671; // Block #68543
5448
pindexLast.nBits = 0x1c05a3f4;
55-
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1c0168fd);
49+
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, chainParams->GetConsensus()), 0x1c0168fd);
5650
}
5751

5852
/* Test the constraint on the upper bound for actual time taken */
5953
BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual)
6054
{
61-
SelectParams(CBaseChainParams::MAIN);
62-
const Consensus::Params& params = Params().GetConsensus();
63-
55+
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
6456
int64_t nLastRetargetTime = 1263163443; // NOTE: Not an actual block time
6557
CBlockIndex pindexLast;
6658
pindexLast.nHeight = 46367;
6759
pindexLast.nTime = 1269211443; // Block #46367
6860
pindexLast.nBits = 0x1c387f6f;
69-
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1d00e1fd);
61+
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, chainParams->GetConsensus()), 0x1d00e1fd);
7062
}
7163

7264
BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
7365
{
74-
SelectParams(CBaseChainParams::MAIN);
75-
const Consensus::Params& params = Params().GetConsensus();
76-
66+
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
7767
std::vector<CBlockIndex> blocks(10000);
7868
for (int i = 0; i < 10000; i++) {
7969
blocks[i].pprev = i ? &blocks[i - 1] : NULL;
8070
blocks[i].nHeight = i;
81-
blocks[i].nTime = 1269211443 + i * params.nPowTargetSpacing;
71+
blocks[i].nTime = 1269211443 + i * chainParams->GetConsensus().nPowTargetSpacing;
8272
blocks[i].nBits = 0x207fffff; /* target 0x7fffff000... */
8373
blocks[i].nChainWork = i ? blocks[i - 1].nChainWork + GetBlockProof(blocks[i - 1]) : arith_uint256(0);
8474
}
@@ -88,7 +78,7 @@ BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
8878
CBlockIndex *p2 = &blocks[GetRand(10000)];
8979
CBlockIndex *p3 = &blocks[GetRand(10000)];
9080

91-
int64_t tdiff = GetBlockProofEquivalentTime(*p1, *p2, *p3, params);
81+
int64_t tdiff = GetBlockProofEquivalentTime(*p1, *p2, *p3, chainParams->GetConsensus());
9282
BOOST_CHECK_EQUAL(tdiff, p1->GetBlockTime() - p2->GetBlockTime());
9383
}
9484
}

0 commit comments

Comments
 (0)