Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_invalid_tx.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2015-2017 The Bitcoin Core developers | # Copyright (c) 2015-2017 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test node responses to invalid transactions. | """Test node responses to invalid transactions. | ||||
In this test we connect to one node over p2p, and test tx requests. | In this test we connect to one node over p2p, and test tx requests. | ||||
""" | """ | ||||
from test_framework.blocktools import ( | from test_framework.blocktools import ( | ||||
create_block, | create_block, | ||||
create_coinbase, | create_coinbase, | ||||
create_transaction, | create_tx_with_script, | ||||
) | ) | ||||
from test_framework.txtools import pad_tx | from test_framework.txtools import pad_tx | ||||
from test_framework.messages import ( | from test_framework.messages import ( | ||||
COIN, | COIN, | ||||
COutPoint, | COutPoint, | ||||
CTransaction, | CTransaction, | ||||
CTxIn, | CTxIn, | ||||
CTxOut, | CTxOut, | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.log.info("Mature the block.") | self.log.info("Mature the block.") | ||||
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_tx_with_script( | ||||
block1.vtx[0], 0, b'\x64' * 35, 50 * COIN - 12000) | block1.vtx[0], 0, script_sig=b'\x64' * 35, amount=50 * COIN - 12000) | ||||
node.p2p.send_txs_and_test( | node.p2p.send_txs_and_test( | ||||
[tx1], node, success=False, expect_disconnect=True) | [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) | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |