Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_invalid_tx.py
Show First 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
node.p2p.send_txs_and_test( | node.p2p.send_txs_and_test( | ||||
[tx_orphan_1, tx_orphan_2_no_fee, tx_orphan_2_valid], node, success=False) | [tx_orphan_1, tx_orphan_2_no_fee, tx_orphan_2_valid], node, success=False) | ||||
# Send invalid tx from p2ps[1] | # Send invalid tx from p2ps[1] | ||||
node.p2ps[1].send_txs_and_test( | node.p2ps[1].send_txs_and_test( | ||||
[tx_orphan_2_invalid], node, success=False) | [tx_orphan_2_invalid], node, success=False) | ||||
# Mempool should be empty | # Mempool should be empty | ||||
assert_equal(0, node.getmempoolinfo()['size']) | assert_equal(0, node.getmempoolinfo()['size']) | ||||
assert_equal(2, len(node.getpeerinfo())) # p2ps[1] is still connected | # p2ps[1] is still connected | ||||
assert_equal(2, len(node.getpeerinfo())) | |||||
self.log.info('Send the withhold tx ... ') | self.log.info('Send the withhold tx ... ') | ||||
with node.assert_debug_log(expected_msgs=["bad-txns-in-belowout"]): | |||||
node.p2p.send_txs_and_test([tx_withhold], node, success=True) | node.p2p.send_txs_and_test([tx_withhold], node, success=True) | ||||
# Transactions that should end up in the mempool | # Transactions that should end up in the mempool | ||||
expected_mempool = { | expected_mempool = { | ||||
t.hash | t.hash | ||||
for t in [ | for t in [ | ||||
tx_withhold, # The transaction that is the root for all orphans | tx_withhold, # The transaction that is the root for all orphans | ||||
tx_orphan_1, # The orphan transaction that splits the coins | tx_orphan_1, # The orphan transaction that splits the coins | ||||
# The valid transaction (with sufficient fee) | # The valid transaction (with sufficient fee) | ||||
tx_orphan_2_valid, | tx_orphan_2_valid, | ||||
] | ] | ||||
} | } | ||||
# Transactions that do not end up in the mempool | # Transactions that do not end up in the mempool | ||||
# tx_orphan_no_fee, because it has too low fee (p2ps[0] is not disconnected for relaying that tx) | # tx_orphan_no_fee, because it has too low fee (p2ps[0] is not disconnected for relaying that tx) | ||||
# tx_orphan_invaid, because it has negative fee (p2ps[1] is disconnected for relaying that tx) | # tx_orphan_invaid, because it has negative fee (p2ps[1] is disconnected for relaying that tx) | ||||
# p2ps[1] is no longer connected | # p2ps[1] is no longer connected | ||||
wait_until(lambda: 1 == len(node.getpeerinfo()), timeout=12) | wait_until(lambda: 1 == len(node.getpeerinfo()), timeout=12) | ||||
assert_equal(expected_mempool, set(node.getrawmempool())) | assert_equal(expected_mempool, set(node.getrawmempool())) | ||||
# restart node with sending BIP61 messages disabled, check that it disconnects without sending the reject message | # restart node with sending BIP61 messages disabled, check that it disconnects without sending the reject message | ||||
self.log.info( | self.log.info( | ||||
'Test a transaction that is rejected, with BIP61 disabled') | 'Test a transaction that is rejected, with BIP61 disabled') | ||||
self.restart_node(0, ['-enablebip61=0', '-persistmempool=0']) | self.restart_node(0, ['-enablebip61=0', '-persistmempool=0']) | ||||
self.reconnect_p2p(num_connections=1) | self.reconnect_p2p(num_connections=1) | ||||
with node.assert_debug_log(expected_msgs=[ | |||||
"{} from peer=0 was not accepted: mandatory-script-verify-flag-failed (Invalid OP_IF construction) (code 16)".format( | |||||
tx1.hash), | |||||
"disconnecting peer=0", | |||||
]): | |||||
node.p2p.send_txs_and_test( | node.p2p.send_txs_and_test( | ||||
[tx1], node, success=False, expect_disconnect=True) | [tx1], node, success=False, reject_reason="{} from peer=0 was not accepted: mandatory-script-verify-flag-failed (Invalid OP_IF construction) (code 16)".format(tx1.hash), 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__': | if __name__ == '__main__': | ||||
InvalidTxRequestTest().main() | InvalidTxRequestTest().main() |