|
|
@ -16,69 +16,59 @@ BOOST_FIXTURE_TEST_SUITE(pow_tests, BasicTestingSetup) |
|
|
|
/* Test calculation of next difficulty target with no constraints applying */ |
|
|
|
/* Test calculation of next difficulty target with no constraints applying */ |
|
|
|
BOOST_AUTO_TEST_CASE(get_next_work) |
|
|
|
BOOST_AUTO_TEST_CASE(get_next_work) |
|
|
|
{ |
|
|
|
{ |
|
|
|
SelectParams(CBaseChainParams::MAIN); |
|
|
|
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN); |
|
|
|
const Consensus::Params& params = Params().GetConsensus(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int64_t nLastRetargetTime = 1261130161; // Block #30240
|
|
|
|
int64_t nLastRetargetTime = 1261130161; // Block #30240
|
|
|
|
CBlockIndex pindexLast; |
|
|
|
CBlockIndex pindexLast; |
|
|
|
pindexLast.nHeight = 32255; |
|
|
|
pindexLast.nHeight = 32255; |
|
|
|
pindexLast.nTime = 1262152739; // Block #32255
|
|
|
|
pindexLast.nTime = 1262152739; // Block #32255
|
|
|
|
pindexLast.nBits = 0x1d00ffff; |
|
|
|
pindexLast.nBits = 0x1d00ffff; |
|
|
|
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1d00d86a); |
|
|
|
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, chainParams->GetConsensus()), 0x1d00d86a); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Test the constraint on the upper bound for next work */ |
|
|
|
/* Test the constraint on the upper bound for next work */ |
|
|
|
BOOST_AUTO_TEST_CASE(get_next_work_pow_limit) |
|
|
|
BOOST_AUTO_TEST_CASE(get_next_work_pow_limit) |
|
|
|
{ |
|
|
|
{ |
|
|
|
SelectParams(CBaseChainParams::MAIN); |
|
|
|
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN); |
|
|
|
const Consensus::Params& params = Params().GetConsensus(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int64_t nLastRetargetTime = 1231006505; // Block #0
|
|
|
|
int64_t nLastRetargetTime = 1231006505; // Block #0
|
|
|
|
CBlockIndex pindexLast; |
|
|
|
CBlockIndex pindexLast; |
|
|
|
pindexLast.nHeight = 2015; |
|
|
|
pindexLast.nHeight = 2015; |
|
|
|
pindexLast.nTime = 1233061996; // Block #2015
|
|
|
|
pindexLast.nTime = 1233061996; // Block #2015
|
|
|
|
pindexLast.nBits = 0x1d00ffff; |
|
|
|
pindexLast.nBits = 0x1d00ffff; |
|
|
|
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1d00ffff); |
|
|
|
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, chainParams->GetConsensus()), 0x1d00ffff); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Test the constraint on the lower bound for actual time taken */ |
|
|
|
/* Test the constraint on the lower bound for actual time taken */ |
|
|
|
BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual) |
|
|
|
BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual) |
|
|
|
{ |
|
|
|
{ |
|
|
|
SelectParams(CBaseChainParams::MAIN); |
|
|
|
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN); |
|
|
|
const Consensus::Params& params = Params().GetConsensus(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int64_t nLastRetargetTime = 1279008237; // Block #66528
|
|
|
|
int64_t nLastRetargetTime = 1279008237; // Block #66528
|
|
|
|
CBlockIndex pindexLast; |
|
|
|
CBlockIndex pindexLast; |
|
|
|
pindexLast.nHeight = 68543; |
|
|
|
pindexLast.nHeight = 68543; |
|
|
|
pindexLast.nTime = 1279297671; // Block #68543
|
|
|
|
pindexLast.nTime = 1279297671; // Block #68543
|
|
|
|
pindexLast.nBits = 0x1c05a3f4; |
|
|
|
pindexLast.nBits = 0x1c05a3f4; |
|
|
|
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1c0168fd); |
|
|
|
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, chainParams->GetConsensus()), 0x1c0168fd); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Test the constraint on the upper bound for actual time taken */ |
|
|
|
/* Test the constraint on the upper bound for actual time taken */ |
|
|
|
BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual) |
|
|
|
BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual) |
|
|
|
{ |
|
|
|
{ |
|
|
|
SelectParams(CBaseChainParams::MAIN); |
|
|
|
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN); |
|
|
|
const Consensus::Params& params = Params().GetConsensus(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int64_t nLastRetargetTime = 1263163443; // NOTE: Not an actual block time
|
|
|
|
int64_t nLastRetargetTime = 1263163443; // NOTE: Not an actual block time
|
|
|
|
CBlockIndex pindexLast; |
|
|
|
CBlockIndex pindexLast; |
|
|
|
pindexLast.nHeight = 46367; |
|
|
|
pindexLast.nHeight = 46367; |
|
|
|
pindexLast.nTime = 1269211443; // Block #46367
|
|
|
|
pindexLast.nTime = 1269211443; // Block #46367
|
|
|
|
pindexLast.nBits = 0x1c387f6f; |
|
|
|
pindexLast.nBits = 0x1c387f6f; |
|
|
|
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1d00e1fd); |
|
|
|
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, chainParams->GetConsensus()), 0x1d00e1fd); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test) |
|
|
|
BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test) |
|
|
|
{ |
|
|
|
{ |
|
|
|
SelectParams(CBaseChainParams::MAIN); |
|
|
|
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN); |
|
|
|
const Consensus::Params& params = Params().GetConsensus(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<CBlockIndex> blocks(10000); |
|
|
|
std::vector<CBlockIndex> blocks(10000); |
|
|
|
for (int i = 0; i < 10000; i++) { |
|
|
|
for (int i = 0; i < 10000; i++) { |
|
|
|
blocks[i].pprev = i ? &blocks[i - 1] : NULL; |
|
|
|
blocks[i].pprev = i ? &blocks[i - 1] : NULL; |
|
|
|
blocks[i].nHeight = i; |
|
|
|
blocks[i].nHeight = i; |
|
|
|
blocks[i].nTime = 1269211443 + i * params.nPowTargetSpacing; |
|
|
|
blocks[i].nTime = 1269211443 + i * chainParams->GetConsensus().nPowTargetSpacing; |
|
|
|
blocks[i].nBits = 0x207fffff; /* target 0x7fffff000... */ |
|
|
|
blocks[i].nBits = 0x207fffff; /* target 0x7fffff000... */ |
|
|
|
blocks[i].nChainWork = i ? blocks[i - 1].nChainWork + GetBlockProof(blocks[i - 1]) : arith_uint256(0); |
|
|
|
blocks[i].nChainWork = i ? blocks[i - 1].nChainWork + GetBlockProof(blocks[i - 1]) : arith_uint256(0); |
|
|
|
} |
|
|
|
} |
|
|
@ -88,7 +78,7 @@ BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test) |
|
|
|
CBlockIndex *p2 = &blocks[GetRand(10000)]; |
|
|
|
CBlockIndex *p2 = &blocks[GetRand(10000)]; |
|
|
|
CBlockIndex *p3 = &blocks[GetRand(10000)]; |
|
|
|
CBlockIndex *p3 = &blocks[GetRand(10000)]; |
|
|
|
|
|
|
|
|
|
|
|
int64_t tdiff = GetBlockProofEquivalentTime(*p1, *p2, *p3, params); |
|
|
|
int64_t tdiff = GetBlockProofEquivalentTime(*p1, *p2, *p3, chainParams->GetConsensus()); |
|
|
|
BOOST_CHECK_EQUAL(tdiff, p1->GetBlockTime() - p2->GetBlockTime()); |
|
|
|
BOOST_CHECK_EQUAL(tdiff, p1->GetBlockTime() - p2->GetBlockTime()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|