aboutsummaryrefslogtreecommitdiff
path: root/src/test/pow_tests.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2015-03-17 06:35:59 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2015-04-22 03:53:25 -0700
commitf7303f97933be33e34d482cf8348d180c8da2a26 (patch)
tree5612e3678a19c1412212ca034e7c7a8b959aa9f1 /src/test/pow_tests.cpp
parentb6ea3bcede1cbbf89486b9d67329e0110c4624ae (diff)
Use equivalent PoW for non-main-chain requests
Diffstat (limited to 'src/test/pow_tests.cpp')
-rw-r--r--src/test/pow_tests.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/test/pow_tests.cpp b/src/test/pow_tests.cpp
index 4ce1591c35..a436749287 100644
--- a/src/test/pow_tests.cpp
+++ b/src/test/pow_tests.cpp
@@ -69,4 +69,28 @@ BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual)
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1d00e1fd);
}
+BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
+{
+ SelectParams(CBaseChainParams::MAIN);
+ const Consensus::Params& params = Params().GetConsensus();
+
+ std::vector<CBlockIndex> blocks(10000);
+ for (int i = 0; i < 10000; i++) {
+ blocks[i].pprev = i ? &blocks[i - 1] : NULL;
+ blocks[i].nHeight = i;
+ blocks[i].nTime = 1269211443 + i * params.nPowTargetSpacing;
+ blocks[i].nBits = 0x207fffff; /* target 0x7fffff000... */
+ blocks[i].nChainWork = i ? blocks[i - 1].nChainWork + GetBlockProof(blocks[i - 1]) : arith_uint256(0);
+ }
+
+ for (int j = 0; j < 1000; j++) {
+ CBlockIndex *p1 = &blocks[GetRand(10000)];
+ CBlockIndex *p2 = &blocks[GetRand(10000)];
+ CBlockIndex *p3 = &blocks[GetRand(10000)];
+
+ int64_t tdiff = GetBlockProofEquivalentTime(*p1, *p2, *p3, params);
+ BOOST_CHECK_EQUAL(tdiff, p1->GetBlockTime() - p2->GetBlockTime());
+ }
+}
+
BOOST_AUTO_TEST_SUITE_END()