Changeset View
Changeset View
Standalone View
Standalone View
src/test/checkpoints_tests.cpp
Show All 18 Lines | |||||
#include <validation.h> | #include <validation.h> | ||||
#include <test/util/setup_common.h> | #include <test/util/setup_common.h> | ||||
#include <boost/test/unit_test.hpp> | #include <boost/test/unit_test.hpp> | ||||
#include <memory> | #include <memory> | ||||
BOOST_FIXTURE_TEST_SUITE(checkpoints_tests, TestingSetup) | BOOST_AUTO_TEST_SUITE(checkpoints_tests) | ||||
BOOST_AUTO_TEST_CASE(sanity) { | BOOST_FIXTURE_TEST_CASE(sanity, TestingSetup) { | ||||
const auto params = CreateChainParams(CBaseChainParams::MAIN); | const auto params = CreateChainParams(CBaseChainParams::MAIN); | ||||
const CCheckpointData &checkpoints = params->Checkpoints(); | const CCheckpointData &checkpoints = params->Checkpoints(); | ||||
BlockHash p11111 = BlockHash::fromHex( | BlockHash p11111 = BlockHash::fromHex( | ||||
"0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d"); | "0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d"); | ||||
BlockHash p134444 = BlockHash::fromHex( | BlockHash p134444 = BlockHash::fromHex( | ||||
"00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe"); | "00000000000005b12ffd4cd315cd34ffd4a594f430ac814c91184a0d42d2b0fe"); | ||||
BOOST_CHECK(Checkpoints::CheckBlock(checkpoints, 11111, p11111)); | BOOST_CHECK(Checkpoints::CheckBlock(checkpoints, 11111, p11111)); | ||||
BOOST_CHECK(Checkpoints::CheckBlock(checkpoints, 134444, p134444)); | BOOST_CHECK(Checkpoints::CheckBlock(checkpoints, 134444, p134444)); | ||||
Show All 27 Lines | static std::unique_ptr<CChainParams> createChainParams() { | ||||
"d1ace08b1a19da3fdcc99ddbd")}, | "d1ace08b1a19da3fdcc99ddbd")}, | ||||
}}; | }}; | ||||
const auto mainParams = CreateChainParams(CBaseChainParams::MAIN); | const auto mainParams = CreateChainParams(CBaseChainParams::MAIN); | ||||
return std::make_unique<ChainParamsWithCheckpoints>(*mainParams, | return std::make_unique<ChainParamsWithCheckpoints>(*mainParams, | ||||
checkpoints); | checkpoints); | ||||
} | } | ||||
}; | }; | ||||
static const MainnetConfigWithTestCheckpoints g_config{}; | |||||
struct CheckpointsTestingSetup : public TestingSetup { | |||||
CheckpointsTestingSetup() | |||||
: TestingSetup{CBaseChainParams::MAIN, /*extra_args=*/{}, | |||||
/*coins_db_in_memory=*/true, | |||||
/*block_tree_db_in_memory=*/true, g_config} {} | |||||
}; | |||||
/** | /** | ||||
* This test has 4 precomputed blocks mined ontop of the genesis block: | * This test has 4 precomputed blocks mined ontop of the genesis block: | ||||
* G ---> A ---> AA (checkpointed) | * G ---> A ---> AA (checkpointed) | ||||
* \ \ | * \ \ | ||||
* \--> B \-> AB | * \--> B \-> AB | ||||
* After the node has accepted only A and AA, these rejects should occur: | * After the node has accepted only A and AA, these rejects should occur: | ||||
* * B should be rejected for forking prior to an accepted checkpoint | * * B should be rejected for forking prior to an accepted checkpoint | ||||
* * AB should be rejected for forking at an accepted checkpoint | * * AB should be rejected for forking at an accepted checkpoint | ||||
*/ | */ | ||||
BOOST_AUTO_TEST_CASE(ban_fork_prior_to_and_at_checkpoints) { | BOOST_FIXTURE_TEST_CASE(ban_fork_prior_to_and_at_checkpoints, | ||||
MainnetConfigWithTestCheckpoints config; | CheckpointsTestingSetup) { | ||||
const Config &config = m_node.chainman->GetConfig(); | |||||
assert(std::addressof(config) == std::addressof(g_config)); | |||||
const CBlockIndex *pindex = nullptr; | const CBlockIndex *pindex = nullptr; | ||||
// 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")); | ||||
▲ Show 20 Lines • Show All 124 Lines • Show Last 20 Lines |