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(),
params),
GetNextWorkRequired(&blocks[lastBlk], nullptr, params));
// Result should be unchanged
// TODO: This should be 0x1e7fffff, and just before GetNextWorkRequired()
// returns, it is. Somehow it ends up off by one....
EXPECT_EQ(0x1e7ffffe, GetNextWorkRequired(&blocks[lastBlk], nullptr, params));
// Result should be unchanged, modulo integer division precision loss
arith_uint256 bnRes;
bnRes.SetCompact(0x1e7fffff);
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)
blocks[lastBlk].nTime += GetRand(params.nPowTargetSpacing/2) + 1;