From 2bf173210fa1ba7b28fd312b2e62bc9ff45af598 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Mon, 12 May 2025 22:40:22 +0200 Subject: [PATCH] =?UTF-8?q?test:=20exercise=20`ReadBlock`=20hash=E2=80=91m?= =?UTF-8?q?ismatch=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ensure `ReadBlock` rejects a block when the tip’s `phashBlock` differs from the expected hash. --- src/test/blockmanager_tests.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/test/blockmanager_tests.cpp b/src/test/blockmanager_tests.cpp index 49e49b2d53..d1c64e786d 100644 --- a/src/test/blockmanager_tests.cpp +++ b/src/test/blockmanager_tests.cpp @@ -137,6 +137,16 @@ BOOST_FIXTURE_TEST_CASE(blockmanager_block_data_availability, TestChain100Setup) BOOST_CHECK(!blockman.CheckBlockDataAvailability(tip, *last_pruned_block)); } +BOOST_FIXTURE_TEST_CASE(blockmanager_readblock_hash_mismatch, TestingSetup) +{ + CBlockIndex* fake_index{WITH_LOCK(m_node.chainman->GetMutex(), return m_node.chainman->ActiveChain().Tip())}; + fake_index->phashBlock = &uint256::ONE; // invalid block hash + + ASSERT_DEBUG_LOG("GetHash() doesn't match index"); + CBlock dummy; + BOOST_CHECK(!m_node.chainman->m_blockman.ReadBlock(dummy, *fake_index)); +} + BOOST_AUTO_TEST_CASE(blockmanager_flush_block_file) { KernelNotifications notifications{Assert(m_node.shutdown_request), m_node.exit_status, *Assert(m_node.warnings)};