12#include <boost/test/unit_test.hpp>
20 mtx.
vin[0].nSequence = id;
21 if (num_witness > 0) {
23 mtx.
vin[0].scriptWitness.stack.resize(num_witness);
33 const NodeId recipient1{1};
35 ipv4Addr.s_addr = 0xa0b0c001;
52 BOOST_REQUIRE(tx1->GetHash() == tx2->GetHash());
53 BOOST_REQUIRE(tx1->GetWitnessHash() != tx2->GetWitnessHash());
57 const auto it{std::ranges::find(infos, tx->GetWitnessHash(), [](
const auto& info) { return info.tx->GetWitnessHash(); })};
58 BOOST_REQUIRE(it != infos.end());
61 const auto check_peer_counts{[&](
size_t tx1_peer_count,
size_t tx2_peer_count) {
68 check_peer_counts(0, 0);
71 BOOST_CHECK(tx_for_recipient1 == tx1 || tx_for_recipient1 == tx2);
74 const NodeId recipient2{2};
77 BOOST_CHECK(tx_for_recipient2 == tx1 || tx_for_recipient2 == tx2);
78 BOOST_CHECK_NE(tx_for_recipient1, tx_for_recipient2);
80 check_peer_counts(1, 1);
82 const NodeId nonexistent_recipient{0};
113 const auto& peers{find_tx_info(infos, tx_for_recipient1).peers};
119 const auto& peers{find_tx_info(infos, tx_for_recipient2).peers};
125 const auto stale_state{pb.
GetStale()};
139 const CService addr_nonexistent{ipv4Addr, 3333};
149 BOOST_REQUIRE(pb.
Add(tx));
156 const auto stale_state{pb.
GetStale()};
157 BOOST_REQUIRE_EQUAL(stale_state.size(), 1);
A combination of a network address (CNetAddr) and a (TCP) port.
Helper to initialize the global NodeClock, let a duration elapse, and reset it after use in a test.
Store a list of transactions to be broadcast privately.
void NodeConfirmedReception(const NodeId &nodeid) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Mark that the node has confirmed reception of the transaction we sent it by responding with PONG to o...
std::vector< TxBroadcastInfo > GetBroadcastInfo() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Get stats about all transactions currently being privately broadcast.
bool HavePendingTransactions() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Check if there are transactions that need to be broadcast.
bool DidNodeConfirmReception(const NodeId &nodeid) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Check if the node has confirmed reception of the transaction.
std::optional< size_t > Remove(const CTransactionRef &tx) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Forget a transaction.
std::optional< CTransactionRef > PickTxForSend(const NodeId &will_send_to_nodeid, const CService &will_send_to_address) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Pick the transaction with the fewest send attempts, and confirmations, and oldest send/confirm times.
std::optional< CTransactionRef > GetTxForNode(const NodeId &nodeid) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Get the transaction that was picked for sending to a given node by PickTxForSend().
bool Add(const CTransactionRef &tx) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Add a transaction to the storage.
std::vector< CTransactionRef > GetStale() const EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Get the transactions that have not been broadcast recently.
static constexpr auto INITIAL_STALE_DURATION
If a transaction is not sent to any peer for this duration, then we consider it stale / for rebroadca...
BOOST_FIXTURE_TEST_SUITE(cuckoocache_tests, BasicTestingSetup)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
BOOST_CHECK_EQUAL(headers.FindFirst("key"), "value")
static const std::string addr1
static const std::string addr2
#define BOOST_CHECK(expr)
static CTransactionRef MakeTransactionRef(Tx &&txIn)
std::shared_ptr< const CTransaction > CTransactionRef
static CTransactionRef MakeDummyTx(uint32_t id, size_t num_witness)
BOOST_AUTO_TEST_CASE(basic)
A mutable version of CTransaction.