aboutsummaryrefslogtreecommitdiff
path: root/test/functional/p2p_invalid_tx.py
diff options
context:
space:
mode:
authorJames O'Beirne <james.obeirne@gmail.com>2018-10-08 04:56:39 -0400
committerJames O'Beirne <james.obeirne@gmail.com>2018-11-27 17:53:53 -0500
commit59e387705c7e55ec40400301346354fa2d0c613f (patch)
tree612d1ebcc06d97f54f5cc8e3b609f8812a1670ef /test/functional/p2p_invalid_tx.py
parenta4eaaa6ac53606a1533b56050af77961d8c27dc7 (diff)
downloadbitcoin-59e387705c7e55ec40400301346354fa2d0c613f.tar.xz
test: add invalid tx templates for use in functional tests
Add templates for easily constructing different kinds of invalid transactions and use them in feature_block and p2p_invalid_tx.
Diffstat (limited to 'test/functional/p2p_invalid_tx.py')
-rwxr-xr-xtest/functional/p2p_invalid_tx.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/test/functional/p2p_invalid_tx.py b/test/functional/p2p_invalid_tx.py
index 58e129b57d..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):
@@ -63,12 +64,21 @@ class InvalidTxRequestTest(BitcoinTestFramework):
self.log.info("Mature the block.")
self.nodes[0].generatetoaddress(100, self.nodes[0].get_deterministic_priv_key().address)
- # 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)
+ # 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)