Changeset View
Changeset View
Standalone View
Standalone View
src/test/checkpoints_tests.cpp
Show First 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | BOOST_AUTO_TEST_CASE(ban_fork_prior_to_and_at_checkpoints) { | ||||
// Start with mainnet genesis block | // Start with mainnet genesis block | ||||
CBlockHeader headerG = config.GetChainParams().GenesisBlock(); | CBlockHeader headerG = config.GetChainParams().GenesisBlock(); | ||||
BOOST_CHECK(headerG.GetHash() == | BOOST_CHECK(headerG.GetHash() == | ||||
uint256S("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f" | uint256S("000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f" | ||||
"1b60a8ce26f")); | "1b60a8ce26f")); | ||||
{ | { | ||||
CValidationState state; | BlockValidationState state; | ||||
BOOST_CHECK(ProcessNewBlockHeaders(config, {headerG}, state, &pindex)); | BOOST_CHECK(ProcessNewBlockHeaders(config, {headerG}, state, &pindex)); | ||||
pindex = nullptr; | pindex = nullptr; | ||||
} | } | ||||
CBlockHeader headerA, headerB, headerAA, headerAB; | CBlockHeader headerA, headerB, headerAA, headerAB; | ||||
CDataStream stream = CDataStream( | CDataStream stream = CDataStream( | ||||
ParseHex( | ParseHex( | ||||
"010000006fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000" | "010000006fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000" | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | stream = CDataStream( | ||||
"322e302fffffffff0100f2052a010000002321020a56690eb0e2454c1f362d3599" | "322e302fffffffff0100f2052a010000002321020a56690eb0e2454c1f362d3599" | ||||
"89198a0b23505578be4164a65521ee7751eb1dac00000000"), | "89198a0b23505578be4164a65521ee7751eb1dac00000000"), | ||||
SER_NETWORK, PROTOCOL_VERSION); | SER_NETWORK, PROTOCOL_VERSION); | ||||
stream >> headerAB; | stream >> headerAB; | ||||
BOOST_CHECK(headerAB.hashPrevBlock == headerA.GetHash()); | BOOST_CHECK(headerAB.hashPrevBlock == headerA.GetHash()); | ||||
// Headers A and AA should be accepted | // Headers A and AA should be accepted | ||||
{ | { | ||||
CValidationState state; | BlockValidationState state; | ||||
BOOST_CHECK(ProcessNewBlockHeaders(config, {headerA}, state, &pindex)); | BOOST_CHECK(ProcessNewBlockHeaders(config, {headerA}, state, &pindex)); | ||||
BOOST_CHECK(state.IsValid()); | BOOST_CHECK(state.IsValid()); | ||||
BOOST_CHECK(pindex != nullptr); | BOOST_CHECK(pindex != nullptr); | ||||
pindex = nullptr; | pindex = nullptr; | ||||
} | } | ||||
{ | { | ||||
CValidationState state; | BlockValidationState state; | ||||
BOOST_CHECK(ProcessNewBlockHeaders(config, {headerAA}, state, &pindex)); | BOOST_CHECK(ProcessNewBlockHeaders(config, {headerAA}, state, &pindex)); | ||||
BOOST_CHECK(state.IsValid()); | BOOST_CHECK(state.IsValid()); | ||||
BOOST_CHECK(pindex != nullptr); | BOOST_CHECK(pindex != nullptr); | ||||
pindex = nullptr; | pindex = nullptr; | ||||
} | } | ||||
// Header B should be rejected | // Header B should be rejected | ||||
{ | { | ||||
CValidationState state; | BlockValidationState state; | ||||
BOOST_CHECK(!ProcessNewBlockHeaders(config, {headerB}, state, &pindex)); | BOOST_CHECK(!ProcessNewBlockHeaders(config, {headerB}, state, &pindex)); | ||||
BOOST_CHECK(state.IsInvalid()); | BOOST_CHECK(state.IsInvalid()); | ||||
BOOST_CHECK(state.GetRejectCode() == REJECT_CHECKPOINT); | BOOST_CHECK(state.GetRejectCode() == REJECT_CHECKPOINT); | ||||
BOOST_CHECK(state.GetRejectReason() == "bad-fork-prior-to-checkpoint"); | BOOST_CHECK(state.GetRejectReason() == "bad-fork-prior-to-checkpoint"); | ||||
BOOST_CHECK(pindex == nullptr); | BOOST_CHECK(pindex == nullptr); | ||||
} | } | ||||
// Sanity check to ensure header was not saved in memory | // Sanity check to ensure header was not saved in memory | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
BOOST_CHECK(LookupBlockIndex(headerB.GetHash()) == nullptr); | BOOST_CHECK(LookupBlockIndex(headerB.GetHash()) == nullptr); | ||||
} | } | ||||
// Header AB should be rejected | // Header AB should be rejected | ||||
{ | { | ||||
CValidationState state; | BlockValidationState state; | ||||
BOOST_CHECK( | BOOST_CHECK( | ||||
!ProcessNewBlockHeaders(config, {headerAB}, state, &pindex)); | !ProcessNewBlockHeaders(config, {headerAB}, state, &pindex)); | ||||
BOOST_CHECK(state.IsInvalid()); | BOOST_CHECK(state.IsInvalid()); | ||||
BOOST_CHECK(state.GetRejectCode() == REJECT_CHECKPOINT); | BOOST_CHECK(state.GetRejectCode() == REJECT_CHECKPOINT); | ||||
BOOST_CHECK(state.GetRejectReason() == "checkpoint mismatch"); | BOOST_CHECK(state.GetRejectReason() == "checkpoint mismatch"); | ||||
BOOST_CHECK(pindex == nullptr); | BOOST_CHECK(pindex == nullptr); | ||||
} | } | ||||
// Sanity check to ensure header was not saved in memory | // Sanity check to ensure header was not saved in memory | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
BOOST_CHECK(LookupBlockIndex(headerAB.GetHash()) == nullptr); | BOOST_CHECK(LookupBlockIndex(headerAB.GetHash()) == nullptr); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |