Replace nPoWTargetSpacing -> PoWTargetSpacing() in tests
This commit is contained in:
parent
22e8dc2679
commit
3a8fd5ea33
|
@ -16,7 +16,7 @@ TEST(PoW, DifficultyAveraging) {
|
|||
for (int i = 0; i <= lastBlk; i++) {
|
||||
blocks[i].pprev = i ? &blocks[i - 1] : nullptr;
|
||||
blocks[i].nHeight = i;
|
||||
blocks[i].nTime = 1269211443 + i * params.nPowTargetSpacing;
|
||||
blocks[i].nTime = 1269211443 + i * params.PoWTargetSpacing(blocks[i].nHeight);
|
||||
blocks[i].nBits = 0x1e7fffff; /* target 0x007fffff000... */
|
||||
blocks[i].nChainWork = i ? blocks[i - 1].nChainWork + GetBlockProof(blocks[i - 1]) : arith_uint256(0);
|
||||
}
|
||||
|
@ -32,12 +32,12 @@ TEST(PoW, DifficultyAveraging) {
|
|||
// Result should be unchanged, modulo integer division precision loss
|
||||
arith_uint256 bnRes;
|
||||
bnRes.SetCompact(0x1e7fffff);
|
||||
bnRes /= params.AveragingWindowTimespan();
|
||||
bnRes *= params.AveragingWindowTimespan();
|
||||
bnRes /= params.AveragingWindowTimespan(blocks[lastBlk].nHeight);
|
||||
bnRes *= params.AveragingWindowTimespan(blocks[lastBlk].nHeight);
|
||||
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;
|
||||
blocks[lastBlk].nTime += GetRand(params.PoWTargetSpacing(blocks[lastBlk].nHeight)/2) + 1;
|
||||
|
||||
// Result should be the same as if last difficulty was used
|
||||
bnAvg.SetCompact(blocks[lastBlk].nBits);
|
||||
|
@ -80,24 +80,24 @@ TEST(PoW, MinDifficultyRules) {
|
|||
for (int i = 0; i <= lastBlk; i++) {
|
||||
blocks[i].pprev = i ? &blocks[i - 1] : nullptr;
|
||||
blocks[i].nHeight = params.nPowAllowMinDifficultyBlocksAfterHeight.get() + i;
|
||||
blocks[i].nTime = 1269211443 + i * params.nPowTargetSpacing;
|
||||
blocks[i].nTime = 1269211443 + i * params.PoWTargetSpacing(blocks[i].nHeight);
|
||||
blocks[i].nBits = 0x1e7fffff; /* target 0x007fffff000... */
|
||||
blocks[i].nChainWork = i ? blocks[i - 1].nChainWork + GetBlockProof(blocks[i - 1]) : arith_uint256(0);
|
||||
}
|
||||
|
||||
// Create a new block at the target spacing
|
||||
CBlockHeader next;
|
||||
next.nTime = blocks[lastBlk].nTime + params.nPowTargetSpacing;
|
||||
next.nTime = blocks[lastBlk].nTime + params.PoWTargetSpacing(blocks[lastBlk].nHeight + 1);
|
||||
|
||||
// Result should be unchanged, modulo integer division precision loss
|
||||
arith_uint256 bnRes;
|
||||
bnRes.SetCompact(0x1e7fffff);
|
||||
bnRes /= params.AveragingWindowTimespan();
|
||||
bnRes *= params.AveragingWindowTimespan();
|
||||
bnRes /= params.AveragingWindowTimespan(blocks[lastBlk].nHeight);
|
||||
bnRes *= params.AveragingWindowTimespan(blocks[lastBlk].nHeight);
|
||||
EXPECT_EQ(GetNextWorkRequired(&blocks[lastBlk], &next, params), bnRes.GetCompact());
|
||||
|
||||
// Delay last block up to the edge of the min-difficulty limit
|
||||
next.nTime += params.nPowTargetSpacing * 5;
|
||||
next.nTime += params.PoWTargetSpacing(blocks[lastBlk].nHeight + 1) * 5;
|
||||
|
||||
// Result should be unchanged, modulo integer division precision loss
|
||||
EXPECT_EQ(GetNextWorkRequired(&blocks[lastBlk], &next, params), bnRes.GetCompact());
|
||||
|
|
|
@ -391,7 +391,7 @@ BOOST_AUTO_TEST_CASE(PartitionAlert)
|
|||
CCriticalSection csDummy;
|
||||
CBlockIndex indexDummy[400];
|
||||
CChainParams& params = Params(CBaseChainParams::MAIN);
|
||||
int64_t nPowTargetSpacing = params.GetConsensus().nPowTargetSpacing;
|
||||
int64_t nPowTargetSpacing = params.GetConsensus().PoWTargetSpacing(0); // First 400 blocks are pre-Blossom
|
||||
|
||||
// Generate fake blockchain timestamps relative to
|
||||
// an arbitrary time:
|
||||
|
|
|
@ -168,7 +168,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity)
|
|||
// of the next block must be six spacings ahead of that to be at least
|
||||
// one spacing ahead of the tip. Within 11 blocks of genesis, the median
|
||||
// will be closer to the tip, and blocks will appear slower.
|
||||
pblock->nTime = chainActive.Tip()->GetMedianTimePast()+6*Params().GetConsensus().nPowTargetSpacing;
|
||||
pblock->nTime = chainActive.Tip()->GetMedianTimePast()+6*Params().GetConsensus().PoWTargetSpacing(i);
|
||||
CMutableTransaction txCoinbase(pblock->vtx[0]);
|
||||
txCoinbase.nVersion = 1;
|
||||
txCoinbase.vin[0].scriptSig = CScript() << (chainActive.Height()+1) << OP_0;
|
||||
|
|
|
@ -78,7 +78,7 @@ BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
|
|||
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].nTime = 1269211443 + i * params.PoWTargetSpacing(blocks[i].nHeight);
|
||||
blocks[i].nBits = 0x207fffff; /* target 0x7fffff000... */
|
||||
blocks[i].nChainWork = i ? blocks[i - 1].nChainWork + GetBlockProof(blocks[i - 1]) : arith_uint256(0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue