Changeset View
Changeset View
Standalone View
Standalone View
src/test/checkpoints_tests.cpp
Show First 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | BOOST_FIXTURE_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")); | ||||
{ | { | ||||
BlockValidationState state; | BlockValidationState state; | ||||
BOOST_CHECK(Assert(m_node.chainman) | BOOST_CHECK( | ||||
->ProcessNewBlockHeaders(config, {headerG}, true, state, | Assert(m_node.chainman) | ||||
&pindex)); | ->ProcessNewBlockHeaders({headerG}, true, 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" | ||||
"000000982051fd1e4ba744bbbe680e1fee14677ba1a3c3540bf7b1cdb606e85723" | "000000982051fd1e4ba744bbbe680e1fee14677ba1a3c3540bf7b1cdb606e85723" | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | stream = CDataStream( | ||||
"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 | ||||
{ | { | ||||
BlockValidationState state; | BlockValidationState state; | ||||
BOOST_CHECK(Assert(m_node.chainman) | BOOST_CHECK( | ||||
->ProcessNewBlockHeaders(config, {headerA}, true, state, | Assert(m_node.chainman) | ||||
&pindex)); | ->ProcessNewBlockHeaders({headerA}, true, state, &pindex)); | ||||
BOOST_CHECK(state.IsValid()); | BOOST_CHECK(state.IsValid()); | ||||
BOOST_CHECK(pindex != nullptr); | BOOST_CHECK(pindex != nullptr); | ||||
pindex = nullptr; | pindex = nullptr; | ||||
} | } | ||||
{ | { | ||||
BlockValidationState state; | BlockValidationState state; | ||||
BOOST_CHECK(Assert(m_node.chainman) | BOOST_CHECK( | ||||
->ProcessNewBlockHeaders(config, {headerAA}, true, | Assert(m_node.chainman) | ||||
state, &pindex)); | ->ProcessNewBlockHeaders({headerAA}, true, 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 | ||||
{ | { | ||||
BlockValidationState state; | BlockValidationState state; | ||||
BOOST_CHECK(!Assert(m_node.chainman) | BOOST_CHECK( | ||||
->ProcessNewBlockHeaders(config, {headerB}, true, | !Assert(m_node.chainman) | ||||
state, &pindex)); | ->ProcessNewBlockHeaders({headerB}, true, state, &pindex)); | ||||
BOOST_CHECK(state.IsInvalid()); | BOOST_CHECK(state.IsInvalid()); | ||||
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(m_node.chainman->m_blockman.LookupBlockIndex( | BOOST_CHECK(m_node.chainman->m_blockman.LookupBlockIndex( | ||||
headerB.GetHash()) == nullptr); | headerB.GetHash()) == nullptr); | ||||
} | } | ||||
// Header AB should be rejected | // Header AB should be rejected | ||||
{ | { | ||||
BlockValidationState state; | BlockValidationState state; | ||||
BOOST_CHECK(!Assert(m_node.chainman) | BOOST_CHECK( | ||||
->ProcessNewBlockHeaders(config, {headerAB}, true, | !Assert(m_node.chainman) | ||||
state, &pindex)); | ->ProcessNewBlockHeaders({headerAB}, true, state, &pindex)); | ||||
BOOST_CHECK(state.IsInvalid()); | BOOST_CHECK(state.IsInvalid()); | ||||
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(m_node.chainman->m_blockman.LookupBlockIndex( | BOOST_CHECK(m_node.chainman->m_blockman.LookupBlockIndex( | ||||
headerAB.GetHash()) == nullptr); | headerAB.GetHash()) == nullptr); | ||||
} | } | ||||
} | } | ||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |