@@ -90,6 +90,13 @@ BOOST_AUTO_TEST_CASE(basic)
9090 BOOST_CHECK (!pb.DidNodeConfirmReception (recipient2));
9191 BOOST_CHECK (!pb.DidNodeConfirmReception (nonexistent_recipient));
9292
93+ // 1. Freshly added transactions should NOT be stale yet.
94+ BOOST_CHECK_EQUAL (pb.GetStale ().size (), 0 );
95+
96+ // 2. Fast-forward the mock clock past the INITIAL_STALE_DURATION.
97+ SetMockTime (Now<NodeSeconds>() + PrivateBroadcast::INITIAL_STALE_DURATION + 1min);
98+
99+ // 3. Now that the initial duration has passed, both unconfirmed transactions should be stale.
93100 BOOST_CHECK_EQUAL (pb.GetStale ().size (), 2 );
94101
95102 // Confirm reception by recipient1.
@@ -102,20 +109,21 @@ BOOST_AUTO_TEST_CASE(basic)
102109 const auto infos{pb.GetBroadcastInfo ()};
103110 BOOST_CHECK_EQUAL (infos.size (), 2 );
104111 {
105- const auto & [tx, peers] {find_tx_info (infos, tx_for_recipient1)};
112+ const auto & peers{find_tx_info (infos, tx_for_recipient1). peers };
106113 BOOST_CHECK_EQUAL (peers.size (), 1 );
107114 BOOST_CHECK_EQUAL (peers[0 ].address .ToStringAddrPort (), addr1.ToStringAddrPort ());
108115 BOOST_CHECK (peers[0 ].received .has_value ());
109116 }
110117 {
111- const auto & [tx, peers] {find_tx_info (infos, tx_for_recipient2)};
118+ const auto & peers{find_tx_info (infos, tx_for_recipient2). peers };
112119 BOOST_CHECK_EQUAL (peers.size (), 1 );
113120 BOOST_CHECK_EQUAL (peers[0 ].address .ToStringAddrPort (), addr2.ToStringAddrPort ());
114121 BOOST_CHECK (!peers[0 ].received .has_value ());
115122 }
116123
117- BOOST_CHECK_EQUAL (pb.GetStale ().size (), 1 );
118- BOOST_CHECK_EQUAL (pb.GetStale ()[0 ], tx_for_recipient2);
124+ const auto stale_state{pb.GetStale ()};
125+ BOOST_CHECK_EQUAL (stale_state.size (), 1 );
126+ BOOST_CHECK_EQUAL (stale_state[0 ], tx_for_recipient2);
119127
120128 SetMockTime (Now<NodeSeconds>() + 10h);
121129
@@ -131,4 +139,22 @@ BOOST_AUTO_TEST_CASE(basic)
131139 BOOST_CHECK (!pb.PickTxForSend (/* will_send_to_nodeid=*/ nonexistent_recipient, /* will_send_to_address=*/ addr_nonexistent).has_value ());
132140}
133141
142+ BOOST_AUTO_TEST_CASE (stale_unpicked_tx)
143+ {
144+ SetMockTime (Now<NodeSeconds>());
145+
146+ PrivateBroadcast pb;
147+ const auto tx{MakeDummyTx (/* id=*/ 42 , /* num_witness=*/ 0 )};
148+ BOOST_REQUIRE (pb.Add (tx));
149+
150+ // Unpicked transactions use the longer INITIAL_STALE_DURATION.
151+ BOOST_CHECK_EQUAL (pb.GetStale ().size (), 0 );
152+ SetMockTime (Now<NodeSeconds>() + PrivateBroadcast::INITIAL_STALE_DURATION - 1min);
153+ BOOST_CHECK_EQUAL (pb.GetStale ().size (), 0 );
154+ SetMockTime (Now<NodeSeconds>() + 2min);
155+ const auto stale_state{pb.GetStale ()};
156+ BOOST_REQUIRE_EQUAL (stale_state.size (), 1 );
157+ BOOST_CHECK_EQUAL (stale_state[0 ], tx);
158+ }
159+
134160BOOST_AUTO_TEST_SUITE_END ()
0 commit comments