Adjust test to account for integer division precision loss

This commit is contained in:
Jack Grigg 2016-09-08 12:46:00 +12:00
parent 4b37cfd5b8
commit 622ced8a74
1 changed files with 6 additions and 4 deletions

View File

@ -29,10 +29,12 @@ TEST(PoW, DifficultyAveraging) {
blocks[firstBlk].GetMedianTimePast(), blocks[firstBlk].GetMedianTimePast(),
params), params),
GetNextWorkRequired(&blocks[lastBlk], nullptr, params)); GetNextWorkRequired(&blocks[lastBlk], nullptr, params));
// Result should be unchanged // Result should be unchanged, modulo integer division precision loss
// TODO: This should be 0x1e7fffff, and just before GetNextWorkRequired() arith_uint256 bnRes;
// returns, it is. Somehow it ends up off by one.... bnRes.SetCompact(0x1e7fffff);
EXPECT_EQ(0x1e7ffffe, GetNextWorkRequired(&blocks[lastBlk], nullptr, params)); bnRes /= params.AveragingWindowTimespan();
bnRes *= params.AveragingWindowTimespan();
EXPECT_EQ(bnRes.GetCompact(), GetNextWorkRequired(&blocks[lastBlk], nullptr, params));
// Randomise the final block time (plus 1 to ensure it is always different) // Randomise the final block time (plus 1 to ensure it is always different)
blocks[lastBlk].nTime += GetRand(params.nPowTargetSpacing/2) + 1; blocks[lastBlk].nTime += GetRand(params.nPowTargetSpacing/2) + 1;