Browse Source

Remove unnecessary method

pull/4/head
Jack Grigg 8 years ago
parent
commit
4b37cfd5b8
  1. 13
      src/gtest/test_pow.cpp
  2. 8
      src/pow.cpp
  3. 1
      src/pow.h
  4. 44
      src/test/pow_tests.cpp

13
src/gtest/test_pow.cpp

@ -22,7 +22,10 @@ TEST(PoW, DifficultyAveraging) {
}
// 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(),
params),
GetNextWorkRequired(&blocks[lastBlk], nullptr, params));
@ -35,7 +38,9 @@ TEST(PoW, DifficultyAveraging) {
blocks[lastBlk].nTime += GetRand(params.nPowTargetSpacing/2) + 1;
// 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(),
params),
GetNextWorkRequired(&blocks[lastBlk], nullptr, params));
@ -46,7 +51,9 @@ TEST(PoW, DifficultyAveraging) {
blocks[lastBlk].nBits = 0x1e0fffff;
// 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(),
params),
GetNextWorkRequired(&blocks[lastBlk], nullptr, params));

8
src/pow.cpp

@ -43,14 +43,6 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead
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,
int64_t nLastBlockTime, int64_t nFirstBlockTime,
const Consensus::Params& params)

1
src/pow.h

@ -17,7 +17,6 @@ class uint256;
class arith_uint256;
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,
int64_t nLastBlockTime, int64_t nFirstBlockTime,
const Consensus::Params&);

44
src/test/pow_tests.cpp

@ -20,12 +20,11 @@ BOOST_AUTO_TEST_CASE(get_next_work)
const Consensus::Params& params = Params().GetConsensus();
int64_t nLastRetargetTime = 1262149169; // NOTE: Not an actual block time
CBlockIndex pindexLast;
pindexLast.nHeight = 32255;
pindexLast.nTime = 1262152739; // Block #32255 of Bitcoin
// This represents an average difficulty in the current algorithm
pindexLast.nBits = 0x1d00ffff;
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1d011998);
int64_t nThisTime = 1262152739; // Block #32255 of Bitcoin
arith_uint256 bnAvg;
bnAvg.SetCompact(0x1d00ffff);
BOOST_CHECK_EQUAL(0x1d011998,
CalculateNextWorkRequired(bnAvg, nThisTime, nLastRetargetTime, params));
}
/* 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();
int64_t nLastRetargetTime = 1231006505; // Block #0 of Bitcoin
CBlockIndex pindexLast;
pindexLast.nHeight = 2015;
pindexLast.nTime = 1233061996; // Block #2015 of Bitcoin
// This represents an average difficulty in the current algorithm
int64_t nThisTime = 1233061996; // Block #2015 of Bitcoin
arith_uint256 bnAvg;
// TODO change once the harder genesis block is generated
pindexLast.nBits = 0x200f0f0f;
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x200f0f0f);
bnAvg.SetCompact(0x200f0f0f);
BOOST_CHECK_EQUAL(0x200f0f0f,
CalculateNextWorkRequired(bnAvg, nThisTime, nLastRetargetTime, params));
}
/* 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();
int64_t nLastRetargetTime = 1279296753; // NOTE: Not an actual block time
CBlockIndex pindexLast;
pindexLast.nHeight = 68543;
pindexLast.nTime = 1279297671; // Block #68543 of Bitcoin
// This represents an average difficulty in the current algorithm
pindexLast.nBits = 0x1c05a3f4;
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1c04bceb);
int64_t nThisTime = 1279297671; // Block #68543 of Bitcoin
arith_uint256 bnAvg;
bnAvg.SetCompact(0x1c05a3f4);
BOOST_CHECK_EQUAL(0x1c04bceb,
CalculateNextWorkRequired(bnAvg, nThisTime, nLastRetargetTime, params));
}
/* 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();
int64_t nLastRetargetTime = 1269205629; // NOTE: Not an actual block time
CBlockIndex pindexLast;
pindexLast.nHeight = 46367;
pindexLast.nTime = 1269211443; // Block #46367 of Bitcoin
// This represents an average difficulty in the current algorithm
pindexLast.nBits = 0x1c387f6f;
BOOST_CHECK_EQUAL(CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, params), 0x1c4a93bb);
int64_t nThisTime = 1269211443; // Block #46367 of Bitcoin
arith_uint256 bnAvg;
bnAvg.SetCompact(0x1c387f6f);
BOOST_CHECK_EQUAL(0x1c4a93bb,
CalculateNextWorkRequired(bnAvg, nThisTime, nLastRetargetTime, params));
}
BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test)

Loading…
Cancel
Save