From 35bf69ec94e2de302699fd4f34118c26f5022d9c Mon Sep 17 00:00:00 2001 From: Sami Ahmed Date: Thu, 26 Mar 2026 20:49:07 -0700 Subject: [PATCH] Fix test linker errors: add missing global stubs, update orphan tx API - test_triangles.cpp: add globals excluded with init.o (fEnforceCanonical, nNodeLifespan, fConfChange, CheckpointsMode, nDerivationMethodIndex, fUseFastIndex) - DoS_tests.cpp: update AddOrphanTx and mapOrphanTransactions to match current CTransaction-based API (was old CDataStream-based) Co-Authored-By: Claude Opus 4.6 --- src/test/DoS_tests.cpp | 29 +++++++++-------------------- src/test/test_triangles.cpp | 9 +++++++++ 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/test/DoS_tests.cpp b/src/test/DoS_tests.cpp index 20f4c54..df4bf20 100644 --- a/src/test/DoS_tests.cpp +++ b/src/test/DoS_tests.cpp @@ -14,10 +14,10 @@ #include // Tests this internal-to-main.cpp method: -extern bool AddOrphanTx(const CDataStream& vMsg); +extern bool AddOrphanTx(const CTransaction& tx); extern unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans); -extern std::map mapOrphanTransactions; -extern std::map > mapOrphanTransactionsByPrev; +extern std::map mapOrphanTransactions; +extern std::map > mapOrphanTransactionsByPrev; CService ip(uint32_t i) { @@ -131,14 +131,11 @@ BOOST_AUTO_TEST_CASE(DoS_checknbits) CTransaction RandomOrphan() { - std::map::iterator it; + std::map::iterator it; it = mapOrphanTransactions.lower_bound(GetRandHash()); if (it == mapOrphanTransactions.end()) it = mapOrphanTransactions.begin(); - const CDataStream* pvMsg = it->second; - CTransaction tx; - CDataStream(*pvMsg) >> tx; - return tx; + return it->second; } BOOST_AUTO_TEST_CASE(DoS_mapOrphans) @@ -160,9 +157,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans) tx.vout[0].nValue = 1*CENT; tx.vout[0].scriptPubKey.SetDestination(key.GetPubKey().GetID()); - CDataStream ds(SER_DISK, CLIENT_VERSION); - ds << tx; - AddOrphanTx(ds); + AddOrphanTx(tx); } // ... and 50 that depend on other orphans: @@ -179,9 +174,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans) tx.vout[0].scriptPubKey.SetDestination(key.GetPubKey().GetID()); SignSignature(keystore, txPrev, tx, 0); - CDataStream ds(SER_DISK, CLIENT_VERSION); - ds << tx; - AddOrphanTx(ds); + AddOrphanTx(tx); } // This really-big orphan should be ignored: @@ -205,9 +198,7 @@ BOOST_AUTO_TEST_CASE(DoS_mapOrphans) for (unsigned int j = 1; j < tx.vin.size(); j++) tx.vin[j].scriptSig = tx.vin[0].scriptSig; - CDataStream ds(SER_DISK, CLIENT_VERSION); - ds << tx; - BOOST_CHECK(!AddOrphanTx(ds)); + BOOST_CHECK(!AddOrphanTx(tx)); } // Test LimitOrphanTxSize() function: @@ -243,9 +234,7 @@ BOOST_AUTO_TEST_CASE(DoS_checkSig) tx.vout[0].nValue = 1*CENT; tx.vout[0].scriptPubKey.SetDestination(key.GetPubKey().GetID()); - CDataStream ds(SER_DISK, CLIENT_VERSION); - ds << tx; - AddOrphanTx(ds); + AddOrphanTx(tx); } // Create a transaction that depends on orphans: diff --git a/src/test/test_triangles.cpp b/src/test/test_triangles.cpp index ef0d4c2..61d9640 100644 --- a/src/test/test_triangles.cpp +++ b/src/test/test_triangles.cpp @@ -4,10 +4,19 @@ #include "db.h" #include "main.h" #include "wallet.h" +#include "checkpoints.h" CWallet* pwalletMain; CClientUIInterface uiInterface; +// Globals normally defined in init.cpp (excluded from test build) +bool fConfChange; +bool fEnforceCanonical; +unsigned int nNodeLifespan; +unsigned int nDerivationMethodIndex; +bool fUseFastIndex; +enum Checkpoints::CPMode CheckpointsMode; + extern bool fPrintToConsole; extern void noui_connect();