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):
diff --git a/test/functional/p2p_segwit.py b/test/functional/p2p_segwit.py
index 519fb0438f..e0c671f55d 100755
--- a/test/functional/p2p_segwit.py
+++ b/test/functional/p2p_segwit.py
@@ -123,13 +123,14 @@ def get_virtual_size(witness_block):
vsize = int((3 * base_size + total_size + 3) / 4)
return vsize
-def test_transaction_acceptance(node, p2p, tx, with_witness, accepted, reason=None):
+def test_transaction_acceptance(node, p2p, tx, with_witness, accepted, reason=None, non_reason=None):
"""Send a transaction to the node and check that it's accepted to the mempool
- Submit the transaction over the p2p interface
- use the getrawmempool rpc to check for acceptance."""
reason = [reason] if reason else []
- with node.assert_debug_log(expected_msgs=reason):
+ non_reason = [non_reason] if non_reason else []
+ with node.assert_debug_log(expected_msgs=reason, unexpected_msgs=non_reason):
p2p.send_and_ping(msg_tx(tx) if with_witness else msg_no_witness_tx(tx))
assert_equal(tx.hash in node.getrawmempool(), accepted)
@@ -1418,7 +1419,7 @@ class SegWitTest(BitcoinTestFramework):
temp_utxo.pop() # last entry in temp_utxo was the output we just spent
temp_utxo.append(UTXO(tx2.sha256, 0, tx2.vout[0].nValue))
- # Spend everything in temp_utxo into an segwit v1 output.
+ # Spend everything in temp_utxo into a segwit v1 output.
tx3 = CTransaction()
total_value = 0
for i in temp_utxo:
@@ -1433,8 +1434,9 @@ class SegWitTest(BitcoinTestFramework):
# making sure the txid is added to the reject filter
self.std_node.announce_tx_and_wait_for_getdata(tx3)
test_transaction_acceptance(self.nodes[1], self.std_node, tx3, with_witness=True, accepted=False, reason="bad-txns-nonstandard-inputs")
- # Now the node will no longer ask for getdata of this transaction when advertised by same txid
- self.std_node.announce_tx_and_wait_for_getdata(tx3, timeout=5, success=False)
+ # If we send the transaction again, it'll be rejected by the recent
+ # rejects filter before we try to accept it to mempool
+ test_transaction_acceptance(self.nodes[1], self.std_node, tx3, with_witness=True, accepted=False, non_reason="bad-txns-nonstandard-inputs")
# Spending a higher version witness output is not allowed by policy,
# even with fRequireStandard=false.