@@ -21,24 +21,17 @@ def skip_test_if_missing_module(self):
21
21
self .skip_if_no_wallet ()
22
22
23
23
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 ()
30
25
26
+ def blocksonly_mode_tests (self ):
27
+ self .log .info ("Tests with node running in -blocksonly mode" )
31
28
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 )
36
29
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 ()
40
32
41
33
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 ())
42
35
assert_equal (self .nodes [0 ].getpeerinfo ()[0 ]['relaytxes' ], True )
43
36
44
37
assert_equal (self .nodes [0 ].testmempoolaccept ([tx_hex ])[0 ]['allowed' ], True )
@@ -73,6 +66,24 @@ def run_test(self):
73
66
assert_equal (self .nodes [0 ].getmempoolinfo ()['size' ], 1 )
74
67
self .log .info ("Relay-permission peer's transaction is accepted and relayed" )
75
68
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
+
76
87
77
88
if __name__ == '__main__' :
78
89
P2PBlocksOnly ().main ()
0 commit comments