Changeset View
Changeset View
Standalone View
Standalone View
src/test/pow_tests.cpp
Show All 21 Lines | BOOST_AUTO_TEST_CASE(get_next_work) { | ||||
int64_t nLastRetargetTime = 1261130161; // Block #30240 | int64_t nLastRetargetTime = 1261130161; // Block #30240 | ||||
CBlockIndex pindexLast; | CBlockIndex pindexLast; | ||||
pindexLast.nHeight = 32255; | pindexLast.nHeight = 32255; | ||||
pindexLast.nTime = 1262152739; // Block #32255 | pindexLast.nTime = 1262152739; // Block #32255 | ||||
pindexLast.nBits = 0x1d00ffff; | pindexLast.nBits = 0x1d00ffff; | ||||
BOOST_CHECK_EQUAL( | BOOST_CHECK_EQUAL( | ||||
CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, config), | CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, config), | ||||
0x1d00d86a); | 0x1d00d86aU); | ||||
} | } | ||||
/* Test the constraint on the upper bound for next work */ | /* Test the constraint on the upper bound for next work */ | ||||
BOOST_AUTO_TEST_CASE(get_next_work_pow_limit) { | BOOST_AUTO_TEST_CASE(get_next_work_pow_limit) { | ||||
DummyConfig config(CBaseChainParams::MAIN); | DummyConfig config(CBaseChainParams::MAIN); | ||||
int64_t nLastRetargetTime = 1231006505; // Block #0 | int64_t nLastRetargetTime = 1231006505; // Block #0 | ||||
CBlockIndex pindexLast; | CBlockIndex pindexLast; | ||||
pindexLast.nHeight = 2015; | pindexLast.nHeight = 2015; | ||||
pindexLast.nTime = 1233061996; // Block #2015 | pindexLast.nTime = 1233061996; // Block #2015 | ||||
pindexLast.nBits = 0x1d00ffff; | pindexLast.nBits = 0x1d00ffff; | ||||
BOOST_CHECK_EQUAL( | BOOST_CHECK_EQUAL( | ||||
CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, config), | CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, config), | ||||
0x1d00ffff); | 0x1d00ffffU); | ||||
} | } | ||||
/* Test the constraint on the lower bound for actual time taken */ | /* Test the constraint on the lower bound for actual time taken */ | ||||
BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual) { | BOOST_AUTO_TEST_CASE(get_next_work_lower_limit_actual) { | ||||
DummyConfig config(CBaseChainParams::MAIN); | DummyConfig config(CBaseChainParams::MAIN); | ||||
int64_t nLastRetargetTime = 1279008237; // Block #66528 | int64_t nLastRetargetTime = 1279008237; // Block #66528 | ||||
CBlockIndex pindexLast; | CBlockIndex pindexLast; | ||||
pindexLast.nHeight = 68543; | pindexLast.nHeight = 68543; | ||||
pindexLast.nTime = 1279297671; // Block #68543 | pindexLast.nTime = 1279297671; // Block #68543 | ||||
pindexLast.nBits = 0x1c05a3f4; | pindexLast.nBits = 0x1c05a3f4; | ||||
BOOST_CHECK_EQUAL( | BOOST_CHECK_EQUAL( | ||||
CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, config), | CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, config), | ||||
0x1c0168fd); | 0x1c0168fdU); | ||||
} | } | ||||
/* Test the constraint on the upper bound for actual time taken */ | /* Test the constraint on the upper bound for actual time taken */ | ||||
BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual) { | BOOST_AUTO_TEST_CASE(get_next_work_upper_limit_actual) { | ||||
DummyConfig config(CBaseChainParams::MAIN); | DummyConfig config(CBaseChainParams::MAIN); | ||||
int64_t nLastRetargetTime = 1263163443; // NOTE: Not an actual block time | int64_t nLastRetargetTime = 1263163443; // NOTE: Not an actual block time | ||||
CBlockIndex pindexLast; | CBlockIndex pindexLast; | ||||
pindexLast.nHeight = 46367; | pindexLast.nHeight = 46367; | ||||
pindexLast.nTime = 1269211443; // Block #46367 | pindexLast.nTime = 1269211443; // Block #46367 | ||||
pindexLast.nBits = 0x1c387f6f; | pindexLast.nBits = 0x1c387f6f; | ||||
BOOST_CHECK_EQUAL( | BOOST_CHECK_EQUAL( | ||||
CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, config), | CalculateNextWorkRequired(&pindexLast, nLastRetargetTime, config), | ||||
0x1d00e1fd); | 0x1d00e1fdU); | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test) { | BOOST_AUTO_TEST_CASE(GetBlockProofEquivalentTime_test) { | ||||
DummyConfig config(CBaseChainParams::MAIN); | DummyConfig config(CBaseChainParams::MAIN); | ||||
std::vector<CBlockIndex> blocks(10000); | std::vector<CBlockIndex> blocks(10000); | ||||
for (int i = 0; i < 10000; i++) { | for (int i = 0; i < 10000; i++) { | ||||
blocks[i].pprev = i ? &blocks[i - 1] : nullptr; | blocks[i].pprev = i ? &blocks[i - 1] : nullptr; | ||||
▲ Show 20 Lines • Show All 291 Lines • Show Last 20 Lines |