MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / BOOST_FIXTURE_TEST_CASE

Function BOOST_FIXTURE_TEST_CASE

src/test/blockmanager_tests.cpp:63–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

61}
62
63BOOST_FIXTURE_TEST_CASE(blockmanager_scan_unlink_already_pruned_files, TestChain100Setup)
64{
65 // Cap last block file size, and mine new block in a new block file.
66 auto& chainman{*Assert(m_node.chainman)};
67 auto& blockman{chainman.m_blockman};
68 const CBlockIndex* old_tip{WITH_LOCK(chainman.GetMutex(), return chainman.ActiveChain().Tip())};
69 WITH_LOCK(chainman.GetMutex(), blockman.GetBlockFileInfo(old_tip->GetBlockPos().nFile)->nSize = MAX_BLOCKFILE_SIZE);
70 CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
71
72 // Prune the older block file, but don't unlink it
73 int file_number;
74 {
75 LOCK(chainman.GetMutex());
76 file_number = old_tip->GetBlockPos().nFile;
77 blockman.PruneOneBlockFile(file_number);
78 }
79
80 const FlatFilePos pos(file_number, 0);
81
82 // Check that the file is not unlinked after ScanAndUnlinkAlreadyPrunedFiles
83 // if m_have_pruned is not yet set
84 WITH_LOCK(chainman.GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles());
85 BOOST_CHECK(!blockman.OpenBlockFile(pos, true).IsNull());
86
87 // Check that the file is unlinked after ScanAndUnlinkAlreadyPrunedFiles
88 // once m_have_pruned is set
89 blockman.m_have_pruned = true;
90 WITH_LOCK(chainman.GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles());
91 BOOST_CHECK(blockman.OpenBlockFile(pos, true).IsNull());
92
93 // Check that calling with already pruned files doesn't cause an error
94 WITH_LOCK(chainman.GetMutex(), blockman.ScanAndUnlinkAlreadyPrunedFiles());
95
96 // Check that the new tip file has not been removed
97 const CBlockIndex* new_tip{WITH_LOCK(chainman.GetMutex(), return chainman.ActiveChain().Tip())};
98 BOOST_CHECK_NE(old_tip, new_tip);
99 const int new_file_number{WITH_LOCK(chainman.GetMutex(), return new_tip->GetBlockPos().nFile)};
100 const FlatFilePos new_pos(new_file_number, 0);
101 BOOST_CHECK(!blockman.OpenBlockFile(new_pos, true).IsNull());
102}
103
104BOOST_FIXTURE_TEST_CASE(blockmanager_block_data_availability, TestChain100Setup)
105{

Callers

nothing calls this directly

Calls 15

GetScriptForRawPubKeyFunction · 0.85
GetBlockFileInfoMethod · 0.80
PruneOneBlockFileMethod · 0.80
OpenBlockFileMethod · 0.80
ReadRawBlockMethod · 0.80
UpdatePruneLockMethod · 0.80
DeletePruneLockMethod · 0.80
TipMethod · 0.45
GetPubKeyMethod · 0.45
IsNullMethod · 0.45

Tested by

no test coverage detected