Changeset View
Changeset View
Standalone View
Standalone View
src/test/blockfilter_index_tests.cpp
Show First 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | bool BuildChainTestingSetup::BuildChain( | ||||
chain.resize(length); | chain.resize(length); | ||||
for (auto &block : chain) { | for (auto &block : chain) { | ||||
block = std::make_shared<CBlock>( | block = std::make_shared<CBlock>( | ||||
CreateBlock(pindex, no_txns, coinbase_script_pub_key)); | CreateBlock(pindex, no_txns, coinbase_script_pub_key)); | ||||
CBlockHeader header = block->GetBlockHeader(); | CBlockHeader header = block->GetBlockHeader(); | ||||
BlockValidationState state; | BlockValidationState state; | ||||
if (!EnsureChainman(m_node).ProcessNewBlockHeaders( | if (!Assert(m_node.chainman) | ||||
GetConfig(), {header}, state, &pindex)) { | ->ProcessNewBlockHeaders(GetConfig(), {header}, state, | ||||
&pindex)) { | |||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, | BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | BOOST_FIXTURE_TEST_CASE(blockfilter_index_initial_sync, | ||||
std::vector<std::shared_ptr<CBlock>> chainA, chainB; | std::vector<std::shared_ptr<CBlock>> chainA, chainB; | ||||
BOOST_REQUIRE(BuildChain(tip, coinbase_script_pub_key_A, 10, chainA)); | BOOST_REQUIRE(BuildChain(tip, coinbase_script_pub_key_A, 10, chainA)); | ||||
BOOST_REQUIRE(BuildChain(tip, coinbase_script_pub_key_B, 10, chainB)); | BOOST_REQUIRE(BuildChain(tip, coinbase_script_pub_key_B, 10, chainB)); | ||||
// Check that new blocks on chain A get indexed. | // Check that new blocks on chain A get indexed. | ||||
uint256 chainA_last_header = last_header; | uint256 chainA_last_header = last_header; | ||||
for (size_t i = 0; i < 2; i++) { | for (size_t i = 0; i < 2; i++) { | ||||
const auto &block = chainA[i]; | const auto &block = chainA[i]; | ||||
BOOST_REQUIRE(EnsureChainman(m_node).ProcessNewBlock(GetConfig(), block, | BOOST_REQUIRE(Assert(m_node.chainman) | ||||
true, nullptr)); | ->ProcessNewBlock(GetConfig(), block, true, nullptr)); | ||||
} | } | ||||
for (size_t i = 0; i < 2; i++) { | for (size_t i = 0; i < 2; i++) { | ||||
const auto &block = chainA[i]; | const auto &block = chainA[i]; | ||||
const CBlockIndex *block_index; | const CBlockIndex *block_index; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
block_index = LookupBlockIndex(block->GetHash()); | block_index = LookupBlockIndex(block->GetHash()); | ||||
} | } | ||||
BOOST_CHECK(filter_index.BlockUntilSyncedToCurrentChain()); | BOOST_CHECK(filter_index.BlockUntilSyncedToCurrentChain()); | ||||
CheckFilterLookups(filter_index, block_index, chainA_last_header); | CheckFilterLookups(filter_index, block_index, chainA_last_header); | ||||
} | } | ||||
// Reorg to chain B. | // Reorg to chain B. | ||||
uint256 chainB_last_header = last_header; | uint256 chainB_last_header = last_header; | ||||
for (size_t i = 0; i < 3; i++) { | for (size_t i = 0; i < 3; i++) { | ||||
const auto &block = chainB[i]; | const auto &block = chainB[i]; | ||||
BOOST_REQUIRE(EnsureChainman(m_node).ProcessNewBlock(GetConfig(), block, | BOOST_REQUIRE(Assert(m_node.chainman) | ||||
true, nullptr)); | ->ProcessNewBlock(GetConfig(), block, true, nullptr)); | ||||
} | } | ||||
for (size_t i = 0; i < 3; i++) { | for (size_t i = 0; i < 3; i++) { | ||||
const auto &block = chainB[i]; | const auto &block = chainB[i]; | ||||
const CBlockIndex *block_index; | const CBlockIndex *block_index; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
block_index = LookupBlockIndex(block->GetHash()); | block_index = LookupBlockIndex(block->GetHash()); | ||||
} | } | ||||
Show All 14 Lines | for (size_t i = 0; i < 2; i++) { | ||||
BOOST_CHECK(filter_index.BlockUntilSyncedToCurrentChain()); | BOOST_CHECK(filter_index.BlockUntilSyncedToCurrentChain()); | ||||
CheckFilterLookups(filter_index, block_index, chainA_last_header); | CheckFilterLookups(filter_index, block_index, chainA_last_header); | ||||
} | } | ||||
// Reorg back to chain A. | // Reorg back to chain A. | ||||
for (size_t i = 2; i < 4; i++) { | for (size_t i = 2; i < 4; i++) { | ||||
const auto &block = chainA[i]; | const auto &block = chainA[i]; | ||||
BOOST_REQUIRE(EnsureChainman(m_node).ProcessNewBlock(GetConfig(), block, | BOOST_REQUIRE(Assert(m_node.chainman) | ||||
true, nullptr)); | ->ProcessNewBlock(GetConfig(), block, true, nullptr)); | ||||
} | } | ||||
// Check that chain A and B blocks can be retrieved. | // Check that chain A and B blocks can be retrieved. | ||||
chainA_last_header = last_header; | chainA_last_header = last_header; | ||||
chainB_last_header = last_header; | chainB_last_header = last_header; | ||||
for (size_t i = 0; i < 3; i++) { | for (size_t i = 0; i < 3; i++) { | ||||
const CBlockIndex *block_index; | const CBlockIndex *block_index; | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |