I don’t like that this is testing transaction acceptance by relying on our transaction download logic. It means that changes to transaction download (eg #19184) may cause unrelated tests to fail, or (perhaps worse) make it such that tests are no longer actually testing what we want them to test.
Unfortunately, we have no way to directly query a node’s recent rejects filter, so we do need to test this indirectly somehow. Here’s an alternative that uses the debug log to determine why the transaction has been rejected. It’s not ideal, but I think it’s better than testing via a separate subcomponent (tx download):
0diff --git a/test/functional/p2p_segwit.py b/test/functional/p2p_segwit.py
1index 519fb0438f..e0c671f55d 100755
2--- a/test/functional/p2p_segwit.py
3+++ b/test/functional/p2p_segwit.py
4@@ -123,13 +123,14 @@ def get_virtual_size(witness_block):
5 vsize = int((3 * base_size + total_size + 3) / 4)
6 return vsize
7
8-def test_transaction_acceptance(node, p2p, tx, with_witness, accepted, reason=None):
9+def test_transaction_acceptance(node, p2p, tx, with_witness, accepted, reason=None, non_reason=None):
10 """Send a transaction to the node and check that it's accepted to the mempool
11
12 - Submit the transaction over the p2p interface
13 - use the getrawmempool rpc to check for acceptance."""
14 reason = [reason] if reason else []
15- with node.assert_debug_log(expected_msgs=reason):
16+ non_reason = [non_reason] if non_reason else []
17+ with node.assert_debug_log(expected_msgs=reason, unexpected_msgs=non_reason):
18 p2p.send_and_ping(msg_tx(tx) if with_witness else msg_no_witness_tx(tx))
19 assert_equal(tx.hash in node.getrawmempool(), accepted)
20
21@@ -1418,7 +1419,7 @@ class SegWitTest(BitcoinTestFramework):
22 temp_utxo.pop() # last entry in temp_utxo was the output we just spent
23 temp_utxo.append(UTXO(tx2.sha256, 0, tx2.vout[0].nValue))
24
25- # Spend everything in temp_utxo into an segwit v1 output.
26+ # Spend everything in temp_utxo into a segwit v1 output.
27 tx3 = CTransaction()
28 total_value = 0
29 for i in temp_utxo:
30@@ -1433,8 +1434,9 @@ class SegWitTest(BitcoinTestFramework):
31 # making sure the txid is added to the reject filter
32 self.std_node.announce_tx_and_wait_for_getdata(tx3)
33 test_transaction_acceptance(self.nodes[1], self.std_node, tx3, with_witness=True, accepted=False, reason="bad-txns-nonstandard-inputs")
34- # Now the node will no longer ask for getdata of this transaction when advertised by same txid
35- self.std_node.announce_tx_and_wait_for_getdata(tx3, timeout=5, success=False)
36+ # If we send the transaction again, it'll be rejected by the recent
37+ # rejects filter before we try to accept it to mempool
38+ test_transaction_acceptance(self.nodes[1], self.std_node, tx3, with_witness=True, accepted=False, non_reason="bad-txns-nonstandard-inputs")
39
40 # Spending a higher version witness output is not allowed by policy,
41 # even with fRequireStandard=false.