Adjust test to account for integer division precision loss
This commit is contained in:
parent
4b37cfd5b8
commit
622ced8a74
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue