Remove unnecessary method
This commit is contained in:
parent
aea79ec053
commit
4b37cfd5b8
|
@ -22,7 +22,10 @@ TEST(PoW, DifficultyAveraging) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Result should be the same as if last difficulty was used
|
// Result should be the same as if last difficulty was used
|
||||||
EXPECT_EQ(CalculateNextWorkRequired(&blocks[lastBlk],
|
arith_uint256 bnAvg;
|
||||||
|
bnAvg.SetCompact(blocks[lastBlk].nBits);
|
||||||
|
EXPECT_EQ(CalculateNextWorkRequired(bnAvg,
|
||||||
|
blocks[lastBlk].GetMedianTimePast(),
|
||||||
blocks[firstBlk].GetMedianTimePast(),
|
blocks[firstBlk].GetMedianTimePast(),
|
||||||
params),
|
params),
|
||||||
GetNextWorkRequired(&blocks[lastBlk], nullptr, params));
|
GetNextWorkRequired(&blocks[lastBlk], nullptr, params));
|
||||||
|
@ -35,7 +38,9 @@ TEST(PoW, DifficultyAveraging) {
|
||||||
blocks[lastBlk].nTime += GetRand(params.nPowTargetSpacing/2) + 1;
|
blocks[lastBlk].nTime += GetRand(params.nPowTargetSpacing/2) + 1;
|
||||||
|
|
||||||
// Result should be the same as if last difficulty was used
|
// Result should be the same as if last difficulty was used
|
||||||
EXPECT_EQ(CalculateNextWorkRequired(&blocks[lastBlk],
|
bnAvg.SetCompact(blocks[lastBlk].nBits);
|
||||||
|
EXPECT_EQ(CalculateNextWorkRequired(bnAvg,
|
||||||
|
blocks[lastBlk].GetMedianTimePast(),
|
||||||
blocks[firstBlk].GetMedianTimePast(),
|
blocks[firstBlk].GetMedianTimePast(),
|
||||||
params),
|
params),
|
||||||
GetNextWorkRequired(&blocks[lastBlk], nullptr, params));
|
GetNextWorkRequired(&blocks[lastBlk], nullptr, params));
|
||||||
|
@ -46,7 +51,9 @@ TEST(PoW, DifficultyAveraging) {
|
||||||
blocks[lastBlk].nBits = 0x1e0fffff;
|
blocks[lastBlk].nBits = 0x1e0fffff;
|
||||||
|
|
||||||
// Result should not be the same as if last difficulty was used
|
// Result should not be the same as if last difficulty was used
|
||||||
EXPECT_NE(CalculateNextWorkRequired(&blocks[lastBlk],
|
bnAvg.SetCompact(blocks[lastBlk].nBits);
|
||||||
|
EXPECT_NE(CalculateNextWorkRequired(bnAvg,
|
||||||
|
blocks[lastBlk].GetMedianTimePast(),
|
||||||
blocks[firstBlk].GetMedianTimePast(),
|
blocks[firstBlk].GetMedianTimePast(),
|
||||||
params),
|
params),
|
||||||
GetNextWorkRequired(&blocks[lastBlk], nullptr, params));
|
GetNextWorkRequired(&blocks[lastBlk], nullptr, params));
|
||||||
|
|
|
@ -43,14 +43,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
|
||||||
return CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params);
|
return CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), pindexFirst->GetMedianTimePast(), params);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Left for testing purposes
|
|
||||||
unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params& params)
|
|
||||||
{
|
|
||||||
arith_uint256 bnAvg;
|
|
||||||
bnAvg.SetCompact(pindexLast->nBits);
|
|
||||||
return CalculateNextWorkRequired(bnAvg, pindexLast->GetMedianTimePast(), nFirstBlockTime, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg,
|
unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg,
|
||||||
int64_t nLastBlockTime, int64_t nFirstBlockTime,
|
int64_t nLastBlockTime, int64_t nFirstBlockTime,
|
||||||
const Consensus::Params& params)
|
const Consensus::Params& params)
|
||||||
|
|
|
@ -17,7 +17,6 @@ class uint256;
|
||||||
class arith_uint256;
|
class arith_uint256;
|
||||||
|
|
||||||
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params&);
|
unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHeader *pblock, const Consensus::Params&);
|
||||||
unsigned int CalculateNextWorkRequired(const CBlockIndex* pindexLast, int64_t nFirstBlockTime, const Consensus::Params&);
|
|
||||||
unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg,
|
unsigned int CalculateNextWorkRequired(arith_uint256 bnAvg,
|
||||||
int64_t nLastBlockTime, int64_t nFirstBlockTime,
|
int64_t nLastBlockTime, int64_t nFirstBlockTime,
|
||||||
const Consensus::Params&);
|
const Consensus::Params&);
|
||||||
|
|
|
@ -20,12 +20,11 @@ BOOST_AUTO_TEST_CASE(get_next_work)
|
||||||
const Consensus::Params& params = Params().GetConsensus();
|
const Consensus::Params& params = Params().GetConsensus();
|
||||||
|
|
||||||
int64_t nLastRetargetTime = 1262149169; // NOTE: Not an actual block time
|
int64_t nLastRetargetTime = 1262149169; // NOTE: Not an actual block time
|
||||||
CBlockIndex pindexLast;
|
int64_t nThisTime = 1262152739; // Block #32255 of Bitcoin
|
||||||
pindexLast.nHeight = 32255;
|
arith_uint256 bnAvg;
|
||||||
pindexLast.nTime = 1262152739; // Block #32255 of Bitcoin
|
bnAvg.SetCompact(0x1d00ffff);
|
||||||
// This represents an average difficulty in the current algorithm
|
BOOST_CHECK_EQUAL(0x1d011998,
|
||||||
pindexLast.nBits = 0x1d00ffff;
|
CalculateNextWorkRequired(bnAvg, nThisTime, nLastRetargetTime, params));
|
||||||
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1d011998);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test the constraint on the upper bound for next work */
|
/* Test the constraint on the upper bound for next work */
|
||||||
|
@ -35,13 +34,12 @@ BOOST_AUTO_TEST_CASE(get_next_work_pow_limit)
|
||||||
const Consensus::Params& params = Params().GetConsensus();
|
const Consensus::Params& params = Params().GetConsensus();
|
||||||
|
|
||||||
int64_t nLastRetargetTime = 1231006505; // Block #0 of Bitcoin
|
int64_t nLastRetargetTime = 1231006505; // Block #0 of Bitcoin
|
||||||
CBlockIndex pindexLast;
|
int64_t nThisTime = 1233061996; // Block #2015 of Bitcoin
|
||||||
pindexLast.nHeight = 2015;
|
arith_uint256 bnAvg;
|
||||||
pindexLast.nTime = 1233061996; // Block #2015 of Bitcoin
|
|
||||||
// This represents an average difficulty in the current algorithm
|
|
||||||
// TODO change once the harder genesis block is generated
|
// TODO change once the harder genesis block is generated
|
||||||
pindexLast.nBits = 0x200f0f0f;
|
bnAvg.SetCompact(0x200f0f0f);
|
||||||
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x200f0f0f);
|
BOOST_CHECK_EQUAL(0x200f0f0f,
|
||||||
|
CalculateNextWorkRequired(bnAvg, nThisTime, nLastRetargetTime, params));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test the constraint on the lower bound for actual time taken */
|
/* Test the constraint on the lower bound for actual time taken */
|
||||||
|
@ -51,12 +49,11 @@ BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual)
|
||||||
const Consensus::Params& params = Params().GetConsensus();
|
const Consensus::Params& params = Params().GetConsensus();
|
||||||
|
|
||||||
int64_t nLastRetargetTime = 1279296753; // NOTE: Not an actual block time
|
int64_t nLastRetargetTime = 1279296753; // NOTE: Not an actual block time
|
||||||
CBlockIndex pindexLast;
|
int64_t nThisTime = 1279297671; // Block #68543 of Bitcoin
|
||||||
pindexLast.nHeight = 68543;
|
arith_uint256 bnAvg;
|
||||||
pindexLast.nTime = 1279297671; // Block #68543 of Bitcoin
|
bnAvg.SetCompact(0x1c05a3f4);
|
||||||
// This represents an average difficulty in the current algorithm
|
BOOST_CHECK_EQUAL(0x1c04bceb,
|
||||||
pindexLast.nBits = 0x1c05a3f4;
|
CalculateNextWorkRequired(bnAvg, nThisTime, nLastRetargetTime, params));
|
||||||
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1c04bceb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Test the constraint on the upper bound for actual time taken */
|
/* Test the constraint on the upper bound for actual time taken */
|
||||||
|
@ -66,12 +63,11 @@ BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual)
|
||||||
const Consensus::Params& params = Params().GetConsensus();
|
const Consensus::Params& params = Params().GetConsensus();
|
||||||
|
|
||||||
int64_t nLastRetargetTime = 1269205629; // NOTE: Not an actual block time
|
int64_t nLastRetargetTime = 1269205629; // NOTE: Not an actual block time
|
||||||
CBlockIndex pindexLast;
|
int64_t nThisTime = 1269211443; // Block #46367 of Bitcoin
|
||||||
pindexLast.nHeight = 46367;
|
arith_uint256 bnAvg;
|
||||||
pindexLast.nTime = 1269211443; // Block #46367 of Bitcoin
|
bnAvg.SetCompact(0x1c387f6f);
|
||||||
// This represents an average difficulty in the current algorithm
|
BOOST_CHECK_EQUAL(0x1c4a93bb,
|
||||||
pindexLast.nBits = 0x1c387f6f;
|
CalculateNextWorkRequired(bnAvg, nThisTime, nLastRetargetTime, params));
|
||||||
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1c4a93bb);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
|
BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)
|
||||||
|
|
Loading…
Reference in New Issue