Skip to content

Commit 2bf1732

Browse files
committed
test: exercise ReadBlock hash‑mismatch path
Ensure `ReadBlock` rejects a block when the tip’s `phashBlock` differs from the expected hash.
1 parent 8309a97 commit 2bf1732

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/test/blockmanager_tests.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ BOOST_FIXTURE_TEST_CASE(blockmanager_block_data_availability, TestChain100Setup)
137137
BOOST_CHECK(!blockman.CheckBlockDataAvailability(tip, *last_pruned_block));
138138
}
139139

140+
BOOST_FIXTURE_TEST_CASE(blockmanager_readblock_hash_mismatch, TestingSetup)
141+
{
142+
CBlockIndex* fake_index{WITH_LOCK(m_node.chainman->GetMutex(), return m_node.chainman->ActiveChain().Tip())};
143+
fake_index->phashBlock = &uint256::ONE; // invalid block hash
144+
145+
ASSERT_DEBUG_LOG("GetHash() doesn't match index");
146+
CBlock dummy;
147+
BOOST_CHECK(!m_node.chainman->m_blockman.ReadBlock(dummy, *fake_index));
148+
}
149+
140150
BOOST_AUTO_TEST_CASE(blockmanager_flush_block_file)
141151
{
142152
KernelNotifications notifications{Assert(m_node.shutdown_request), m_node.exit_status, *Assert(m_node.warnings)};

0 commit comments

Comments
 (0)