Merge bitcoin/bitcoin#36091: test: Add debug output to common tested types
What changed, and why it matters
This commit only changes Bitcoin Core's test code. It adds pretty-printing helpers for common data types and updates test assertions to use macros that print more helpful failure messages. There is no change to the actual Bitcoin node software that users run, so it cannot affect live wallets, transactions, or network behavior.
No security action required. Treat as normal test-quality improvement.
Security signals we found
No production code changes
Test-only refactoring
No cryptographic, consensus, network, or wallet logic changes
No bug fixes or vulnerability patches present in diff
Evidence from the diff
The merge adds operator<< overloads in src/test/util/common.{h,cpp} for test-only debug output of types such as CScript, CService, CAddress, CExtKey, CExtPubKey, FeeFrac, CTxDestination variants, CPubKey, XOnlyPubKey, KeyOriginInfo, and AddressPosition. It also converts BOOST_CHECK/BOOST_CHECK_EQUAL/BOOST_CHECK_* comparisons across 16 test files to use BOOST_CHECK_EQUAL / BOOST_CHECK_EQUAL_COLLECTIONS / BOOST_CHECK_GT / etc., which leverage the new stream operators to emit values on assertion failure. No production code is modified.
Changed components
src/test/util/common.hsrc/test/util/common.cppsrc/test/*_tests.cppInspect captured patch +384 / −169
### src/test/addrman_tests.cpp
@@ -215,21 +215,21 @@ BOOST_AUTO_TEST_CASE(addrman_select)
BOOST_CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source));
BOOST_CHECK_EQUAL(addrman->Size(), 1U);
- BOOST_CHECK(addrman->Select(/*new_only=*/true).first == addr1);
- BOOST_CHECK(addrman->Select(/*new_only=*/false).first == addr1);
+ BOOST_CHECK_EQUAL(addrman->Select(/*new_only=*/true).first, addr1);
+ BOOST_CHECK_EQUAL(addrman->Select(/*new_only=*/false).first, addr1);
// Move address to the tried table
BOOST_CHECK(addrman->Good(CAddress(addr1, NODE_NONE)));
BOOST_CHECK_EQUAL(addrman->Size(), 1U);
BOOST_CHECK(!addrman->Select(/*new_only=*/true).first.IsValid());
- BOOST_CHECK(addrman->Select().first == addr1);
+ BOOST_CHECK_EQUAL(addrman->Select().first, addr1);
BOOST_CHECK_EQUAL(addrman->Size(), 1U);
// Add one address to the new table
CService addr2 = ResolveService("250.3.1.1", 8333);
BOOST_CHECK(addrman->Add({CAddress(addr2, NODE_NONE)}, addr2));
- BOOST_CHECK(addrman->Select(/*new_only=*/true).first == addr2);
+ BOOST_CHECK_EQUAL(addrman->Select(/*new_only=*/true).first, addr2);
// Add two more addresses to the new table
CService addr3 = ResolveService("250.3.2.2", 9999);
@@ -272,23 +272,23 @@ BOOST_AUTO_TEST_CASE(addrman_select_by_network)
CService addr1 = ResolveService("250.1.1.1", 8333);
BOOST_CHECK(addrman->Add({CAddress(addr1, NODE_NONE)}, source));
- BOOST_CHECK(addrman->Select(/*new_only=*/true, {NET_IPV4}).first == addr1);
- BOOST_CHECK(addrman->Select(/*new_only=*/false, {NET_IPV4}).first == addr1);
+ BOOST_CHECK_EQUAL(addrman->Select(/*new_only=*/true, {NET_IPV4}).first, addr1);
+ BOOST_CHECK_EQUAL(addrman->Select(/*new_only=*/false, {NET_IPV4}).first, addr1);
BOOST_CHECK(!addrman->Select(/*new_only=*/false, {NET_IPV6}).first.IsValid());
BOOST_CHECK(!addrman->Select(/*new_only=*/false, {NET_ONION}).first.IsValid());
BOOST_CHECK(!addrman->Select(/*new_only=*/false, {NET_I2P}).first.IsValid());
BOOST_CHECK(!addrman->Select(/*new_only=*/false, {NET_CJDNS}).first.IsValid());
BOOST_CHECK(!addrman->Select(/*new_only=*/true, {NET_CJDNS}).first.IsValid());
- BOOST_CHECK(addrman->Select(/*new_only=*/false).first == addr1);
+ BOOST_CHECK_EQUAL(addrman->Select(/*new_only=*/false).first, addr1);
// add I2P address to the new table
CAddress i2p_addr;
i2p_addr.SetSpecial("udhdrtrcetjm5sxzskjyr5ztpeszydbh4dpl3pl4utgqqw2v4jna.b32.i2p");
BOOST_CHECK(addrman->Add({i2p_addr}, source));
- BOOST_CHECK(addrman->Select(/*new_only=*/true, {NET_I2P}).first == i2p_addr);
- BOOST_CHECK(addrman->Select(/*new_only=*/false, {NET_I2P}).first == i2p_addr);
- BOOST_CHECK(addrman->Select(/*new_only=*/false, {NET_IPV4}).first == addr1);
+ BOOST_CHECK_EQUAL(addrman->Select(/*new_only=*/true, {NET_I2P}).first, i2p_addr);
+ BOOST_CHECK_EQUAL(addrman->Select(/*new_only=*/false, {NET_I2P}).first, i2p_addr);
+ BOOST_CHECK_EQUAL(addrman->Select(/*new_only=*/false, {NET_IPV4}).first, addr1);
std::unordered_set<Network> nets_with_entries = {NET_IPV4, NET_I2P};
BOOST_CHECK(addrman->Select(/*new_only=*/false, nets_with_entries).first.IsValid());
BOOST_CHECK(!addrman->Select(/*new_only=*/false, {NET_IPV6}).first.IsValid());
@@ -301,14 +301,14 @@ BOOST_AUTO_TEST_CASE(addrman_select_by_network)
BOOST_CHECK(addrman->Good(i2p_addr));
BOOST_CHECK(!addrman->Select(/*new_only=*/true, {NET_I2P}).first.IsValid());
- BOOST_CHECK(addrman->Select(/*new_only=*/false, {NET_I2P}).first == i2p_addr);
+ BOOST_CHECK_EQUAL(addrman->Select(/*new_only=*/false, {NET_I2P}).first, i2p_addr);
// add another I2P address to the new table
CAddress i2p_addr2;
i2p_addr2.SetSpecial("c4gfnttsuwqomiygupdqqqyy5y5emnk5c73hrfvatri67prd7vyq.b32.i2p");
BOOST_CHECK(addrman->Add({i2p_addr2}, source));
- BOOST_CHECK(addrman->Select(/*new_only=*/true, {NET_I2P}).first == i2p_addr2);
+ BOOST_CHECK_EQUAL(addrman->Select(/*new_only=*/true, {NET_I2P}).first, i2p_addr2);
// ensure that both new and tried table are selected from
bool new_selected{false};
@@ -405,7 +405,7 @@ BOOST_AUTO_TEST_CASE(addrman_select_special)
// since the only ipv4 address is on the new table, ensure that the new
// table gets selected even if new_only is false. if the table was being
// selected at random, this test will sporadically fail
- BOOST_CHECK(addrman->Select(/*new_only=*/false, {NET_IPV4}).first == addr1);
+ BOOST_CHECK_EQUAL(addrman->Select(/*new_only=*/false, {NET_IPV4}).first, addr1);
}
BOOST_AUTO_TEST_CASE(addrman_new_collisions)
@@ -875,7 +875,7 @@ BOOST_AUTO_TEST_CASE(addrman_serialization)
BOOST_CHECK(addr_pos1.multiplicity != 0);
BOOST_CHECK(addr_pos2.multiplicity != 0);
- BOOST_CHECK(addr_pos1 == addr_pos2);
+ BOOST_CHECK_EQUAL(addr_pos1, addr_pos2);
// deserializing asmaped peers.dat to non-asmaped addrman
stream << *addrman_asmap1;
@@ -895,7 +895,7 @@ BOOST_AUTO_TEST_CASE(addrman_serialization)
AddressPosition addr_pos4 = addrman_asmap1->FindAddressEntry(addr).value();
BOOST_CHECK(addr_pos4.multiplicity != 0);
BOOST_CHECK(addr_pos4.bucket != addr_pos3.bucket);
- BOOST_CHECK(addr_pos4 == addr_pos2);
+ BOOST_CHECK_EQUAL(addr_pos4, addr_pos2);
// used to map to different buckets, now maps to the same bucket.
addrman_asmap1 = std::make_unique<AddrMan>(netgroupman, DETERMINISTIC, ratio);
### src/test/bip32_tests.cpp
@@ -8,6 +8,7 @@
#include <key.h>
#include <key_io.h>
#include <streams.h>
+#include <test/util/common.h>
#include <test/util/setup_common.h>
#include <util/bip32.h>
#include <util/strencodings.h>
@@ -138,16 +139,16 @@ void RunTest(const TestVector& test)
CExtPubKey pubkey_deser;
ss >> key_deser;
ss >> pubkey_deser;
- BOOST_CHECK(key_deser == key);
- BOOST_CHECK(pubkey_deser == pubkey);
+ BOOST_CHECK_EQUAL(key_deser, key);
+ BOOST_CHECK_EQUAL(pubkey_deser, pubkey);
// Test private key
BOOST_CHECK(EncodeExtKey(key) == derive.prv);
- BOOST_CHECK(DecodeExtKey(derive.prv) == key); //ensure a base58 decoded key also matches
+ BOOST_CHECK_EQUAL(DecodeExtKey(derive.prv), key); //ensure a base58 decoded key also matches
// Test public key
BOOST_CHECK(EncodeExtPubKey(pubkey) == derive.pub);
- BOOST_CHECK(DecodeExtPubKey(derive.pub) == pubkey); //ensure a base58 decoded pubkey also matches
+ BOOST_CHECK_EQUAL(DecodeExtPubKey(derive.pub), pubkey); //ensure a base58 decoded pubkey also matches
// Derive new keys
CExtKey keyNew;
@@ -157,7 +158,7 @@ void RunTest(const TestVector& test)
// Compare with public derivation
CExtPubKey pubkeyNew2;
BOOST_CHECK(pubkey.Derive(pubkeyNew2, derive.nChild));
- BOOST_CHECK(pubkeyNew == pubkeyNew2);
+ BOOST_CHECK_EQUAL(pubkeyNew, pubkeyNew2);
}
key = keyNew;
pubkey = pubkeyNew;
@@ -232,7 +233,7 @@ BOOST_AUTO_TEST_CASE(bip32_deserialize_invalid)
DataStream ss{extra};
CExtKey key;
ss >> key;
- BOOST_CHECK(key == master);
+ BOOST_CHECK_EQUAL(key, master);
BOOST_CHECK_EQUAL(ss.size(), 1);
}
{
@@ -241,7 +242,7 @@ BOOST_AUTO_TEST_CASE(bip32_deserialize_invalid)
DataStream ss{extra};
CExtPubKey pubkey;
ss >> pubkey;
- BOOST_CHECK(pubkey == master_pub);
+ BOOST_CHECK_EQUAL(pubkey, master_pub);
BOOST_CHECK_EQUAL(ss.size(), 1);
}
@@ -307,13 +308,13 @@ BOOST_AUTO_TEST_CASE(bip32_derive_ext_key)
KeyOriginInfo expected_origin;
expected_origin.fingerprint = master.id_key_fingerprint();
expected_origin.path = path;
- BOOST_CHECK(derived->second == expected_origin);
+ BOOST_CHECK_EQUAL(derived->second, expected_origin);
const auto root{DeriveExtKey(master, {})};
BOOST_REQUIRE(root);
- BOOST_CHECK(root->first == master);
+ BOOST_CHECK_EQUAL(root->first, master);
expected_origin.path.clear();
- BOOST_CHECK(root->second == expected_origin);
+ BOOST_CHECK_EQUAL(root->second, expected_origin);
CExtKey max_depth{master};
for (auto i{0}; i++ < 255;) {
### src/test/bip352_tests.cpp
@@ -14,6 +14,7 @@
#include <script/solver.h>
#include <test/data/bip352_send_and_receive_vectors.json.h>
+#include <test/util/common.h>
#include <test/util/setup_common.h>
#include <boost/test/unit_test.hpp>
@@ -274,7 +275,7 @@ BOOST_AUTO_TEST_CASE(bip352_scan_skips_invalid_taproot_outputs)
const auto found_outputs = receiver.Scan(*prevouts_summary, output_pub_keys);
BOOST_REQUIRE(found_outputs.has_value());
BOOST_REQUIRE_EQUAL(found_outputs->size(), 1);
- BOOST_CHECK(found_outputs->front().output == expected_output);
+ BOOST_CHECK_EQUAL(found_outputs->front().output, expected_output);
}
BOOST_AUTO_TEST_CASE(bip352_p2pkh_pubkey_extraction_with_checksig_in_scriptsig)
@@ -309,7 +310,7 @@ BOOST_AUTO_TEST_CASE(bip352_p2pkh_pubkey_extraction_with_checksig_in_scriptsig)
const auto extracted_pubkey = GetPubKeyFromInput(txin, spk);
BOOST_REQUIRE(extracted_pubkey.has_value());
- BOOST_CHECK(std::get<CPubKey>(*extracted_pubkey) == pubkey);
+ BOOST_CHECK_EQUAL(std::get<CPubKey>(*extracted_pubkey), pubkey);
}
BOOST_AUTO_TEST_CASE(bip352_label_serialize_roundtrip)
### src/test/descriptor_tests.cpp
@@ -5,6 +5,7 @@
#include <pubkey.h>
#include <script/descriptor.h>
#include <script/sign.h>
+#include <test/util/common.h>
#include <test/util/setup_common.h>
#include <util/check.h>
#include <util/strencodings.h>
@@ -330,10 +331,12 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int
// Try to expand again using cached data, and compare.
BOOST_CHECK(parse_pub->ExpandFromCache(i, desc_cache, spks_cached, script_provider_cached));
- BOOST_CHECK(spks == spks_cached);
+ BOOST_CHECK_EQUAL_COLLECTIONS(spks.begin(), spks.end(), spks_cached.begin(), spks_cached.end());
BOOST_CHECK(GetKeyData(script_provider, flags) == GetKeyData(script_provider_cached, flags));
BOOST_CHECK(script_provider.scripts == script_provider_cached.scripts);
- BOOST_CHECK(GetKeyOriginData(script_provider, flags) == GetKeyOriginData(script_provider_cached, flags));
+ const auto origins{GetKeyOriginData(script_provider, flags)};
+ const auto origins_cached{GetKeyOriginData(script_provider_cached, flags)};
+ BOOST_CHECK_EQUAL_COLLECTIONS(origins.begin(), origins.end(), origins_cached.begin(), origins_cached.end());
// Check whether keys are in the cache
const auto& der_xpub_cache = desc_cache.GetCachedDerivedExtPubKeys();
@@ -437,10 +440,12 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int
// Try again but use the cache from expanding i. That cache won't have the pubkeys for i + 1, but will have the parent xpub for derivation.
BOOST_CHECK(parse_pub->ExpandFromCache(i + 1, desc_cache, spk1_from_cache, script_provider_cached1));
- BOOST_CHECK(spks1 == spk1_from_cache);
+ BOOST_CHECK_EQUAL_COLLECTIONS(spks1.begin(), spks1.end(), spk1_from_cache.begin(), spk1_from_cache.end());
BOOST_CHECK(GetKeyData(script_provider1, flags) == GetKeyData(script_provider_cached1, flags));
BOOST_CHECK(script_provider1.scripts == script_provider_cached1.scripts);
- BOOST_CHECK(GetKeyOriginData(script_provider1, flags) == GetKeyOriginData(script_provider_cached1, flags));
+ const auto origins1{GetKeyOriginData(script_provider1, flags)};
+ const auto origins_cached1{GetKeyOriginData(script_provider_cached1, flags)};
+ BOOST_CHECK_EQUAL_COLLECTIONS(origins1.begin(), origins1.end(), origins_cached1.begin(), origins_cached1.end());
}
// For each of the produced scripts, verify solvability, and when possible, try to sign a transaction spending it.
@@ -474,9 +479,11 @@ void DoCheck(std::string prv, std::string pub, const std::string& norm_pub, int
FlatSigningProvider provider_inferred;
BOOST_CHECK(inferred->Expand(0, provider_inferred, spks_inferred, provider_inferred));
BOOST_CHECK_EQUAL(spks_inferred.size(), 1U);
- BOOST_CHECK(spks_inferred[0] == spks[n]);
+ BOOST_CHECK_EQUAL(spks_inferred[0], spks[n]);
BOOST_CHECK_EQUAL(InferDescriptor(spks_inferred[0], provider_inferred)->IsSolvable(), !(flags & UNSOLVABLE));
- BOOST_CHECK(GetKeyOriginData(provider_inferred, flags) == GetKeyOriginData(script_provider, flags));
+ const auto origins_inferred{GetKeyOriginData(provider_inferred, flags)};
+ const auto origins_script{GetKeyOriginData(script_provider, flags)};
+ BOOST_CHECK_EQUAL_COLLECTIONS(origins_inferred.begin(), origins_inferred.end(), origins_script.begin(), origins_script.end());
}
// Test whether the observed key path is present in the 'paths' variable (which contains expected, unobserved paths),
### src/test/feefrac_tests.cpp
@@ -2,6 +2,7 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include <test/util/common.h>
#include <util/feefrac.h>
#include <random.h>
@@ -55,30 +56,30 @@ BOOST_AUTO_TEST_CASE(feefrac_operators)
BOOST_CHECK_EQUAL(neg.EvaluateFeeUp(100000001), -1001000010);
BOOST_CHECK_EQUAL(neg.EvaluateFeeUp(0x7fffffff), -21496311306);
- BOOST_CHECK(empty == FeeFrac{}); // same as no-args
+ BOOST_CHECK_EQUAL(empty, FeeFrac{}); // same as no-args
- BOOST_CHECK(p1 == p1);
- BOOST_CHECK(p1 + p2 == sum);
- BOOST_CHECK(p1 - p2 == diff);
+ BOOST_CHECK_EQUAL(p1, p1);
+ BOOST_CHECK_EQUAL(p1 + p2, sum);
+ BOOST_CHECK_EQUAL(p1 - p2, diff);
FeeFrac p3{2000, 200};
- BOOST_CHECK(p1 != p3); // feefracs only equal if both fee and size are same
- BOOST_CHECK(p2 != p3);
+ BOOST_CHECK_NE(p1, p3); // feefracs only equal if both fee and size are same
+ BOOST_CHECK_NE(p2, p3);
FeeFrac p4{3000, 300};
- BOOST_CHECK(p1 == p4-p3);
- BOOST_CHECK(p1 + p3 == p4);
+ BOOST_CHECK_EQUAL(p1, p4-p3);
+ BOOST_CHECK_EQUAL(p1 + p3, p4);
// Fee-rate comparison
- BOOST_CHECK(ByRatioNegSize{p1} > ByRatioNegSize{p2});
- BOOST_CHECK(ByRatioNegSize{p1} >= ByRatioNegSize{p2});
- BOOST_CHECK(ByRatioNegSize{p1} >= ByRatioNegSize{p4-p3});
+ BOOST_CHECK_GT(ByRatioNegSize{p1}, ByRatioNegSize{p2});
+ BOOST_CHECK_GE(ByRatioNegSize{p1}, ByRatioNegSize{p2});
+ BOOST_CHECK_GE(ByRatioNegSize{p1}, ByRatioNegSize{p4-p3});
BOOST_CHECK(!(ByRatio{p1} > ByRatio{p3})); // not strictly better
BOOST_CHECK(ByRatio{p1} > ByRatio{p2}); // strictly greater feerate
- BOOST_CHECK(ByRatioNegSize{p2} < ByRatioNegSize{p1});
- BOOST_CHECK(ByRatioNegSize{p2} <= ByRatioNegSize{p1});
- BOOST_CHECK(ByRatioNegSize{p1} <= ByRatioNegSize{p4-p3});
+ BOOST_CHECK_LT(ByRatioNegSize{p2}, ByRatioNegSize{p1});
+ BOOST_CHECK_LE(ByRatioNegSize{p2}, ByRatioNegSize{p1});
+ BOOST_CHECK_LE(ByRatioNegSize{p1}, ByRatioNegSize{p4-p3});
BOOST_CHECK(!(ByRatio{p3} < ByRatio{p1})); // not strictly worse
BOOST_CHECK(ByRatio{p2} < ByRatio{p1}); // strictly lower feerate
@@ -89,21 +90,21 @@ BOOST_AUTO_TEST_CASE(feefrac_operators)
BOOST_CHECK(!(ByRatio{empty} < ByRatio{empty}));
// empty is always bigger than everything else
- BOOST_CHECK(ByRatioNegSize{empty} > ByRatioNegSize{p1});
- BOOST_CHECK(ByRatioNegSize{empty} > ByRatioNegSize{p2});
- BOOST_CHECK(ByRatioNegSize{empty} > ByRatioNegSize{p3});
- BOOST_CHECK(ByRatioNegSize{empty} >= ByRatioNegSize{p1});
- BOOST_CHECK(ByRatioNegSize{empty} >= ByRatioNegSize{p2});
- BOOST_CHECK(ByRatioNegSize{empty} >= ByRatioNegSize{p3});
+ BOOST_CHECK_GT(ByRatioNegSize{empty}, ByRatioNegSize{p1});
+ BOOST_CHECK_GT(ByRatioNegSize{empty}, ByRatioNegSize{p2});
+ BOOST_CHECK_GT(ByRatioNegSize{empty}, ByRatioNegSize{p3});
+ BOOST_CHECK_GE(ByRatioNegSize{empty}, ByRatioNegSize{p1});
+ BOOST_CHECK_GE(ByRatioNegSize{empty}, ByRatioNegSize{p2});
+ BOOST_CHECK_GE(ByRatioNegSize{empty}, ByRatioNegSize{p3});
// check "max" values for comparison
FeeFrac oversized_1{4611686000000, 4000000};
FeeFrac oversized_2{184467440000000, 100000};
- BOOST_CHECK(ByRatioNegSize{oversized_1} < ByRatioNegSize{oversized_2});
- BOOST_CHECK(ByRatioNegSize{oversized_1} <= ByRatioNegSize{oversized_2});
+ BOOST_CHECK_LT(ByRatioNegSize{oversized_1}, ByRatioNegSize{oversized_2});
+ BOOST_CHECK_LE(ByRatioNegSize{oversized_1}, ByRatioNegSize{oversized_2});
BOOST_CHECK(ByRatio{oversized_1} < ByRatio{oversized_2});
- BOOST_CHECK(ByRatioNegSize{oversized_1} != ByRatioNegSize{oversized_2});
+ BOOST_CHECK_NE(ByRatioNegSize{oversized_1}, ByRatioNegSize{oversized_2});
BOOST_CHECK_EQUAL(oversized_1.EvaluateFeeDown(0), 0);
BOOST_CHECK_EQUAL(oversized_1.EvaluateFeeDown(1), 1152921);
@@ -129,8 +130,8 @@ BOOST_AUTO_TEST_CASE(feefrac_operators)
FeeFrac max_fee{2100000000000000, INT32_MAX};
BOOST_CHECK(!(ByRatioNegSize{max_fee} < ByRatioNegSize{max_fee}));
BOOST_CHECK(!(ByRatioNegSize{max_fee} > ByRatioNegSize{max_fee}));
- BOOST_CHECK(ByRatioNegSize{max_fee} <= ByRatioNegSize{max_fee});
- BOOST_CHECK(ByRatioNegSize{max_fee} >= ByRatioNegSize{max_fee});
+ BOOST_CHECK_LE(ByRatioNegSize{max_fee}, ByRatioNegSize{max_fee});
+ BOOST_CHECK_GE(ByRatioNegSize{max_fee}, ByRatioNegSize{max_fee});
BOOST_CHECK_EQUAL(max_fee.EvaluateFeeDown(0), 0);
BOOST_CHECK_EQUAL(max_fee.EvaluateFeeDown(1), 977888);
@@ -146,7 +147,7 @@ BOOST_AUTO_TEST_CASE(feefrac_operators)
BOOST_CHECK_EQUAL(max_fee.EvaluateFeeUp(INT32_MAX), 2100000000000000);
FeeFrac max_fee2{1, 1};
- BOOST_CHECK(ByRatioNegSize{max_fee} >= ByRatioNegSize{max_fee2});
+ BOOST_CHECK_GE(ByRatioNegSize{max_fee}, ByRatioNegSize{max_fee2});
// Test for integer overflow issue (https://github.com/bitcoin/bitcoin/issues/32294)
BOOST_CHECK_EQUAL((FeeFrac{0x7ffffffdfffffffb, 0x7ffffffd}.EvaluateFeeDown(0x7fffffff)), 0x7fffffffffffffff);
### src/test/key_tests.cpp
@@ -80,10 +80,10 @@ BOOST_AUTO_TEST_CASE(key_test1)
BOOST_CHECK(!key2C.VerifyPubKey(pubkey2));
BOOST_CHECK(key2C.VerifyPubKey(pubkey2C));
- BOOST_CHECK(DecodeDestination(addr1) == CTxDestination(PKHash(pubkey1)));
- BOOST_CHECK(DecodeDestination(addr2) == CTxDestination(PKHash(pubkey2)));
- BOOST_CHECK(DecodeDestination(addr1C) == CTxDestination(PKHash(pubkey1C)));
- BOOST_CHECK(DecodeDestination(addr2C) == CTxDestination(PKHash(pubkey2C)));
+ BOOST_CHECK_EQUAL(DecodeDestination(addr1), CTxDestination(PKHash(pubkey1)));
+ BOOST_CHECK_EQUAL(DecodeDestination(addr2), CTxDestination(PKHash(pubkey2)));
+ BOOST_CHECK_EQUAL(DecodeDestination(addr1C), CTxDestination(PKHash(pubkey1C)));
+ BOOST_CHECK_EQUAL(DecodeDestination(addr2C), CTxDestination(PKHash(pubkey2C)));
for (int n=0; n<16; n++)
{
@@ -135,10 +135,10 @@ BOOST_AUTO_TEST_CASE(key_test1)
BOOST_CHECK(rkey1C.RecoverCompact(hashMsg, csign1C));
BOOST_CHECK(rkey2C.RecoverCompact(hashMsg, csign2C));
- BOOST_CHECK(rkey1 == pubkey1);
- BOOST_CHECK(rkey2 == pubkey2);
- BOOST_CHECK(rkey1C == pubkey1C);
- BOOST_CHECK(rkey2C == pubkey2C);
+ BOOST_CHECK_EQUAL(rkey1, pubkey1);
+ BOOST_CHECK_EQUAL(rkey2, pubkey2);
+ BOOST_CHECK_EQUAL(rkey1C, pubkey1C);
+ BOOST_CHECK_EQUAL(rkey2C, pubkey2C);
}
// test deterministic signing
@@ -237,7 +237,7 @@ static void CmpSerializationPubkey(const CPubKey& pubkey)
stream << pubkey;
CPubKey pubkey2;
stream >> pubkey2;
- BOOST_CHECK(pubkey == pubkey2);
+ BOOST_CHECK_EQUAL(pubkey, pubkey2);
}
BOOST_AUTO_TEST_CASE(pubkey_unserialize)
@@ -355,7 +355,7 @@ BOOST_AUTO_TEST_CASE(key_ellswift)
// to compare.
decoded_pubkey.Decompress();
}
- BOOST_CHECK(key.GetPubKey() == decoded_pubkey);
+ BOOST_CHECK_EQUAL(key.GetPubKey(), decoded_pubkey);
}
}
@@ -365,7 +365,7 @@ BOOST_AUTO_TEST_CASE(bip341_test_h)
HashWriter hw;
hw.write(G_uncompressed);
XOnlyPubKey H{hw.GetSHA256()};
- BOOST_CHECK(XOnlyPubKey::NUMS_H == H);
+ BOOST_CHECK_EQUAL(XOnlyPubKey::NUMS_H, H);
}
BOOST_AUTO_TEST_CASE(key_schnorr_tweak_smoke_test)
### src/test/mempool_fee_estimator_tests.cpp
@@ -8,6 +8,7 @@
#include <policy/policy.h>
#include <primitives/block.h>
#include <random.h>
+#include <test/util/common.h>
#include <test/util/setup_common.h>
#include <test/util/txmempool.h>
#include <txmempool.h>
@@ -119,8 +120,8 @@ BOOST_AUTO_TEST_CASE(mempool_fee_rate_estimator_cache)
BOOST_CHECK(!cache.IsStale());
const auto cached{cache.GetCachedEstimate(tip_hash)};
BOOST_REQUIRE(cached);
- BOOST_CHECK(cached->m_conservative == conservative);
- BOOST_CHECK(cached->m_economical == economical);
+ BOOST_CHECK_EQUAL(cached->m_conservative, conservative);
+ BOOST_CHECK_EQUAL(cached->m_economical, economical);
BOOST_CHECK(!cache.GetCachedEstimate(next_tip_hash));
clock += CACHE_LIFE + std::chrono::seconds{1};
@@ -249,14 +250,14 @@ BOOST_AUTO_TEST_CASE(MempoolFeeRateEstimator)
{
const auto result = mempool_estimator.EstimateFeeRate(/*conservative=*/true);
BOOST_REQUIRE(result.has_value());
- BOOST_CHECK(result->feerate == floor);
+ BOOST_CHECK_EQUAL(result->feerate, floor);
BOOST_CHECK(result->feerate_estimator == FeeRateEstimatorType::MEMPOOL_POLICY);
BOOST_CHECK_EQUAL(result->returned_target, MEMPOOL_FEE_ESTIMATOR_MAX_TARGET);
// The floor estimate is cached like any other; a second call returns the same value.
const auto cached_result = mempool_estimator.EstimateFeeRate(/*conservative=*/true);
BOOST_REQUIRE(cached_result.has_value());
- BOOST_CHECK(cached_result->feerate == floor);
+ BOOST_CHECK_EQUAL(cached_result->feerate, floor);
}
TestMemPoolEntryHelper entry;
const auto tx_vsize = entry.FromTx(MakeRandomTx()).GetTxSize();
@@ -278,7 +279,7 @@ BOOST_AUTO_TEST_CASE(MempoolFeeRateEstimator)
SetMockTime(GetTime<std::chrono::seconds>() + CACHE_LIFE + std::chrono::seconds{1});
const auto result = mempool_estimator.EstimateFeeRate(/*conservative=*/true);
BOOST_REQUIRE(result.has_value());
- BOOST_CHECK(result->feerate == floor);
+ BOOST_CHECK_EQUAL(result->feerate, floor);
}
// A mempool that fills 50% of a block but not 75% has a conservative (p50)
// estimate, while the economical (p75) estimate falls back to the floor.
@@ -295,8 +296,8 @@ BOOST_AUTO_TEST_CASE(MempoolFeeRateEstimator)
const auto economical = mempool_estimator.EstimateFeeRate(/*conservative=*/false);
BOOST_REQUIRE(conservative.has_value());
BOOST_REQUIRE(economical.has_value());
- BOOST_CHECK(conservative->feerate == FeeFrac(med_fee, tx_vsize));
- BOOST_CHECK(economical->feerate == floor);
+ BOOST_CHECK_EQUAL(conservative->feerate, FeeFrac(med_fee, tx_vsize));
+ BOOST_CHECK_EQUAL(economical->feerate, floor);
}
// Mempool transactions are enough to provide both feerate estimates.
{
@@ -314,8 +315,8 @@ BOOST_AUTO_TEST_CASE(MempoolFeeRateEstimator)
const auto result_economical = mempool_estimator.EstimateFeeRate(/*conservative=*/false);
BOOST_CHECK(result_conservative.has_value());
BOOST_CHECK(result_economical.has_value());
- BOOST_CHECK(result_economical->feerate == FeeFrac(low_fee, tx_vsize));
- BOOST_CHECK(result_conservative->feerate == FeeFrac(med_fee, tx_vsize));
+ BOOST_CHECK_EQUAL(result_economical->feerate, FeeFrac(low_fee, tx_vsize));
+ BOOST_CHECK_EQUAL(result_conservative->feerate, FeeFrac(med_fee, tx_vsize));
BOOST_CHECK(ByRatio{result_conservative->feerate} > ByRatio{result_economical->feerate});
BOOST_CHECK(result_conservative->feerate_estimator == FeeRateEstimatorType::MEMPOOL_POLICY);
BOOST_CHECK(result_economical->feerate_estimator == FeeRateEstimatorType::MEMPOOL_POLICY);
@@ -331,12 +332,12 @@ BOOST_AUTO_TEST_CASE(MempoolFeeRateEstimator)
TryAddToMempool(*m_node.mempool, entry.Fee(very_high_fee).FromTx(MakeRandomTx()));
}
}
- BOOST_CHECK(mempool_estimator.EstimateFeeRate(/*conservative=*/false).value().feerate == FeeFrac(low_fee, tx_vsize));
- BOOST_CHECK(mempool_estimator.EstimateFeeRate(/*conservative=*/true).value().feerate == FeeFrac(med_fee, tx_vsize));
+ BOOST_CHECK_EQUAL(mempool_estimator.EstimateFeeRate(/*conservative=*/false).value().feerate, FeeFrac(low_fee, tx_vsize));
+ BOOST_CHECK_EQUAL(mempool_estimator.EstimateFeeRate(/*conservative=*/true).value().feerate, FeeFrac(med_fee, tx_vsize));
// Expire the cache by advancing mock time past CACHE_LIFE so the next call recomputes.
SetMockTime(GetTime<std::chrono::seconds>() + CACHE_LIFE + std::chrono::seconds{1});
- BOOST_CHECK(mempool_estimator.EstimateFeeRate(/*conservative=*/false).value().feerate == FeeFrac(med_fee, tx_vsize));
- BOOST_CHECK(mempool_estimator.EstimateFeeRate(/*conservative=*/true).value().feerate == FeeFrac(high_fee, tx_vsize));
+ BOOST_CHECK_EQUAL(mempool_estimator.EstimateFeeRate(/*conservative=*/false).value().feerate, FeeFrac(med_fee, tx_vsize));
+ BOOST_CHECK_EQUAL(mempool_estimator.EstimateFeeRate(/*conservative=*/true).value().feerate, FeeFrac(high_fee, tx_vsize));
}
}
### src/test/miner_tests.cpp
@@ -227,11 +227,11 @@ void MinerTestingSetup::TestPackageSelection(const CScript& scriptPubKey, const
const auto combined_txs_size = parent_tx.GetTxSize() + high_fee_tx.GetTxSize();
FeeFrac package_feefrac{combined_txs_fee, combined_txs_size};
// The package should be added first.
- BOOST_CHECK(block_package_feerates[0] == package_feefrac);
+ BOOST_CHECK_EQUAL(block_package_feerates[0], package_feefrac);
// The medium_fee_tx should be added next.
FeeFrac medium_tx_feefrac{medium_fee_tx.GetFee(), medium_fee_tx.GetTxSize()};
- BOOST_CHECK(block_package_feerates[1] == medium_tx_feefrac);
+ BOOST_CHECK_EQUAL(block_package_feerates[1], medium_tx_feefrac);
// Test that a package below the block min tx fee doesn't get included
tx.vin[0].prevout.hash = hashHighFeeTx;
### src/test/net_tests.cpp
@@ -684,7 +684,7 @@ BOOST_AUTO_TEST_CASE(get_local_addr_for_peer_port)
auto chosen_local_addr = GetLocalAddrForPeer(peer_out);
BOOST_REQUIRE(chosen_local_addr);
const CService expected{peer_us_addr, bind_port};
- BOOST_CHECK(*chosen_local_addr == expected);
+ BOOST_CHECK_EQUAL(*chosen_local_addr, expected);
// Create a peer with a routable IPv4 address (inbound).
in_addr peer_in_in_addr;
@@ -705,7 +705,7 @@ BOOST_AUTO_TEST_CASE(get_local_addr_for_peer_port)
// Without the fix peer_us:8333 is chosen instead of the proper peer_us:peer_us.GetPort().
chosen_local_addr = GetLocalAddrForPeer(peer_in);
BOOST_REQUIRE(chosen_local_addr);
- BOOST_CHECK(*chosen_local_addr == peer_us);
+ BOOST_CHECK_EQUAL(*chosen_local_addr, peer_us);
m_node.args->ForceSetArg("-bind", "");
}
@@ -996,11 +996,11 @@ BOOST_AUTO_TEST_CASE(advertise_local_address)
// one local clearnet address - advertise to all but privacy peers
AddLocal(addr_ipv4);
- BOOST_CHECK(GetLocalAddress(*peer_ipv4) == addr_ipv4);
- BOOST_CHECK(GetLocalAddress(*peer_ipv6) == addr_ipv4);
- BOOST_CHECK(GetLocalAddress(*peer_ipv6_tunnel) == addr_ipv4);
- BOOST_CHECK(GetLocalAddress(*peer_teredo) == addr_ipv4);
- BOOST_CHECK(GetLocalAddress(*peer_cjdns) == addr_ipv4);
+ BOOST_CHECK_EQUAL(GetLocalAddress(*peer_ipv4), addr_ipv4);
+ BOOST_CHECK_EQUAL(GetLocalAddress(*peer_ipv6), addr_ipv4);
+ BOOST_CHECK_EQUAL(GetLocalAddress(*peer_ipv6_tunnel), addr_ipv4);
+ BOOST_CHECK_EQUAL(GetLocalAddress(*peer_teredo), addr_ipv4);
+ BOOST_CHECK_EQUAL(GetLocalAddress(*peer_cjdns), addr_ipv4);
BOOST_CHECK(!GetLocalAddress(*peer_onion).IsValid());
BOOST_CHECK(!GetLocalAddress(*peer_i2p).IsValid());
RemoveLocal(addr_ipv4);
@@ -1013,8 +1013,8 @@ BOOST_AUTO_TEST_CASE(advertise_local_address)
BOOST_CHECK(!GetLocalAddress(*peer_ipv6_tunnel).IsValid());
BOOST_CHECK(!GetLocalAddress(*peer_teredo).IsValid());
BOOST_CHECK(!GetLocalAddress(*peer_cjdns).IsValid());
- BOOST_CHECK(GetLocalAddress(*peer_onion) == addr_onion);
- BOOST_CHECK(GetLocalAddress(*peer_i2p) == addr_i2p);
+ BOOST_CHECK_EQUAL(GetLocalAddress(*peer_onion), addr_onion);
+ BOOST_CHECK_EQUAL(GetLocalAddress(*peer_i2p), addr_i2p);
RemoveLocal(addr_onion);
RemoveLocal(addr_i2p);
@@ -1026,13 +1026,13 @@ BOOST_AUTO_TEST_CASE(advertise_local_address)
AddLocal(addr_onion);
AddLocal(addr_i2p);
AddLocal(addr_cjdns);
- BOOST_CHECK(GetLocalAddress(*peer_ipv4) == addr_ipv4);
- BOOST_CHECK(GetLocalAddress(*peer_ipv6) == addr_ipv6);
- BOOST_CHECK(GetLocalAddress(*peer_ipv6_tunnel) == addr_ipv6);
- BOOST_CHECK(GetLocalAddress(*peer_teredo) == addr_ipv4);
- BOOST_CHECK(GetLocalAddress(*peer_onion) == addr_onion);
- BOOST_CHECK(GetLocalAddress(*peer_i2p) == addr_i2p);
- BOOST_CHECK(GetLocalAddress(*peer_cjdns) == addr_cjdns);
+ BOOST_CHECK_EQUAL(GetLocalAddress(*peer_ipv4), addr_ipv4);
+ BOOST_CHECK_EQUAL(GetLocalAddress(*peer_ipv6), addr_ipv6);
+ BOOST_CHECK_EQUAL(GetLocalAddress(*peer_ipv6_tunnel), addr_ipv6);
+ BOOST_CHECK_EQUAL(GetLocalAddress(*peer_teredo), addr_ipv4);
+ BOOST_CHECK_EQUAL(GetLocalAddress(*peer_onion), addr_onion);
+ BOOST_CHECK_EQUAL(GetLocalAddress(*peer_i2p), addr_i2p);
+ BOOST_CHECK_EQUAL(GetLocalAddress(*peer_cjdns), addr_cjdns);
RemoveLocal(addr_ipv4);
RemoveLocal(addr_ipv6);
RemoveLocal(addr_ipv6_tunnel);
### src/test/netbase_tests.cpp
@@ -583,7 +583,8 @@ BOOST_AUTO_TEST_CASE(caddress_unserialize_v1)
std::vector<CAddress> addresses_unserialized;
SpanReader{ParseHex(stream_addrv1_hex)} >> CAddress::V1_NETWORK(addresses_unserialized);
- BOOST_CHECK(fixture_addresses == addresses_unserialized);
+ BOOST_CHECK_EQUAL_COLLECTIONS(fixture_addresses.begin(), fixture_addresses.end(),
+ addresses_unserialized.begin(), addresses_unserialized.end());
}
BOOST_AUTO_TEST_CASE(caddress_serialize_v2)
@@ -599,7 +600,8 @@ BOOST_AUTO_TEST_CASE(caddress_unserialize_v2)
std::vector<CAddress> addresses_unserialized;
SpanReader{ParseHex(stream_addrv2_hex)} >> CAddress::V2_NETWORK(addresses_unserialized);
- BOOST_CHECK(fixture_addresses == addresses_unserialized);
+ BOOST_CHECK_EQUAL_COLLECTIONS(fixture_addresses.begin(), fixture_addresses.end(),
+ addresses_unserialized.begin(), addresses_unserialized.end());
}
BOOST_AUTO_TEST_CASE(isbadport)
### src/test/psbt_tests.cpp
@@ -9,6 +9,7 @@
#include <script/script.h>
#include <script/signingprovider.h>
#include <script/solver.h>
+#include <test/util/common.h>
#include <test/util/setup_common.h>
#include <util/strencodings.h>
#include <util/string.h>
@@ -278,7 +279,7 @@ BOOST_AUTO_TEST_CASE(update_psbt_output_redeem_script)
for (bool has_input : {false, true}) {
PSBTOutputTest test{"sh(wpkh(<KEY>))"};
auto out{test.UpdateOutput(has_input)};
- BOOST_CHECK(out.redeem_script == GetScriptForDestination(WitnessV0KeyHash{test.pubkey}));
+ BOOST_CHECK_EQUAL(out.redeem_script, GetScriptForDestination(WitnessV0KeyHash{test.pubkey}));
BOOST_CHECK(out.hd_keypaths.contains(test.pubkey));
}
}
@@ -288,7 +289,7 @@ BOOST_AUTO_TEST_CASE(update_psbt_output_witness_script)
for (bool has_input : {false, true}) {
PSBTOutputTest test{"wsh(pk(<KEY>))"};
auto out{test.UpdateOutput(has_input)};
- BOOST_CHECK(out.witness_script == GetScriptForRawPubKey(test.pubkey));
+ BOOST_CHECK_EQUAL(out.witness_script, GetScriptForRawPubKey(test.pubkey));
BOOST_CHECK(out.hd_keypaths.contains(test.pubkey));
}
}
@@ -298,7 +299,7 @@ BOOST_AUTO_TEST_CASE(update_psbt_output_miniscript_timelock)
for (bool has_input : {false, true}) {
PSBTOutputTest test{"wsh(and_v(v:pk(<KEY>),older(144)))"};
auto out{test.UpdateOutput(has_input)};
- BOOST_CHECK(GetScriptForDestination(WitnessV0ScriptHash{out.witness_script}) == test.script_pubkey);
+ BOOST_CHECK_EQUAL(GetScriptForDestination(WitnessV0ScriptHash{out.witness_script}), test.script_pubkey);
BOOST_CHECK(out.hd_keypaths.contains(test.pubkey));
}
}
### src/test/rbf_tests.cpp
@@ -8,6 +8,7 @@
#include <txmempool.h>
#include <util/time.h>
+#include <test/util/common.h>
#include <test/util/setup_common.h>
#include <boost/test/unit_test.hpp>
@@ -363,9 +364,11 @@ BOOST_FIXTURE_TEST_CASE(calc_feerate_diagram_rbf, TestChain100Setup)
const auto replace_one{changeset->CalculateChunksForRBF()};
BOOST_CHECK(replace_one.has_value());
std::vector<FeeFrac> expected_old_chunks{{low_fee, low_size}};
- BOOST_CHECK(replace_one->first == expected_old_chunks);
+ BOOST_CHECK_EQUAL_COLLECTIONS(replace_one->first.begin(), replace_one->first.end(),
+ expected_old_chunks.begin(), expected_old_chunks.end());
std::vector<FeeFrac> expected_new_chunks{{0, entry_replacement.GetAdjustedWeight()}};
- BOOST_CHECK(replace_one->second == expected_new_chunks);
+ BOOST_CHECK_EQUAL_COLLECTIONS(replace_one->second.begin(), replace_one->second.end(),
+ expected_new_chunks.begin(), expected_new_chunks.end());
}
// Non-zero replacement fee/size
@@ -376,9 +379,11 @@ BOOST_FIXTURE_TEST_CASE(calc_feerate_diagram_rbf, TestChain100Setup)
const auto replace_one_fee{changeset->CalculateChunksForRBF()};
BOOST_CHECK(replace_one_fee.has_value());
std::vector<FeeFrac> expected_old_diagram{{low_fee, low_size}};
- BOOST_CHECK(replace_one_fee->first == expected_old_diagram);
+ BOOST_CHECK_EQUAL_COLLECTIONS(replace_one_fee->first.begin(), replace_one_fee->first.end(),
+ expected_old_diagram.begin(), expected_old_diagram.end());
std::vector<FeeFrac> expected_new_diagram{{high_fee, entry_replacement.GetAdjustedWeight()}};
- BOOST_CHECK(replace_one_fee->second == expected_new_diagram);
+ BOOST_CHECK_EQUAL_COLLECTIONS(replace_one_fee->second.begin(), replace_one_fee->second.end(),
+ expected_new_diagram.begin(), expected_new_diagram.end());
}
// Add a second transaction to the cluster that will make a single chunk, to be evicted in the RBF
@@ -395,9 +400,11 @@ BOOST_FIXTURE_TEST_CASE(calc_feerate_diagram_rbf, TestChain100Setup)
const auto replace_single_chunk{changeset->CalculateChunksForRBF()};
BOOST_CHECK(replace_single_chunk.has_value());
std::vector<FeeFrac> expected_old_chunks{{low_fee + high_fee, low_size + high_size}};
- BOOST_CHECK(replace_single_chunk->first == expected_old_chunks);
+ BOOST_CHECK_EQUAL_COLLECTIONS(replace_single_chunk->first.begin(), replace_single_chunk->first.end(),
+ expected_old_chunks.begin(), expected_old_chunks.end());
std::vector<FeeFrac> expected_new_chunks{{high_fee, entry_replacement.GetAdjustedWeight()}};
- BOOST_CHECK(replace_single_chunk->second == expected_new_chunks);
+ BOOST_CHECK_EQUAL_COLLECTIONS(replace_single_chunk->second.begin(), replace_single_chunk->second.end(),
+ expected_new_chunks.begin(), expected_new_chunks.end());
}
// Conflict with the 2nd tx, resulting in new diagram with three entries
@@ -408,9 +415,11 @@ BOOST_FIXTURE_TEST_CASE(calc_feerate_diagram_rbf, TestChain100Setup)
const auto replace_cpfp_child{changeset->CalculateChunksForRBF()};
BOOST_CHECK(replace_cpfp_child.has_value());
std::vector<FeeFrac> expected_old_chunks{{low_fee + high_fee, low_size + high_size}};
- BOOST_CHECK(replace_cpfp_child->first == expected_old_chunks);
+ BOOST_CHECK_EQUAL_COLLECTIONS(replace_cpfp_child->first.begin(), replace_cpfp_child->first.end(),
+ expected_old_chunks.begin(), expected_old_chunks.end());
std::vector<FeeFrac> expected_new_chunks{{high_fee, entry_replacement.GetAdjustedWeight()}, {low_fee, low_size}};
- BOOST_CHECK(replace_cpfp_child->second == expected_new_chunks);
+ BOOST_CHECK_EQUAL_COLLECTIONS(replace_cpfp_child->second.begin(), replace_cpfp_child->second.end(),
+ expected_new_chunks.begin(), expected_new_chunks.end());
}
// Make a size 2 cluster that is itself two chunks; evict both txns
@@ -432,9 +441,11 @@ BOOST_FIXTURE_TEST_CASE(calc_feerate_diagram_rbf, TestChain100Setup)
const auto replace_two_chunks_single_cluster{changeset->CalculateChunksForRBF()};
BOOST_CHECK(replace_two_chunks_single_cluster.has_value());
std::vector<FeeFrac> expected_old_chunks{{high_fee, high_size_2}, {low_fee, low_size_2}};
- BOOST_CHECK(replace_two_chunks_single_cluster->first == expected_old_chunks);
+ BOOST_CHECK_EQUAL_COLLECTIONS(replace_two_chunks_single_cluster->first.begin(), replace_two_chunks_single_cluster->first.end(),
+ expected_old_chunks.begin(), expected_old_chunks.end());
std::vector<FeeFrac> expected_new_chunks{{high_fee, low_size_2}};
- BOOST_CHECK(replace_two_chunks_single_cluster->second == expected_new_chunks);
+ BOOST_CHECK_EQUAL_COLLECTIONS(replace_two_chunks_single_cluster->second.begin(), replace_two_chunks_single_cluster->second.end(),
+ expected_new_chunks.begin(), expected_new_chunks.end());
}
// You can have more than two direct conflicts
### src/test/script_standard_tests.cpp
@@ -235,20 +235,20 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestination)
s.clear();
s << ToByteVector(pubkey) << OP_CHECKSIG;
BOOST_CHECK(!ExtractDestination(s, address));
- BOOST_CHECK(std::get<PubKeyDestination>(address) == PubKeyDestination(pubkey));
+ BOOST_CHECK_EQUAL(std::get<PubKeyDestination>(address), PubKeyDestination(pubkey));
// TxoutType::PUBKEYHASH
s.clear();
s << OP_DUP << OP_HASH160 << ToByteVector(pubkey.GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
BOOST_CHECK(ExtractDestination(s, address));
- BOOST_CHECK(std::get<PKHash>(address) == PKHash(pubkey));
+ BOOST_CHECK_EQUAL(std::get<PKHash>(address), PKHash(pubkey));
// TxoutType::SCRIPTHASH
CScript redeemScript(s); // initialize with leftover P2PKH script
s.clear();
s << OP_HASH160 << ToByteVector(CScriptID(redeemScript)) << OP_EQUAL;
BOOST_CHECK(ExtractDestination(s, address));
- BOOST_CHECK(std::get<ScriptHash>(address) == ScriptHash(redeemScript));
+ BOOST_CHECK_EQUAL(std::get<ScriptHash>(address), ScriptHash(redeemScript));
// TxoutType::MULTISIG
s.clear();
@@ -266,42 +266,42 @@ BOOST_AUTO_TEST_CASE(script_standard_ExtractDestination)
BOOST_CHECK(ExtractDestination(s, address));
WitnessV0KeyHash keyhash;
CHash160().Write(pubkey).Finalize(keyhash);
- BOOST_CHECK(std::get<WitnessV0KeyHash>(address) == keyhash);
+ BOOST_CHECK_EQUAL(std::get<WitnessV0KeyHash>(address), keyhash);
// TxoutType::WITNESS_V0_SCRIPTHASH
s.clear();
WitnessV0ScriptHash scripthash;
CSHA256().Write(redeemScript.data(), redeemScript.size()).Finalize(scripthash.begin());
s << OP_0 << ToByteVector(scripthash);
BOOST_CHECK(ExtractDestination(s, address));
- BOOST_CHECK(std::get<WitnessV0ScriptHash>(address) == scripthash);
+ BOOST_CHECK_EQUAL(std::get<WitnessV0ScriptHash>(address), scripthash);
// TxoutType::WITNESS_V1_TAPROOT
s.clear();
auto xpk = XOnlyPubKey(pubkey);
s << OP_1 << ToByteVector(xpk);
BOOST_CHECK(ExtractDestination(s, address));
- BOOST_CHECK(std::get<WitnessV1Taproot>(address) == WitnessV1Taproot(xpk));
+ BOOST_CHECK_EQUAL(std::get<WitnessV1Taproot>(address), WitnessV1Taproot(xpk));
// TxoutType::ANCHOR
s.clear();
s << OP_1 << ANCHOR_BYTES;
BOOST_CHECK(ExtractDestination(s, address));
- BOOST_CHECK(std::get<PayToAnchor>(address) == PayToAnchor());
+ BOOST_CHECK_EQUAL(std::get<PayToAnchor>(address), PayToAnchor());
// TxoutType::WITNESS_UNKNOWN with unknown version
// -> segwit version 1 with an undefined program size (33 bytes in this test case)
s.clear();
s << OP_1 << ToByteVector(pubkey);
BOOST_CHECK(ExtractDestination(s, address));
WitnessUnknown unk_v1{1, ToByteVector(pubkey)};
- BOOST_CHECK(std::get<WitnessUnknown>(address) == unk_v1);
+ BOOST_CHECK_EQUAL(std::get<WitnessUnknown>(address), unk_v1);
s.clear();
// -> segwit versions 2+ are not specified yet
s << OP_2 << ToByteVector(xpk);
BOOST_CHECK(ExtractDestination(s, address));
WitnessUnknown unk_v2{2, ToByteVector(xpk)};
- BOOST_CHECK(std::get<WitnessUnknown>(address) == unk_v2);
+ BOOST_CHECK_EQUAL(std::get<WitnessUnknown>(address), unk_v2);
}
BOOST_AUTO_TEST_CASE(script_standard_GetScriptFor_)
@@ -319,25 +319,25 @@ BOOST_AUTO_TEST_CASE(script_standard_GetScriptFor_)
expected.clear();
expected << OP_DUP << OP_HASH160 << ToByteVector(pubkeys[0].GetID()) << OP_EQUALVERIFY << OP_CHECKSIG;
result = GetScriptForDestination(PKHash(pubkeys[0]));
- BOOST_CHECK(result == expected);
+ BOOST_CHECK_EQUAL(result, expected);
// CScriptID
CScript redeemScript(result);
expected.clear();
expected << OP_HASH160 << ToByteVector(CScriptID(redeemScript)) << OP_EQUAL;
result = GetScriptForDestination(ScriptHash(redeemScript));
- BOOST_CHECK(result == expected);
+ BOOST_CHECK_EQUAL(result, expected);
// CNoDestination
expected.clear();
result = GetScriptForDestination(CNoDestination());
- BOOST_CHECK(result == expected);
+ BOOST_CHECK_EQUAL(result, expected);
// GetScriptForRawPubKey
expected.clear();
expected << ToByteVector(pubkeys[0]) << OP_CHECKSIG;
result = GetScriptForRawPubKey(pubkeys[0]);
- BOOST_CHECK(result == expected);
+ BOOST_CHECK_EQUAL(result, expected);
// GetScriptForMultisig
expected.clear();
@@ -347,15 +347,15 @@ BOOST_AUTO_TEST_CASE(script_standard_GetScriptFor_)
ToByteVector(pubkeys[2]) <<
OP_3 << OP_CHECKMULTISIG;
result = GetScriptForMultisig(2, std::vector<CPubKey>(pubkeys, pubkeys + 3));
- BOOST_CHECK(result == expected);
+ BOOST_CHECK_EQUAL(result, expected);
// WitnessV0KeyHash
expected.clear();
expected << OP_0 << ToByteVector(pubkeys[0].GetID());
result = GetScriptForDestination(WitnessV0KeyHash(Hash160(ToByteVector(pubkeys[0]))));
- BOOST_CHECK(result == expected);
+ BOOST_CHECK_EQUAL(result, expected);
result = GetScriptForDestination(WitnessV0KeyHash(pubkeys[0].GetID()));
- BOOST_CHECK(result == expected);
+ BOOST_CHECK_EQUAL(result, expected);
// WitnessV0ScriptHash (multisig)
CScript witnessScript;
@@ -368,20 +368,20 @@ BOOST_AUTO_TEST_CASE(script_standard_GetScriptFor_)
expected.clear();
expected << OP_0 << ToByteVector(scriptHash);
result = GetScriptForDestination(WitnessV0ScriptHash(witnessScript));
- BOOST_CHECK(result == expected);
+ BOOST_CHECK_EQUAL(result, expected);
// WitnessV1Taproot
auto xpk = XOnlyPubKey(pubkeys[0]);
expected.clear();
expected << OP_1 << ToByteVector(xpk);
result = GetScriptForDestination(WitnessV1Taproot(xpk));
- BOOST_CHECK(result == expected);
+ BOOST_CHECK_EQUAL(result, expected);
// PayToAnchor
expected.clear();
expected << OP_1 << ANCHOR_BYTES;
result = GetScriptForDestination(PayToAnchor());
- BOOST_CHECK(result == expected);
+ BOOST_CHECK_EQUAL(result, expected);
}
BOOST_AUTO_TEST_CASE(script_standard_taproot_builder)
### src/test/script_tests.cpp
@@ -1298,9 +1298,9 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
BOOST_CHECK(SignSignature(keystore, CTransaction(txFrom), txTo, 0, SIGHASH_ALL, dummy)); // changes scriptSig
scriptSig = DataFromTransaction(txTo, 0, txFrom.vout[0]);
combined = CombineSignatures(txFrom.vout[0], txTo, scriptSig, empty);
- BOOST_CHECK(combined.scriptSig == scriptSig.scriptSig);
+ BOOST_CHECK_EQUAL(combined.scriptSig, scriptSig.scriptSig);
combined = CombineSignatures(txFrom.vout[0], txTo, empty, scriptSig);
- BOOST_CHECK(combined.scriptSig == scriptSig.scriptSig);
+ BOOST_CHECK_EQUAL(combined.scriptSig, scriptSig.scriptSig);
SignatureData scriptSigCopy = scriptSig;
// Signing again will give a different, valid signature:
SignatureData dummy_b;
@@ -1317,9 +1317,9 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
BOOST_CHECK(SignSignature(keystore, CTransaction(txFrom), txTo, 0, SIGHASH_ALL, dummy_c));
scriptSig = DataFromTransaction(txTo, 0, txFrom.vout[0]);
combined = CombineSignatures(txFrom.vout[0], txTo, scriptSig, empty);
- BOOST_CHECK(combined.scriptSig == scriptSig.scriptSig);
+ BOOST_CHECK_EQUAL(combined.scriptSig, scriptSig.scriptSig);
combined = CombineSignatures(txFrom.vout[0], txTo, empty, scriptSig);
- BOOST_CHECK(combined.scriptSig == scriptSig.scriptSig);
+ BOOST_CHECK_EQUAL(combined.scriptSig, scriptSig.scriptSig);
scriptSigCopy = scriptSig;
SignatureData dummy_d;
BOOST_CHECK(SignSignature(keystore, CTransaction(txFrom), txTo, 0, SIGHASH_ALL, dummy_d));
@@ -1334,9 +1334,9 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
BOOST_CHECK(SignSignature(keystore, CTransaction(txFrom), txTo, 0, SIGHASH_ALL, dummy_e));
scriptSig = DataFromTransaction(txTo, 0, txFrom.vout[0]);
combined = CombineSignatures(txFrom.vout[0], txTo, scriptSig, empty);
- BOOST_CHECK(combined.scriptSig == scriptSig.scriptSig);
+ BOOST_CHECK_EQUAL(combined.scriptSig, scriptSig.scriptSig);
combined = CombineSignatures(txFrom.vout[0], txTo, empty, scriptSig);
- BOOST_CHECK(combined.scriptSig == scriptSig.scriptSig);
+ BOOST_CHECK_EQUAL(combined.scriptSig, scriptSig.scriptSig);
// A couple of partially-signed versions:
std::vector<unsigned char> sig1;
@@ -1371,21 +1371,21 @@ BOOST_AUTO_TEST_CASE(script_combineSigs)
partial3_sigs.signatures.emplace(keys[2].GetPubKey().GetID(), SigPair(keys[2].GetPubKey(), sig3));
combined = CombineSignatures(txFrom.vout[0], txTo, partial1_sigs, partial1_sigs);
- BOOST_CHECK(combined.scriptSig == partial1a);
+ BOOST_CHECK_EQUAL(combined.scriptSig, partial1a);
combined = CombineSignatures(txFrom.vout[0], txTo, partial1_sigs, partial2_sigs);
- BOOST_CHECK(combined.scriptSig == complete12);
+ BOOST_CHECK_EQUAL(combined.scriptSig, complete12);
combined = CombineSignatures(txFrom.vout[0], txTo, partial2_sigs, partial1_sigs);
- BOOST_CHECK(combined.scriptSig == complete12);
+ BOOST_CHECK_EQUAL(combined.scriptSig, complete12);
combined = CombineSignatures(txFrom.vout[0], txTo, partial1_sigs, partial2_sigs);
- BOOST_CHECK(combined.scriptSig == complete12);
+ BOOST_CHECK_EQUAL(combined.scriptSig, complete12);
combined = CombineSignatures(txFrom.vout[0], txTo, partial3_sigs, partial1_sigs);
- BOOST_CHECK(combined.scriptSig == complete13);
+ BOOST_CHECK_EQUAL(combined.scriptSig, complete13);
combined = CombineSignatures(txFrom.vout[0], txTo, partial2_sigs, partial3_sigs);
- BOOST_CHECK(combined.scriptSig == complete23);
+ BOOST_CHECK_EQUAL(combined.scriptSig, complete23);
combined = CombineSignatures(txFrom.vout[0], txTo, partial3_sigs, partial2_sigs);
- BOOST_CHECK(combined.scriptSig == complete23);
+ BOOST_CHECK_EQUAL(combined.scriptSig, complete23);
combined = CombineSignatures(txFrom.vout[0], txTo, partial3_sigs, partial3_sigs);
- BOOST_CHECK(combined.scriptSig == partial3c);
+ BOOST_CHECK_EQUAL(combined.scriptSig, partial3c);
}
/**
@@ -1505,7 +1505,7 @@ BOOST_AUTO_TEST_CASE(script_byte_array_u8_vector_equivalence)
{
const CScript scriptPubKey1 = CScript() << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"_hex_v_u8 << OP_CHECKSIG;
const CScript scriptPubKey2 = CScript() << "04678afdb0fe5548271967f1a67130b7105cd6a828e03909a67962e0ea1f61deb649f6bc3f4cef38c4f35504e51ec112de5c384df7ba0b8d578a4c702b6bf11d5f"_hex << OP_CHECKSIG;
- BOOST_CHECK(scriptPubKey1 == scriptPubKey2);
+ BOOST_CHECK_EQUAL(scriptPubKey1, scriptPubKey2);
}
BOOST_AUTO_TEST_CASE(script_FindAndDelete)
@@ -1519,102 +1519,102 @@ BOOST_AUTO_TEST_CASE(script_FindAndDelete)
d = CScript(); // delete nothing should be a no-op
expect = s;
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 0);
- BOOST_CHECK(s == expect);
+ BOOST_CHECK_EQUAL(s, expect);
s = CScript() << OP_1 << OP_2 << OP_3;
d = CScript() << OP_2;
expect = CScript() << OP_1 << OP_3;
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 1);
- BOOST_CHECK(s == expect);
+ BOOST_CHECK_EQUAL(s, expect);
s = CScript() << OP_3 << OP_1 << OP_3 << OP_3 << OP_4 << OP_3;
d = CScript() << OP_3;
expect = CScript() << OP_1 << OP_4;
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 4);
- BOOST_CHECK(s == expect);
+ BOOST_CHECK_EQUAL(s, expect);
s = ToScript("0302ff03"_hex); // PUSH 0x02ff03 onto stack
d = ToScript("0302ff03"_hex);
expect = CScript();
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 1);
- BOOST_CHECK(s == expect);
+ BOOST_CHECK_EQUAL(s, expect);
s = ToScript("0302ff030302ff03"_hex); // PUSH 0x02ff03 PUSH 0x02ff03
d = ToScript("0302ff03"_hex);
expect = CScript();
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 2);
- BOOST_CHECK(s == expect);
+ BOOST_CHECK_EQUAL(s, expect);
s = ToScript("0302ff030302ff03"_hex);
d = ToScript("02"_hex);
expect = s; // FindAndDelete matches entire opcodes
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 0);
- BOOST_CHECK(s == expect);
+ BOOST_CHECK_EQUAL(s, expect);
s = ToScript("0302ff030302ff03"_hex);
d = ToScript("ff"_hex);
expect = s;
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 0);
- BOOST_CHECK(s == expect);
+ BOOST_CHECK_EQUAL(s, expect);
// This is an odd edge case: strip of the push-three-bytes
// prefix, leaving 02ff03 which is push-two-bytes:
s = ToScript("0302ff030302ff03"_hex);
d = ToScript("03"_hex);
expect = CScript() << "ff03"_hex << "ff03"_hex;
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 2);
- BOOST_CHECK(s == expect);
+ BOOST_CHECK_EQUAL(s, expect);
// Byte sequence that spans multiple opcodes:
s = ToScript("02feed5169"_hex); // PUSH(0xfeed) OP_1 OP_VERIFY
d = ToScript("feed51"_hex);
expect = s;
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 0); // doesn't match 'inside' opcodes
- BOOST_CHECK(s == expect);
+ BOOST_CHECK_EQUAL(s, expect);
s = ToScript("02feed5169"_hex); // PUSH(0xfeed) OP_1 OP_VERIFY
d = ToScript("02feed51"_hex);
expect = ToScript("69"_hex);
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 1);
- BOOST_CHECK(s == expect);
+ BOOST_CHECK_EQUAL(s, expect);
s = ToScript("516902feed5169"_hex);
d = ToScript("feed51"_hex);
expect = s;
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 0);
- BOOST_CHECK(s == expect);
+ BOOST_CHECK_EQUAL(s, expect);
s = ToScript("516902feed5169"_hex);
d = ToScript("02feed51"_hex);
expect = ToScript("516969"_hex);
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 1);
- BOOST_CHECK(s == expect);
+ BOOST_CHECK_EQUAL(s, expect);
s = CScript() << OP_0 << OP_0 << OP_1 << OP_1;
d = CScript() << OP_0 << OP_1;
expect = CScript() << OP_0 << OP_1; // FindAndDelete is single-pass
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 1);
- BOOST_CHECK(s == expect);
+ BOOST_CHECK_EQUAL(s, expect);
s = CScript() << OP_0 << OP_0 << OP_1 << OP_0 << OP_1 << OP_1;
d = CScript() << OP_0 << OP_1;
expect = CScript() << OP_0 << OP_1; // FindAndDelete is single-pass
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 2);
- BOOST_CHECK(s == expect);
+ BOOST_CHECK_EQUAL(s, expect);
// Another weird edge case:
// End with invalid push (not enough data)...
s = ToScript("0003feed"_hex);
d = ToScript("03feed"_hex); // ... can remove the invalid push
expect = ToScript("00"_hex);
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 1);
- BOOST_CHECK(s == expect);
+ BOOST_CHECK_EQUAL(s, expect);
s = ToScript("0003feed"_hex);
d = ToScript("00"_hex);
expect = ToScript("03feed"_hex);
BOOST_CHECK_EQUAL(FindAndDelete(s, d), 1);
- BOOST_CHECK(s == expect);
+ BOOST_CHECK_EQUAL(s, expect);
}
BOOST_AUTO_TEST_CASE(script_HasValidOps)
### src/test/txgraph_tests.cpp
@@ -5,6 +5,7 @@
#include <txgraph.h>
#include <random.h>
+#include <test/util/common.h>
#include <boost/test/unit_test.hpp>
@@ -315,11 +316,11 @@ BOOST_AUTO_TEST_CASE(txgraph_chunk_chain)
for (TxGraph::Ref* ref : chunk->first) {
// The reported chunk feerate must match the chunk feerate obtained by asking
// it for each of the chunk's transactions individually.
- BOOST_CHECK(graph->GetMainChunkFeerate(*ref) == chunk->second);
+ BOOST_CHECK_EQUAL(graph->GetMainChunkFeerate(*ref), chunk->second);
// Verify the chunk feerate matches the sum of the reported individual feerates.
sum += graph->GetIndividualFeerate(*ref);
}
- BOOST_CHECK(sum == chunk->second);
+ BOOST_CHECK_EQUAL(sum, chunk->second);
chunks.push_back(std::move(chunk->first));
last_chunk_feerate = chunk->second;
builder->Include();
@@ -331,7 +332,7 @@ BOOST_AUTO_TEST_CASE(txgraph_chunk_chain)
std::reverse(last_chunk.begin(), last_chunk.end());
auto [worst_chunk, worst_chunk_feerate] = graph->GetWorstMainChunk();
BOOST_CHECK(last_chunk == worst_chunk);
- BOOST_CHECK(last_chunk_feerate == worst_chunk_feerate);
+ BOOST_CHECK_EQUAL(last_chunk_feerate, worst_chunk_feerate);
};
std::vector<TxGraph::Ref> refs;
### src/test/util/CMakeLists.txt
@@ -5,6 +5,7 @@
add_library(test_util STATIC EXCLUDE_FROM_ALL
blockfilter.cpp
coins.cpp
+ common.cpp
coverage.cpp
json.cpp
logging.cpp
### src/test/util/common.cpp
@@ -0,0 +1,140 @@
+// Copyright (c) The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or https://www.opensource.org/licenses/mit-license.php.
+
+#include <test/util/common.h>
+
+#include <addresstype.h>
+#include <addrman.h>
+#include <core_io.h>
+#include <crypto/hex_base.h>
+#include <key.h>
+#include <netaddress.h>
+#include <netbase.h>
+#include <protocol.h>
+#include <pubkey.h>
+#include <script/keyorigin.h>
+#include <script/script.h>
+#include <streams.h>
+#include <tinyformat.h>
+#include <util/bip32.h>
+#include <util/string.h>
+
+#include <array>
+#include <ostream>
+#include <variant>
+
+std::ostream& operator<<(std::ostream& os, const AddressPosition& pos)
+{
+ return os << strprintf("AddressPosition(tried=%d, multiplicity=%d, bucket=%d, position=%d)", pos.tried, pos.multiplicity, pos.bucket, pos.position);
+}
+
+std::ostream& operator<<(std::ostream& os, const CScript& script)
+{
+ return os << strprintf("CScript(asm=%s, hex=%s)", ScriptToAsmStr(script), HexStr(script));
+}
+
+std::ostream& operator<<(std::ostream& os, const CService& service)
+{
+ return os << strprintf("CService(addr=%s, net=%s)", service.ToStringAddrPort(), GetNetworkName(service.GetNetwork()));
+}
+
+std::ostream& operator<<(std::ostream& os, const CAddress& addr)
+{
+ return os << strprintf("CAddress(addr=%s, nTime=%s, nServices=[%s])",
+ addr.ToStringAddrPort(),
+ addr.nTime,
+ util::Join(serviceFlagsToStr(addr.nServices), ", "));
+}
+
+std::ostream& operator<<(std::ostream& os, const CExtKey& k)
+{
+ if (!k.key.IsValid()) return os << "CExtKey(<invalid>)";
+ std::array<std::byte, BIP32_EXTKEY_SIZE> code;
+ SpanWriter{code} << k;
+ return os << strprintf("CExtKey(encoded=%s)", HexStr(code));
+}
+
+std::ostream& operator<<(std::ostream& os, const CExtPubKey& k)
+{
+ if (k.pubkey.size() != CPubKey::COMPRESSED_SIZE) return os << "CExtPubKey(<invalid>)";
+ std::array<std::byte, BIP32_EXTKEY_SIZE> code;
+ SpanWriter{code} << k;
+ return os << strprintf("CExtPubKey(encoded=%s)", HexStr(code));
+}
+
+std::ostream& operator<<(std::ostream& os, const FeeFrac& ff)
+{
+ return os << strprintf("FeeFrac(fee=%d, size=%d)", ff.fee, ff.size);
+}
+
+std::ostream& operator<<(std::ostream& os, const ByRatioNegSize<FeeFrac>& b)
+{
+ return os << "ByRatioNegSize(" << static_cast<const FeeFrac&>(b) << ")";
+}
+
+std::ostream& operator<<(std::ostream& os, const CNoDestination& dest)
+{
+ return os << strprintf("CNoDestination(script=%s)", dest.GetScript());
+}
+
+std::ostream& operator<<(std::ostream& os, const PubKeyDestination& dest)
+{
+ return os << strprintf("PubKeyDestination(pubkey=%s)", dest.GetPubKey());
+}
+
+std::ostream& operator<<(std::ostream& os, const PKHash& h)
+{
+ return os << strprintf("PKHash(hash=%s)", h.ToString());
+}
+
+std::ostream& operator<<(std::ostream& os, const ScriptHash& h)
+{
+ return os << strprintf("ScriptHash(hash=%s)", h.ToString());
+}
+
+std::ostream& operator<<(std::ostream& os, const WitnessV0KeyHash& h)
+{
+ return os << strprintf("WitnessV0KeyHash(hash=%s)", h.ToString());
+}
+
+std::ostream& operator<<(std::ostream& os, const WitnessV0ScriptHash& h)
+{
+ return os << strprintf("WitnessV0ScriptHash(hash=%s)", h.ToString());
+}
+
+std::ostream& operator<<(std::ostream& os, const WitnessUnknown& w)
+{
+ return os << strprintf("WitnessUnknown(version=%u, program=%s)", w.GetWitnessVersion(), HexStr(w.GetWitnessProgram()));
+}
+
+std::ostream& operator<<(std::ostream& os, const PayToAnchor& p)
+{
+ return os << strprintf("PayToAnchor(version=%u, program=%s)", p.GetWitnessVersion(), HexStr(p.GetWitnessProgram()));
+}
+
+std::ostream& operator<<(std::ostream& os, const WitnessV1Taproot& t)
+{
+ return os << strprintf("WitnessV1Taproot(program=%s)", HexStr(t));
+}
+
+std::ostream& operator<<(std::ostream& os, const CTxDestination& dest)
+{
+ std::visit([&os](const auto& alt) { os << alt; }, dest);
+ return os;
+}
+
+std::ostream& operator<<(std::ostream& os, const CPubKey& pk)
+{
+ return os << strprintf("CPubKey(pubkey=%s)", HexStr(pk));
+}
+
+std::ostream& operator<<(std::ostream& os, const XOnlyPubKey& pk)
+{
+ return os << strprintf("XOnlyPubKey(pubkey=%s)", HexStr(pk));
+}
+
+std::ostream& operator<<(std::ostream& os, const KeyOriginInfo& info)
+{
+ return os << strprintf("KeyOriginInfo(fingerprint=%s, path=%s)", HexStr(info.fingerprint), FormatHDKeypath(info.path));
+}
### src/test/util/common.h
@@ -5,10 +5,29 @@
#ifndef BITCOIN_TEST_UTIL_COMMON_H
#define BITCOIN_TEST_UTIL_COMMON_H
+// This file defines concepts and operator<< overloads such that
+// Bitcoin Core types are printable by BOOST_CHECK_*. Include this from
+// *_tests.cpp to get value output on failure; browse this file for
+// the list of supported types.
+
+#include <addresstype.h>
+#include <util/feefrac.h>
+
#include <chrono>
#include <optional>
#include <ostream>
#include <string>
+#include <utility>
+
+struct AddressPosition;
+class CAddress;
+struct CExtKey;
+struct CExtPubKey;
+class CPubKey;
+class CScript;
+class CService;
+struct KeyOriginInfo;
+class XOnlyPubKey;
/**
* BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
@@ -57,6 +76,35 @@ inline std::ostream& operator<<(std::ostream& os, const T& obj)
return os << obj.ToString();
}
+std::ostream& operator<<(std::ostream& os, const AddressPosition& pos);
+std::ostream& operator<<(std::ostream& os, const CScript& script);
+std::ostream& operator<<(std::ostream& os, const CService& service);
+std::ostream& operator<<(std::ostream& os, const CAddress& addr);
+std::ostream& operator<<(std::ostream& os, const CExtKey& k);
+std::ostream& operator<<(std::ostream& os, const CExtPubKey& k);
+std::ostream& operator<<(std::ostream& os, const FeeFrac& ff);
+std::ostream& operator<<(std::ostream& os, const CNoDestination& dest);
+std::ostream& operator<<(std::ostream& os, const PubKeyDestination& dest);
+std::ostream& operator<<(std::ostream& os, const PKHash& h);
+std::ostream& operator<<(std::ostream& os, const ScriptHash& h);
+std::ostream& operator<<(std::ostream& os, const WitnessV0KeyHash& h);
+std::ostream& operator<<(std::ostream& os, const WitnessV0ScriptHash& h);
+std::ostream& operator<<(std::ostream& os, const WitnessUnknown& w);
+std::ostream& operator<<(std::ostream& os, const PayToAnchor& p);
+std::ostream& operator<<(std::ostream& os, const WitnessV1Taproot& t);
+std::ostream& operator<<(std::ostream& os, const CTxDestination& dest);
+std::ostream& operator<<(std::ostream& os, const CPubKey& pk);
+std::ostream& operator<<(std::ostream& os, const KeyOriginInfo& info);
+std::ostream& operator<<(std::ostream& os, const ByRatioNegSize<FeeFrac>& b);
+std::ostream& operator<<(std::ostream& os, const XOnlyPubKey& x);
+
+template <typename T, typename U>
+ requires requires(std::ostream& os, const T& t, const U& u) { os << t; os << u; }
+inline std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p)
+{
+ return os << "std::pair(" << p.first << ", " << p.second << ")";
+}
+
// @}
#endif // BITCOIN_TEST_UTIL_COMMON_HWhy 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.