Repository: bitcoin/bitcoin
File: src/test/util_string_tests.cpp (C++)

Code before:
    {
        // Check three lines terminated by \n and \r\n, trimming whitespace
        const std::vector<std::byte> input{StringToBuffer("once upon a time\n there was a dog \r\nwho liked food\n")};
        LineReader reader(input, /*max_line_length=*/128);
        std::optional<std::string> line1{reader.ReadLine()};
        BOOST_CHECK_EQUAL(reader.Remaining(), 34);
        std::optional<std::string> line2{reader.ReadLine()};
        BOOST_CHECK_EQUAL(reader.Remaining(), 15);
        std::optional<std::string> line3{reader.ReadLine()};
        std::optional<std::string> line4{reader.ReadLine()};
        BOOST_CHECK(line1);
        BOOST_CHECK(line2);
        BOOST_CHECK(line3);
        BOOST_CHECK(!line4);
        BOOST_CHECK_EQUAL(line1.value(), "once upon a time");
        BOOST_CHECK_EQUAL(line2.value(), "there was a dog");
        BOOST_CHECK_EQUAL(line3.value(), "who liked food");
    }
    {
        // Do not exceed max_line_length + 1 while searching for \n
        // Test with 22-character line + \n + 23-character line + \n
        const std::vector<std::byte> input{StringToBuffer("once upon a time there\nwas a dog who liked tea\n")};

        LineReader reader1(input, /*max_line_length=*/22);
        // First line is exactly the length of max_line_length
        BOOST_CHECK_EQUAL(*reader1.ReadLine(), "once upon a time there");
        // Second line is +1 character too long
        BOOST_CHECK_EXCEPTION(reader1.ReadLine(), std::runtime_error, HasReason{"max_line_length exceeded by LineReader"});

        // Increase max_line_length by 1
        LineReader reader2(input, /*max_line_length=*/23);
        // Both lines fit within limit
        BOOST_CHECK_EQUAL(*reader2.ReadLine(), "once upon a time there");
        BOOST_CHECK_EQUAL(*reader2.ReadLine(), "was a dog who liked tea");
        // End of buffer reached
        BOOST_CHECK(!reader2.ReadLine());
    }
    {
        // Empty lines are empty
        const std::vector<std::byte> input{StringToBuffer("\n")};
        LineReader reader(input, /*max_line_length=*/1024);
        BOOST_CHECK_EQUAL(*reader.ReadLine(), "");
        BOOST_CHECK(!reader.ReadLine());
    }
    {
        // Empty buffers are null
        const std::vector<std::byte> input{StringToBuffer("")};
        LineReader reader(input, /*max_line_length=*/1024);
        BOOST_CHECK(!reader.ReadLine());
    }
    {

Review comment (bug):
In c9e6f2725b6efc4b41dd0e2851781a521684c172 "test: refactor, decouple HasReason from test framework machinery":

All of these changes to prevent https://en.cppreference.com/w/cpp/utility/optional/operator_cmp.html (21), comparing `optional` with value, from being used should be dropped IMO.
```suggestion
        BOOST_CHECK_EQUAL(reader1.ReadLine(), "once upon a time there");
```
Doing that requires keeping the #include of setup_common.h, or moving the ostream `operator<<` implementations from setup_common.h/cpp to common.h, which may be a more suitable place anyway.

<details><summary>Full patch on top of that commit</summary>

```diff
diff --git a/src/test/arith_uint256_tests.cpp b/src/test/arith_uint256_tests.cpp
index 0a15458041..016b465871 100644
--- a/src/test/arith_uint256_tests.cpp
+++ b/src/test/arith_uint256_tests.cpp
@@ -3,7 +3,7 @@
 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
 
 #include <arith_uint256.h>
-#include <test/util/setup_common.h>
+#include <test/util/common.h>
 #include <uint256.h>
 
 #include <boost/test/unit_test.hpp>
diff --git a/src/test/blockencodings_tests.cpp b/src/test/blockencodings_tests.cpp
index 0fbe0f3c13..e4200cace2 100644
--- a/src/test/blockencodings_tests.cpp
+++ b/src/test/blockencodings_tests.cpp
@@ -10,6 +10,7 @@
 #include <test/util/random.h>
 #include <test/util/txmempool.h>
 
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 
 #include <boost/test/unit_test.hpp>
diff --git a/src/test/blockfilter_index_tests.cpp b/src/test/blockfilter_index_tests.cpp
index d7d10dfb1a..25762e070d 100644
--- a/src/test/blockfilter_index_tests.cpp
+++ b/src/test/blockfilter_index_tests.cpp
@@ -12,6 +12,7 @@
 #include <node/miner.h>
 #include <pow.h>
 #include <test/util/blockfilter.h>
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 #include <validation.h>
 
diff --git a/src/test/blockfilter_tests.cpp b/src/test/blockfilter_tests.cpp
index c8334dabe1..e89909dfaa 100644
--- a/src/test/blockfilter_tests.cpp
+++ b/src/test/blockfilter_tests.cpp
@@ -3,6 +3,7 @@
 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
 
 #include <test/data/blockfilters.json.h>
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 
 #include <blockfilter.h>
diff --git a/src/test/blockmanager_tests.cpp b/src/test/blockmanager_tests.cpp
index db59931ba7..28bb7b70a7 100644
--- a/src/test/blockmanager_tests.cpp
+++ b/src/test/blockmanager_tests.cpp
@@ -14,6 +14,7 @@
 #include <validation.h>
 
 #include <boost/test/unit_test.hpp>
+#include <test/util/common.h>
 #include <test/util/logging.h>
 #include <test/util/setup_common.h>
 
diff --git a/src/test/bloom_tests.cpp b/src/test/bloom_tests.cpp
index 8e02cfd08c..ed333c34c0 100644
--- a/src/test/bloom_tests.cpp
+++ b/src/test/bloom_tests.cpp
@@ -13,6 +13,7 @@
 #include <random.h>
 #include <serialize.h>
 #include <streams.h>
+#include <test/util/common.h>
 #include <test/util/random.h>
 #include <test/util/setup_common.h>
 #include <uint256.h>
diff --git a/src/test/crypto_tests.cpp b/src/test/crypto_tests.cpp
index 5588d4cdbc..b348793bfb 100644
--- a/src/test/crypto_tests.cpp
+++ b/src/test/crypto_tests.cpp
@@ -17,6 +17,7 @@
 #include <crypto/muhash.h>
 #include <random.h>
 #include <streams.h>
+#include <test/util/common.h>
 #include <test/util/random.h>
 #include <test/util/setup_common.h>
 #include <util/strencodings.h>
diff --git a/src/test/dbwrapper_tests.cpp b/src/test/dbwrapper_tests.cpp
index d3a9e54348..3896ea64da 100644
--- a/src/test/dbwrapper_tests.cpp
+++ b/src/test/dbwrapper_tests.cpp
@@ -3,6 +3,7 @@
 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
 
 #include <dbwrapper.h>
+#include <test/util/common.h>
 #include <test/util/random.h>
 #include <test/util/setup_common.h>
 #include <uint256.h>
diff --git a/src/test/getarg_tests.cpp b/src/test/getarg_tests.cpp
index ec17fe3997..d349ceea44 100644
--- a/src/test/getarg_tests.cpp
+++ b/src/test/getarg_tests.cpp
@@ -5,6 +5,7 @@
 #include <common/args.h>
 #include <common/settings.h>
 #include <logging.h>
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 #include <univalue.h>
 #include <util/strencodings.h>
diff --git a/src/test/headers_sync_chainwork_tests.cpp b/src/test/headers_sync_chainwork_tests.cpp
index f9426fa311..bba612f8b4 100644
--- a/src/test/headers_sync_chainwork_tests.cpp
+++ b/src/test/headers_sync_chainwork_tests.cpp
@@ -8,6 +8,7 @@
 #include <headerssync.h>
 #include <net_processing.h>
 #include <pow.h>
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 #include <validation.h>
 
diff --git a/src/test/interfaces_tests.cpp b/src/test/interfaces_tests.cpp
index da0f5eecce..1a98256ce2 100644
--- a/src/test/interfaces_tests.cpp
+++ b/src/test/interfaces_tests.cpp
@@ -5,6 +5,7 @@
 #include <chainparams.h>
 #include <consensus/validation.h>
 #include <interfaces/chain.h>
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 #include <script/solver.h>
 #include <validation.h>
diff --git a/src/test/key_tests.cpp b/src/test/key_tests.cpp
index acced716f0..b0c052af0f 100644
--- a/src/test/key_tests.cpp
+++ b/src/test/key_tests.cpp
@@ -9,6 +9,7 @@
 #include <span.h>
 #include <streams.h>
 #include <secp256k1_extrakeys.h>
+#include <test/util/common.h>
 #include <test/util/random.h>
 #include <test/util/setup_common.h>
 #include <uint256.h>
diff --git a/src/test/logging_tests.cpp b/src/test/logging_tests.cpp
index 8ead946f7f..f232bb4181 100644
--- a/src/test/logging_tests.cpp
+++ b/src/test/logging_tests.cpp
@@ -6,6 +6,7 @@
 #include <logging.h>
 #include <logging/timer.h>
 #include <scheduler.h>
+#include <test/util/common.h>
 #include <test/util/logging.h>
 #include <test/util/setup_common.h>
 #include <tinyformat.h>
diff --git a/src/test/merkle_tests.cpp b/src/test/merkle_tests.cpp
index dc4791419e..a7212147b6 100644
--- a/src/test/merkle_tests.cpp
+++ b/src/test/merkle_tests.cpp
@@ -3,6 +3,7 @@
 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
 
 #include <consensus/merkle.h>
+#include <test/util/common.h>
 #include <test/util/random.h>
 #include <test/util/setup_common.h>
 
diff --git a/src/test/merkleblock_tests.cpp b/src/test/merkleblock_tests.cpp
index 00a1f0b92d..a461e04300 100644
--- a/src/test/merkleblock_tests.cpp
+++ b/src/test/merkleblock_tests.cpp
@@ -3,6 +3,7 @@
 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
 
 #include <merkleblock.h>
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 #include <uint256.h>
 
diff --git a/src/test/minisketch_tests.cpp b/src/test/minisketch_tests.cpp
index 1d6f2a12ef..ba895478de 100644
--- a/src/test/minisketch_tests.cpp
+++ b/src/test/minisketch_tests.cpp
@@ -5,6 +5,7 @@
 #include <minisketch.h>
 #include <node/minisketchwrapper.h>
 #include <random.h>
+#include <test/util/common.h>
 #include <test/util/random.h>
 #include <test/util/setup_common.h>
 
diff --git a/src/test/multisig_tests.cpp b/src/test/multisig_tests.cpp
index 932b83fee4..0b1cc98086 100644
--- a/src/test/multisig_tests.cpp
+++ b/src/test/multisig_tests.cpp
@@ -9,6 +9,7 @@
 #include <script/script_error.h>
 #include <script/sign.h>
 #include <script/signingprovider.h>
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 #include <test/util/transaction_utils.h>
 #include <tinyformat.h>
diff --git a/src/test/netbase_tests.cpp b/src/test/netbase_tests.cpp
index 4770cabf7a..167b88f5f3 100644
--- a/src/test/netbase_tests.cpp
+++ b/src/test/netbase_tests.cpp
@@ -10,7 +10,7 @@
 #include <protocol.h>
 #include <serialize.h>
 #include <streams.h>
-#include <test/util/setup_common.h>
+#include <test/util/common.h>
 #include <util/strencodings.h>
 #include <util/translation.h>
 
@@ -22,7 +22,7 @@
 using namespace std::literals;
 using namespace util::hex_literals;
 
-BOOST_FIXTURE_TEST_SUITE(netbase_tests, BasicTestingSetup)
+BOOST_AUTO_TEST_SUITE(netbase_tests)
 
 static CNetAddr ResolveIP(const std::string& ip)
 {
diff --git a/src/test/node_init_tests.cpp b/src/test/node_init_tests.cpp
index a4292e66ca..44635dd4aa 100644
--- a/src/test/node_init_tests.cpp
+++ b/src/test/node_init_tests.cpp
@@ -7,6 +7,7 @@
 #include <rpc/server.h>
 
 #include <boost/test/unit_test.hpp>
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 
 using node::NodeContext;
diff --git a/src/test/orphanage_tests.cpp b/src/test/orphanage_tests.cpp
index 933736dcc1..6ebfab34c5 100644
--- a/src/test/orphanage_tests.cpp
+++ b/src/test/orphanage_tests.cpp
@@ -10,6 +10,7 @@
 #include <pubkey.h>
 #include <script/sign.h>
 #include <script/signingprovider.h>
+#include <test/util/common.h>
 #include <test/util/random.h>
 #include <test/util/setup_common.h>
 #include <test/util/transaction_utils.h>
diff --git a/src/test/pcp_tests.cpp b/src/test/pcp_tests.cpp
index c71c9de160..51b004a5d5 100644
--- a/src/test/pcp_tests.cpp
+++ b/src/test/pcp_tests.cpp
@@ -5,6 +5,7 @@
 #include <common/pcp.h>
 #include <netbase.h>
 #include <test/util/logging.h>
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 #include <util/time.h>
 
diff --git a/src/test/pow_tests.cpp b/src/test/pow_tests.cpp
index 8de76ff21f..f6123401ad 100644
--- a/src/test/pow_tests.cpp
+++ b/src/test/pow_tests.cpp
@@ -6,6 +6,7 @@
 #include <chainparams.h>
 #include <pow.h>
 #include <test/util/random.h>
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 #include <util/chaintype.h>
 
diff --git a/src/test/rest_tests.cpp b/src/test/rest_tests.cpp
index 5dc122507f..fefc41bd73 100644
--- a/src/test/rest_tests.cpp
+++ b/src/test/rest_tests.cpp
@@ -3,6 +3,7 @@
 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
 
 #include <rest.h>
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 
 #include <boost/test/unit_test.hpp>
diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp
index f8d75a8022..b435fb8992 100644
--- a/src/test/rpc_tests.cpp
+++ b/src/test/rpc_tests.cpp
@@ -9,6 +9,7 @@
 #include <rpc/client.h>
 #include <rpc/server.h>
 #include <rpc/util.h>
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 #include <univalue.h>
 #include <util/time.h>
diff --git a/src/test/script_standard_tests.cpp b/src/test/script_standard_tests.cpp
index c6d3b125eb..63215895ff 100644
--- a/src/test/script_standard_tests.cpp
+++ b/src/test/script_standard_tests.cpp
@@ -10,16 +10,24 @@
 #include <script/script.h>
 #include <script/signingprovider.h>
 #include <script/solver.h>
-#include <test/util/setup_common.h>
+#include <test/util/common.h>
 #include <util/strencodings.h>
 
 #include <boost/test/unit_test.hpp>
+#include <boost/test/unit_test_suite.hpp>
 
 #include <univalue.h>
 
 using namespace util::hex_literals;
 
-BOOST_FIXTURE_TEST_SUITE(script_standard_tests, BasicTestingSetup)
+namespace {
+struct ScriptStandardTest {
+    ECC_Context ecc;
+    ScriptStandardTest() { SelectParams(ChainType::MAIN); }
+};
+} // namespace
+
+BOOST_FIXTURE_TEST_SUITE(script_standard_tests, ScriptStandardTest)
 
 BOOST_AUTO_TEST_CASE(dest_default_is_no_dest)
 {
diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp
index 2134bcc179..1478cf9125 100644
--- a/src/test/script_tests.cpp
+++ b/src/test/script_tests.cpp
@@ -19,6 +19,7 @@
 #include <streams.h>
 #include <test/util/json.h>
 #include <test/util/random.h>
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 #include <test/util/transaction_utils.h>
 #include <util/fs.h>
@@ -26,7 +27,6 @@
 #include <util/string.h>
 
 #include <cstdint>
-#include <fstream>
 #include <string>
 #include <vector>
 
diff --git a/src/test/serialize_tests.cpp b/src/test/serialize_tests.cpp
index 33a9133d2e..f646ba5faf 100644
--- a/src/test/serialize_tests.cpp
+++ b/src/test/serialize_tests.cpp
@@ -5,6 +5,7 @@
 #include <hash.h>
 #include <serialize.h>
 #include <streams.h>
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 #include <util/strencodings.h>
 
diff --git a/src/test/sighash_tests.cpp b/src/test/sighash_tests.cpp
index 5d65c35a8c..5afdea43d8 100644
--- a/src/test/sighash_tests.cpp
+++ b/src/test/sighash_tests.cpp
@@ -11,6 +11,7 @@
 #include <serialize.h>
 #include <streams.h>
 #include <test/data/sighash.json.h>
+#include <test/util/common.h>
 #include <test/util/json.h>
 #include <test/util/random.h>
 #include <test/util/setup_common.h>
diff --git a/src/test/txdownload_tests.cpp b/src/test/txdownload_tests.cpp
index e9c6160ebf..d7ddef905b 100644
--- a/src/test/txdownload_tests.cpp
+++ b/src/test/txdownload_tests.cpp
@@ -8,6 +8,7 @@
 #include <node/txdownloadman_impl.h>
 #include <primitives/transaction.h>
 #include <script/script.h>
+#include <test/util/common.h>
 #include <test/util/random.h>
 #include <test/util/setup_common.h>
 #include <validation.h>
diff --git a/src/test/txpackage_tests.cpp b/src/test/txpackage_tests.cpp
index 24760664c1..06c5816b72 100644
--- a/src/test/txpackage_tests.cpp
+++ b/src/test/txpackage_tests.cpp
@@ -11,6 +11,7 @@
 #include <script/script.h>
 #include <serialize.h>
 #include <streams.h>
+#include <test/util/common.h>
 #include <test/util/random.h>
 #include <test/util/script.h>
 #include <test/util/setup_common.h>
diff --git a/src/test/txreconciliation_tests.cpp b/src/test/txreconciliation_tests.cpp
index d4ed3511f4..8d1a47b6e3 100644
--- a/src/test/txreconciliation_tests.cpp
+++ b/src/test/txreconciliation_tests.cpp
@@ -4,11 +4,11 @@
 
 #include <node/txreconciliation.h>
 
-#include <test/util/setup_common.h>
+#include <test/util/common.h>
 
 #include <boost/test/unit_test.hpp>
 
-BOOST_FIXTURE_TEST_SUITE(txreconciliation_tests, BasicTestingSetup)
+BOOST_AUTO_TEST_SUITE(txreconciliation_tests)
 
 BOOST_AUTO_TEST_CASE(RegisterPeerTest)
 {
diff --git a/src/test/txvalidation_tests.cpp b/src/test/txvalidation_tests.cpp
index b16b60474a..2a4f213c4b 100644
--- a/src/test/txvalidation_tests.cpp
+++ b/src/test/txvalidation_tests.cpp
@@ -11,6 +11,7 @@
 #include <primitives/transaction.h>
 #include <random.h>
 #include <script/script.h>
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 #include <test/util/txmempool.h>
 #include <validation.h>
diff --git a/src/test/uint256_tests.cpp b/src/test/uint256_tests.cpp
index a4ebc049fb..0de391d8cc 100644
--- a/src/test/uint256_tests.cpp
+++ b/src/test/uint256_tests.cpp
@@ -4,7 +4,7 @@
 
 #include <primitives/transaction_identifier.h>
 #include <streams.h>
-#include <test/util/setup_common.h>
+#include <test/util/common.h>
 #include <uint256.h>
 #include <util/strencodings.h>
 
diff --git a/src/test/util/common.h b/src/test/util/common.h
index 788df0d3fe..9d5b70d9c8 100644
--- a/src/test/util/common.h
+++ b/src/test/util/common.h
@@ -5,6 +5,8 @@
 #ifndef BITCOIN_TEST_UTIL_COMMON_H
 #define BITCOIN_TEST_UTIL_COMMON_H
 
+#include <primitives/transaction_identifier.h>
+#include <arith_uint256.h>
 #include <string>
 
 /**
@@ -23,4 +25,47 @@ private:
     const std::string m_reason;
 };
 
+// Make types usable in BOOST_CHECK_* @{
+namespace std {
+template <typename T> requires std::is_enum_v<T>
+inline std::ostream& operator<<(std::ostream& os, const T& e)
+{
+    return os << static_cast<std::underlying_type_t<T>>(e);
+}
+
+template <typename T>
+inline std::ostream& operator<<(std::ostream& os, const std::optional<T>& v)
+{
+    return v ? os << *v
+             : os << "std::nullopt";
+}
+} // namespace std
+
+inline std::ostream& operator<<(std::ostream& os, const arith_uint256& num)
+{
+    return os << num.ToString();
+}
+
+inline std::ostream& operator<<(std::ostream& os, const uint160& num)
+{
+    return os << num.ToString();
+}
+
+inline std::ostream& operator<<(std::ostream& os, const uint256& num)
+{
+    return os << num.ToString();
+}
+
+inline std::ostream& operator<<(std::ostream& os, const Txid& txid)
+{
+    return os << txid.ToString();
+}
+
+inline std::ostream& operator<<(std::ostream& os, const Wtxid& wtxid)
+{
+    return os << wtxid.ToString();
+}
+
+// @}
+
 #endif // BITCOIN_TEST_UTIL_COMMON_H
diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp
index 995f532fd7..6fdc9e1882 100644
--- a/src/test/util/setup_common.cpp
+++ b/src/test/util/setup_common.cpp
@@ -620,26 +620,3 @@ CBlock getBlock13b8a()
     stream >> TX_WITH_WITNESS(block);
     return block;
 }
-
-std::ostream& operator<<(std::ostream& os, const arith_uint256& num)
-{
-    return os << num.ToString();
-}
-
-std::ostream& operator<<(std::ostream& os, const uint160& num)
-{
-    return os << num.ToString();
-}
-
-std::ostream& operator<<(std::ostream& os, const uint256& num)
-{
-    return os << num.ToString();
-}
-
-std::ostream& operator<<(std::ostream& os, const Txid& txid) {
-    return os << txid.ToString();
-}
-
-std::ostream& operator<<(std::ostream& os, const Wtxid& wtxid) {
-    return os << wtxid.ToString();
-}
diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h
index 1f71b21a25..c02a4fd331 100644
--- a/src/test/util/setup_common.h
+++ b/src/test/util/setup_common.h
@@ -261,27 +261,4 @@ std::unique_ptr<T> MakeNoLogFileContext(const ChainType chain_type = ChainType::
 
 CBlock getBlock13b8a();
 
-// Make types usable in BOOST_CHECK_* @{
-namespace std {
-template <typename T> requires std::is_enum_v<T>
-inline std::ostream& operator<<(std::ostream& os, const T& e)
-{
-    return os << static_cast<std::underlying_type_t<T>>(e);
-}
-
-template <typename T>
-inline std::ostream& operator<<(std::ostream& os, const std::optional<T>& v)
-{
-    return v ? os << *v
-             : os << "std::nullopt";
-}
-} // namespace std
-
-std::ostream& operator<<(std::ostream& os, const arith_uint256& num);
-std::ostream& operator<<(std::ostream& os, const uint160& num);
-std::ostream& operator<<(std::ostream& os, const uint256& num);
-std::ostream& operator<<(std::ostream& os, const Txid& txid);
-std::ostream& operator<<(std::ostream& os, const Wtxid& wtxid);
-// @}
-
 #endif // BITCOIN_TEST_UTIL_SETUP_COMMON_H
diff --git a/src/test/util_string_tests.cpp b/src/test/util_string_tests.cpp
index 69a6c9c110..7757695085 100644
--- a/src/test/util_string_tests.cpp
+++ b/src/test/util_string_tests.cpp
@@ -216,15 +216,15 @@ BOOST_AUTO_TEST_CASE(line_reader_test)
 
         LineReader reader1(input, /*max_line_length=*/22);
         // First line is exactly the length of max_line_length
-        BOOST_CHECK_EQUAL(*reader1.ReadLine(), "once upon a time there");
+        BOOST_CHECK_EQUAL(reader1.ReadLine(), "once upon a time there");
         // Second line is +1 character too long
         BOOST_CHECK_EXCEPTION(reader1.ReadLine(), std::runtime_error, HasReason{"max_line_length exceeded by LineReader"});
 
         // Increase max_line_length by 1
         LineReader reader2(input, /*max_line_length=*/23);
         // Both lines fit within limit
-        BOOST_CHECK_EQUAL(*reader2.ReadLine(), "once upon a time there");
-        BOOST_CHECK_EQUAL(*reader2.ReadLine(), "was a dog who liked tea");
+        BOOST_CHECK_EQUAL(reader2.ReadLine(), "once upon a time there");
+        BOOST_CHECK_EQUAL(reader2.ReadLine(), "was a dog who liked tea");
         // End of buffer reached
         BOOST_CHECK(!reader2.ReadLine());
     }
@@ -232,7 +232,7 @@ BOOST_AUTO_TEST_CASE(line_reader_test)
         // Empty lines are empty
         const std::vector<std::byte> input{StringToBuffer("\n")};
         LineReader reader(input, /*max_line_length=*/1024);
-        BOOST_CHECK_EQUAL(*reader.ReadLine(), "");
+        BOOST_CHECK_EQUAL(reader.ReadLine(), "");
         BOOST_CHECK(!reader.ReadLine());
     }
     {
@@ -251,15 +251,15 @@ BOOST_AUTO_TEST_CASE(line_reader_test)
     {
         const std::vector<std::byte> input{StringToBuffer("a\nb\n")};
         LineReader reader(input, /*max_line_length=*/1);
-        BOOST_CHECK_EQUAL(*reader.ReadLine(), "a");
-        BOOST_CHECK_EQUAL(*reader.ReadLine(), "b");
+        BOOST_CHECK_EQUAL(reader.ReadLine(), "a");
+        BOOST_CHECK_EQUAL(reader.ReadLine(), "b");
         BOOST_CHECK(!reader.ReadLine());
     }
     {
         // If ReadLine fails, the iterator is reset and we can ReadLength instead
         const std::vector<std::byte> input{StringToBuffer("a\nbaboon\n")};
         LineReader reader(input, /*max_line_length=*/1);
-        BOOST_CHECK_EQUAL(*reader.ReadLine(), "a");
+        BOOST_CHECK_EQUAL(reader.ReadLine(), "a");
         // "baboon" is too long
         BOOST_CHECK_EXCEPTION(reader.ReadLine(), std::runtime_error, HasReason{"max_line_length exceeded by LineReader"});
         BOOST_CHECK_EQUAL(reader.ReadLength(1), "b");
@@ -268,7 +268,7 @@ BOOST_AUTO_TEST_CASE(line_reader_test)
         // "on" is too long
         BOOST_CHECK_EXCEPTION(reader.ReadLine(), std::runtime_error, HasReason{"max_line_length exceeded by LineReader"});
         BOOST_CHECK_EQUAL(reader.ReadLength(1), "o");
-        BOOST_CHECK_EQUAL(*reader.ReadLine(), "n"); // now the remainder of the buffer fits in one line
+        BOOST_CHECK_EQUAL(reader.ReadLine(), "n"); // now the remainder of the buffer fits in one line
         BOOST_CHECK(!reader.ReadLine());
     }
     {
diff --git a/src/test/validation_block_tests.cpp b/src/test/validation_block_tests.cpp
index f91b30a307..083a32da96 100644
--- a/src/test/validation_block_tests.cpp
+++ b/src/test/validation_block_tests.cpp
@@ -10,6 +10,7 @@
 #include <node/miner.h>
 #include <pow.h>
 #include <random.h>
+#include <test/util/common.h>
 #include <test/util/random.h>
 #include <test/util/script.h>
 #include <test/util/setup_common.h>
diff --git a/src/test/validation_chainstate_tests.cpp b/src/test/validation_chainstate_tests.cpp
index 9e2c710977..df5e522edd 100644
--- a/src/test/validation_chainstate_tests.cpp
+++ b/src/test/validation_chainstate_tests.cpp
@@ -9,6 +9,7 @@
 #include <rpc/blockchain.h>
 #include <sync.h>
 #include <test/util/chainstate.h>
+#include <test/util/common.h>
 #include <test/util/coins.h>
 #include <test/util/random.h>
 #include <test/util/setup_common.h>
diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp
index 40f99690ce..06de793d25 100644
--- a/src/test/validation_chainstatemanager_tests.cpp
+++ b/src/test/validation_chainstatemanager_tests.cpp
@@ -12,6 +12,7 @@
 #include <rpc/blockchain.h>
 #include <sync.h>
 #include <test/util/chainstate.h>
+#include <test/util/common.h>
 #include <test/util/logging.h>
 #include <test/util/random.h>
 #include <test/util/setup_common.h>
diff --git a/src/test/validation_flush_tests.cpp b/src/test/validation_flush_tests.cpp
index 66c284b979..c35cef7f45 100644
--- a/src/test/validation_flush_tests.cpp
+++ b/src/test/validation_flush_tests.cpp
@@ -5,6 +5,7 @@
 #include <sync.h>
 #include <test/util/coins.h>
 #include <test/util/random.h>
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 #include <validation.h>
 
diff --git a/src/test/versionbits_tests.cpp b/src/test/versionbits_tests.cpp
index ea1044023e..ad79205311 100644
--- a/src/test/versionbits_tests.cpp
+++ b/src/test/versionbits_tests.cpp
@@ -6,6 +6,7 @@
 #include <chainparams.h>
 #include <consensus/params.h>
 #include <test/util/random.h>
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 #include <util/chaintype.h>
 #include <versionbits.h>
diff --git a/src/wallet/test/coinselector_tests.cpp b/src/wallet/test/coinselector_tests.cpp
index 7f55d76585..92a35b08af 100644
--- a/src/wallet/test/coinselector_tests.cpp
+++ b/src/wallet/test/coinselector_tests.cpp
@@ -7,6 +7,7 @@
 #include <policy/policy.h>
 #include <primitives/transaction.h>
 #include <random.h>
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 #include <util/translation.h>
 #include <wallet/coincontrol.h>
diff --git a/src/wallet/test/db_tests.cpp b/src/wallet/test/db_tests.cpp
index 8b71634ed8..532bdce384 100644
--- a/src/wallet/test/db_tests.cpp
+++ b/src/wallet/test/db_tests.cpp
@@ -4,6 +4,7 @@
 
 #include <boost/test/unit_test.hpp>
 
+#include <test/util/common.h>
 #include <test/util/setup_common.h>
 #include <util/check.h>
 #include <util/fs.h>
@@ -14,7 +15,6 @@
 #include <wallet/walletutil.h>
 
 #include <cstddef>
-#include <fstream>
 #include <memory>
 #include <span>
 #include <string>
diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp
index 36782cd187..54f453623e 100644
--- a/src/wallet/test/wallet_tests.cpp
+++ b/src/wallet/test/wallet_tests.cpp
@@ -17,6 +17,7 @@
 #include <policy/policy.h>
 #include <rpc/server.h>
 #include <script/solver.h>
+#include <test/util/common.h>
 #include <test/util/logging.h>
 #include <test/util/random.h>
 #include <test/util/setup_common.h>
diff --git a/src/wallet/test/wallet_transaction_tests.cpp b/src/wallet/test/wallet_transaction_tests.cpp
index e49439065a..38be52f41f 100644
--- a/src/wallet/test/wallet_transaction_tests.cpp
+++ b/src/wallet/test/wallet_transaction_tests.cpp
@@ -4,6 +4,7 @@
 
 #include <wallet/transaction.h>
 
+#include <test/util/common.h>
 #include <wallet/test/wallet_test_fixture.h>
 
 #include <boost/test/unit_test.hpp>
diff --git a/src/wallet/test/walletload_tests.cpp b/src/wallet/test/walletload_tests.cpp
index bc994ba606..1463ee98b3 100644
--- a/src/wallet/test/walletload_tests.cpp
+++ b/src/wallet/test/walletload_tests.cpp
@@ -4,6 +4,7 @@
 
 #include <wallet/test/util.h>
 #include <wallet/wallet.h>
+#include <test/util/common.h>
 #include <test/util/logging.h>
 #include <test/util/setup_common.h>
 
```

</details>

Code after:
    {
        // Check three lines terminated by \n and \r\n, trimming whitespace
        const std::vector<std::byte> input{StringToBuffer("once upon a time\n there was a dog \r\nwho liked food\n")};
        LineReader reader(input, /*max_line_length=*/128);
        std::optional<std::string> line1{reader.ReadLine()};
        BOOST_CHECK_EQUAL(reader.Remaining(), 34);
        std::optional<std::string> line2{reader.ReadLine()};
        BOOST_CHECK_EQUAL(reader.Remaining(), 15);
        std::optional<std::string> line3{reader.ReadLine()};
        std::optional<std::string> line4{reader.ReadLine()};
        BOOST_CHECK(line1);
        BOOST_CHECK(line2);
        BOOST_CHECK(line3);
        BOOST_CHECK(!line4);
        BOOST_CHECK_EQUAL(line1.value(), "once upon a time");
        BOOST_CHECK_EQUAL(line2.value(), "there was a dog");
        BOOST_CHECK_EQUAL(line3.value(), "who liked food");
    }
    {
        // Do not exceed max_line_length + 1 while searching for \n
        // Test with 22-character line + \n + 23-character line + \n
        const std::vector<std::byte> input{StringToBuffer("once upon a time there\nwas a dog who liked tea\n")};

        LineReader reader1(input, /*max_line_length=*/22);
        // First line is exactly the length of max_line_length
        BOOST_CHECK_EQUAL(reader1.ReadLine(), "once upon a time there");
        // Second line is +1 character too long
        BOOST_CHECK_EXCEPTION(reader1.ReadLine(), std::runtime_error, HasReason{"max_line_length exceeded by LineReader"});

        // Increase max_line_length by 1
        LineReader reader2(input, /*max_line_length=*/23);
        // Both lines fit within limit
        BOOST_CHECK_EQUAL(reader2.ReadLine(), "once upon a time there");
        BOOST_CHECK_EQUAL(reader2.ReadLine(), "was a dog who liked tea");
        // End of buffer reached
        BOOST_CHECK(!reader2.ReadLine());
    }
    {
        // Empty lines are empty
        const std::vector<std::byte> input{StringToBuffer("\n")};
        LineReader reader(input, /*max_line_length=*/1024);
        BOOST_CHECK_EQUAL(reader.ReadLine(), "");
        BOOST_CHECK(!reader.ReadLine());
    }
    {
        // Empty buffers are null
        const std::vector<std::byte> input{StringToBuffer("")};
        LineReader reader(input, /*max_line_length=*/1024);
        BOOST_CHECK(!reader.ReadLine());
    }
    {