The two new tests cover the FLUSH pair and LoadBlockIndexDB's FATAL. Nothing covers the FATAL that WriteBlock returns when it cannot open the block file, and deleting the push_back for Failed to write block. leaves the whole suite green. The same directory trick from the flush test works here. I ran this one on the head, it passes, and it fails with that push_back removed. Worth adding?
}
BOOST_AUTO_TEST_CASE(blockmanager_returns_write_fatal_error)
{
const auto params{CreateChainParams(ArgsManager{}, ChainType::MAIN)};
const BlockManager::Options blockman_opts{
.chainparams = *params,
.blocks_dir = m_args.GetBlocksDirPath(),
.block_tree_db_params = DBParams{
.path = m_args.GetDataDirNet() / "blocks" / "index",
.cache_bytes = 0,
},
};
BlockManager blockman{*Assert(m_node.shutdown_signal), blockman_opts};
// Make the block file the next write would open impossible to open.
BOOST_REQUIRE(fs::create_directory(m_args.GetBlocksDirPath() / "blk00000.dat"));
CBlock block;
LOCK(::cs_main);
const auto outcome{blockman.WriteBlock(block, /*nHeight=*/0)};
BOOST_CHECK(outcome.value.IsNull());
BOOST_REQUIRE_EQUAL(outcome.notifications.size(), 1U);
BOOST_CHECK(outcome.notifications[0].type == node::BlockStorageErrorType::FATAL);
BOOST_CHECK_EQUAL(outcome.notifications[0].message.original, "Failed to write block.");
}