refactor(test): Break up headers_sync_state
What changed, and why it matters
This commit only reorganizes existing test code in Bitcoin Core. It splits one large test case into three smaller, logically separate test cases and adds a missing comment. No production code, network behavior, or security-sensitive logic is changed.
No security action needed. This is a routine test-maintenance refactor.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change is a pure refactor of src/test/headers_sync_chainwork_tests.cpp. The single BOOST_AUTO_TEST_CASE(headers_sync_state) is broken into three cases: sneaky_redownload, happy_path, and too_little_work. Test logic, assertions, and the underlying HeadersSyncState implementation are unchanged. A previously shared unique_ptr and ProcessingResult are redeclared in each new test case, and a comment for part 4 is added.
Changed components
src/test/headers_sync_chainwork_tests.cppInspect captured patch +15 / −1
diff --git a/src/test/headers_sync_chainwork_tests.cpp b/src/test/headers_sync_chainwork_tests.cpp
index 51193328..c83fd29c 100644
--- a/src/test/headers_sync_chainwork_tests.cpp
+++ b/src/test/headers_sync_chainwork_tests.cpp
@@ -85,7 +85,7 @@ std::vector<CBlockHeader> HeadersGeneratorSetup::GenerateHeaders(
// phases is successful.
BOOST_FIXTURE_TEST_SUITE(headers_sync_chainwork_tests, HeadersGeneratorSetup)
-BOOST_AUTO_TEST_CASE(headers_sync_state)
+BOOST_AUTO_TEST_CASE(sneaky_redownload)
{
const auto& first_chain{FirstChain()};
const auto& second_chain{SecondChain()};
@@ -109,7 +109,14 @@ BOOST_AUTO_TEST_CASE(headers_sync_state)
result = hss->ProcessNextHeaders(second_chain, true);
BOOST_CHECK(!result.success); // foiled!
BOOST_CHECK(hss->GetState() == HeadersSyncState::State::FINAL);
+}
+BOOST_AUTO_TEST_CASE(happy_path)
+{
+ const auto& first_chain{FirstChain()};
+
+ std::unique_ptr<HeadersSyncState> hss;
+ HeadersSyncState::ProcessingResult result;
// Now try again, this time feeding the first chain twice.
hss.reset(new HeadersSyncState(0, Params().GetConsensus(), chain_start, CHAIN_WORK));
(void)hss->ProcessNextHeaders(first_chain, true);
@@ -122,7 +129,14 @@ BOOST_AUTO_TEST_CASE(headers_sync_state)
BOOST_CHECK(result.pow_validated_headers.size() == first_chain.size());
// Nothing left for the sync logic to do:
BOOST_CHECK(hss->GetState() == HeadersSyncState::State::FINAL);
+}
+BOOST_AUTO_TEST_CASE(too_little_work)
+{
+ const auto& second_chain{SecondChain()};
+
+ std::unique_ptr<HeadersSyncState> hss;
+ HeadersSyncState::ProcessingResult result;
// Finally, verify that just trying to process the second chain would not
// succeed (too little work)
hss.reset(new HeadersSyncState(0, Params().GetConsensus(), chain_start, CHAIN_WORK));
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.