aboutsummaryrefslogtreecommitdiff
path: root/test/functional/p2p_invalid_tx.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/p2p_invalid_tx.py')
-rwxr-xr-xtest/functional/p2p_invalid_tx.py40
1 files changed, 22 insertions, 18 deletions
diff --git a/test/functional/p2p_invalid_tx.py b/test/functional/p2p_invalid_tx.py
index 0aa5e21103..1b18dd3e58 100755
--- a/test/functional/p2p_invalid_tx.py
+++ b/test/functional/p2p_invalid_tx.py
@@ -5,7 +5,7 @@
"""Test node responses to invalid transactions.
In this test we connect to one node over p2p, and test tx requests."""
-from test_framework.blocktools import create_block, create_coinbase, create_tx_with_script
+from test_framework.blocktools import create_block, create_coinbase
from test_framework.messages import (
COIN,
COutPoint,
@@ -19,6 +19,7 @@ from test_framework.util import (
assert_equal,
wait_until,
)
+from data import invalid_txs
class InvalidTxRequestTest(BitcoinTestFramework):
@@ -61,14 +62,23 @@ class InvalidTxRequestTest(BitcoinTestFramework):
node.p2p.send_blocks_and_test([block], node, success=True)
self.log.info("Mature the block.")
- self.nodes[0].generate(100)
-
- # b'\x64' is OP_NOTIF
- # Transaction will be rejected with code 16 (REJECT_INVALID)
- # and we get disconnected immediately
- self.log.info('Test a transaction that is rejected')
- tx1 = create_tx_with_script(block1.vtx[0], 0, script_sig=b'\x64' * 35, amount=50 * COIN - 12000)
- node.p2p.send_txs_and_test([tx1], node, success=False, expect_disconnect=True)
+ self.nodes[0].generatetoaddress(100, self.nodes[0].get_deterministic_priv_key().address)
+
+ # Iterate through a list of known invalid transaction types, ensuring each is
+ # rejected. Some are consensus invalid and some just violate policy.
+ for BadTxTemplate in invalid_txs.iter_all_templates():
+ self.log.info("Testing invalid transaction: %s", BadTxTemplate.__name__)
+ template = BadTxTemplate(spend_block=block1)
+ tx = template.get_tx()
+ node.p2p.send_txs_and_test(
+ [tx], node, success=False,
+ expect_disconnect=template.expect_disconnect,
+ reject_reason=template.reject_reason,
+ )
+
+ if template.expect_disconnect:
+ self.log.info("Reconnecting to peer")
+ self.reconnect_p2p()
# Make two p2p connections to provide the node with orphans
# * p2ps[0] will send valid orphan txs (one with low fee)
@@ -76,7 +86,7 @@ class InvalidTxRequestTest(BitcoinTestFramework):
self.reconnect_p2p(num_connections=2)
self.log.info('Test orphan transaction handling ... ')
- # Create a root transaction that we withhold until all dependend transactions
+ # Create a root transaction that we withhold until all dependent transactions
# are sent out and in the orphan cache
SCRIPT_PUB_KEY_OP_TRUE = b'\x51\x75' * 15 + b'\x51'
tx_withhold = CTransaction()
@@ -116,7 +126,8 @@ class InvalidTxRequestTest(BitcoinTestFramework):
assert_equal(2, len(node.getpeerinfo())) # p2ps[1] is still connected
self.log.info('Send the withhold tx ... ')
- node.p2p.send_txs_and_test([tx_withhold], node, success=True)
+ with node.assert_debug_log(expected_msgs=["bad-txns-in-belowout"]):
+ node.p2p.send_txs_and_test([tx_withhold], node, success=True)
# Transactions that should end up in the mempool
expected_mempool = {
@@ -134,13 +145,6 @@ class InvalidTxRequestTest(BitcoinTestFramework):
wait_until(lambda: 1 == len(node.getpeerinfo()), timeout=12) # p2ps[1] is no longer connected
assert_equal(expected_mempool, set(node.getrawmempool()))
- # restart node with sending BIP61 messages disabled, check that it disconnects without sending the reject message
- self.log.info('Test a transaction that is rejected, with BIP61 disabled')
- self.restart_node(0, ['-enablebip61=0','-persistmempool=0'])
- self.reconnect_p2p(num_connections=1)
- node.p2p.send_txs_and_test([tx1], node, success=False, expect_disconnect=True)
- # send_txs_and_test will have waited for disconnect, so we can safely check that no reject has been received
- assert_equal(node.p2p.reject_code_received, None)
if __name__ == '__main__':
InvalidTxRequestTest().main()