Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_invalid_tx.py
Show All 22 Lines | |||||
from test_framework.mininode import network_thread_start, P2PDataStore, network_thread_join | from test_framework.mininode import network_thread_start, P2PDataStore, network_thread_join | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
wait_until, | wait_until, | ||||
) | ) | ||||
REJECT_INVALID = 16 | |||||
REJECT_PUSHONLY = b'mandatory-script-verify-flag-failed (Only push operators allowed in signature scripts)' | |||||
class InvalidTxRequestTest(BitcoinTestFramework): | class InvalidTxRequestTest(BitcoinTestFramework): | ||||
def set_test_params(self): | def set_test_params(self): | ||||
self.num_nodes = 1 | self.num_nodes = 1 | ||||
self.setup_clean_chain = True | self.setup_clean_chain = True | ||||
def bootstrap_p2p(self, *, num_connections=1): | def bootstrap_p2p(self, *, num_connections=1): | ||||
"""Add a P2P connection to the node. | """Add a P2P connection to the node. | ||||
Show All 36 Lines | def run_test(self): | ||||
self.nodes[0].generate(100) | self.nodes[0].generate(100) | ||||
# b'\x64' is OP_NOTIF | # b'\x64' is OP_NOTIF | ||||
# Transaction will be rejected with code 16 (REJECT_INVALID) | # Transaction will be rejected with code 16 (REJECT_INVALID) | ||||
# and we get disconnected immediately | # and we get disconnected immediately | ||||
self.log.info('Test a transaction that is rejected') | self.log.info('Test a transaction that is rejected') | ||||
tx1 = create_transaction( | tx1 = create_transaction( | ||||
block1.vtx[0], 0, b'\x64' * 35, 50 * COIN - 12000) | block1.vtx[0], 0, b'\x64' * 35, 50 * COIN - 12000) | ||||
node.p2p.send_txs_and_test([tx1], node, success=False, expect_disconnect=True, | node.p2p.send_txs_and_test( | ||||
reject_code=REJECT_INVALID, reject_reason=REJECT_PUSHONLY) | [tx1], node, success=False, expect_disconnect=True) | ||||
# Make two p2p connections to provide the node with orphans | # Make two p2p connections to provide the node with orphans | ||||
# * p2ps[0] will send valid orphan txs (one with low fee) | # * p2ps[0] will send valid orphan txs (one with low fee) | ||||
# * p2ps[1] will send an invalid orphan tx (and is later disconnected for that) | # * p2ps[1] will send an invalid orphan tx (and is later disconnected for that) | ||||
self.reconnect_p2p(num_connections=2) | self.reconnect_p2p(num_connections=2) | ||||
self.log.info('Test orphan transaction handling ... ') | self.log.info('Test orphan transaction handling ... ') | ||||
# Create a root transaction that we withold until all dependend transactions | # Create a root transaction that we withold until all dependend transactions | ||||
▲ Show 20 Lines • Show All 88 Lines • Show Last 20 Lines |