Skip to content

Commit 8bb6bea

Browse files
committed
[test/refactor] P2PBlocksOnly - Extract transaction violation test into helper.
This is in preparation for use in the next commit.
1 parent 99791e7 commit 8bb6bea

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

test/functional/p2p_blocksonly.py

+24-13
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,17 @@ def skip_test_if_missing_module(self):
2121
self.skip_if_no_wallet()
2222

2323
def run_test(self):
24-
block_relay_peer = self.nodes[0].add_p2p_connection(P2PInterface())
25-
26-
input_txid = self.nodes[0].getblock(self.nodes[0].getblockhash(1), 2)['tx'][0]['txid']
27-
tx = create_transaction(self.nodes[0], input_txid, self.nodes[0].getnewaddress(), amount=(50 - 0.001))
28-
txid = tx.rehash()
29-
tx_hex = tx.serialize().hex()
24+
self.blocksonly_mode_tests()
3025

26+
def blocksonly_mode_tests(self):
27+
self.log.info("Tests with node running in -blocksonly mode")
3128
assert_equal(self.nodes[0].getnetworkinfo()['localrelay'], False)
32-
with self.nodes[0].assert_debug_log(['transaction sent in violation of protocol peer=0']):
33-
block_relay_peer.send_message(msg_tx(tx))
34-
block_relay_peer.wait_for_disconnect()
35-
assert_equal(self.nodes[0].getmempoolinfo()['size'], 0)
3629

37-
# Remove the disconnected peer and add a new one.
38-
del self.nodes[0].p2ps[0]
39-
tx_relay_peer = self.nodes[0].add_p2p_connection(P2PInterface())
30+
self.nodes[0].add_p2p_connection(P2PInterface())
31+
tx, txid, tx_hex = self.check_p2p_tx_violation()
4032

4133
self.log.info('Check that txs from rpc are not rejected and relayed to other peers')
34+
tx_relay_peer = self.nodes[0].add_p2p_connection(P2PInterface())
4235
assert_equal(self.nodes[0].getpeerinfo()[0]['relaytxes'], True)
4336

4437
assert_equal(self.nodes[0].testmempoolaccept([tx_hex])[0]['allowed'], True)
@@ -73,6 +66,24 @@ def run_test(self):
7366
assert_equal(self.nodes[0].getmempoolinfo()['size'], 1)
7467
self.log.info("Relay-permission peer's transaction is accepted and relayed")
7568

69+
def check_p2p_tx_violation(self):
70+
self.log.info('Check that txs from P2P are rejected and result in disconnect')
71+
72+
input_txid = self.nodes[0].getblock(self.nodes[0].getblockhash(1), 2)['tx'][0]['txid']
73+
tx = create_transaction(self.nodes[0], input_txid, self.nodes[0].getnewaddress(), amount=(50 - 0.001))
74+
txid = tx.rehash()
75+
tx_hex = tx.serialize().hex()
76+
77+
with self.nodes[0].assert_debug_log(['transaction sent in violation of protocol peer=0']):
78+
self.nodes[0].p2ps[0].send_message(msg_tx(tx))
79+
self.nodes[0].p2ps[0].wait_for_disconnect()
80+
assert_equal(self.nodes[0].getmempoolinfo()['size'], 0)
81+
82+
# Remove the disconnected peer
83+
del self.nodes[0].p2ps[0]
84+
85+
return tx, txid, tx_hex
86+
7687

7788
if __name__ == '__main__':
7889
P2PBlocksOnly().main()

0 commit comments

Comments
 (0)