6
6
7
7
import time
8
8
9
- from test_framework .blocktools import COINBASE_MATURITY
10
9
from test_framework .messages import msg_tx
11
10
from test_framework .p2p import P2PInterface , P2PTxInvStore
12
11
from test_framework .test_framework import BitcoinTestFramework
16
15
17
16
class P2PBlocksOnly (BitcoinTestFramework ):
18
17
def set_test_params (self ):
19
- self .setup_clean_chain = True
20
18
self .num_nodes = 1
21
19
self .extra_args = [["-blocksonly" ]]
22
20
23
21
def run_test (self ):
24
22
self .miniwallet = MiniWallet (self .nodes [0 ])
25
23
# Add enough mature utxos to the wallet, so that all txs spend confirmed coins
26
- self .generate (self .miniwallet , 2 )
27
- self .generate (self .nodes [0 ], COINBASE_MATURITY )
24
+ self .miniwallet .rescan_utxos ()
28
25
29
26
self .blocksonly_mode_tests ()
30
27
self .blocks_relay_conn_tests ()
@@ -83,7 +80,7 @@ def blocks_relay_conn_tests(self):
83
80
# Ensure we disconnect if a block-relay-only connection sends us a transaction
84
81
self .nodes [0 ].add_outbound_p2p_connection (P2PInterface (), p2p_idx = 0 , connection_type = "block-relay-only" )
85
82
assert_equal (self .nodes [0 ].getpeerinfo ()[0 ]['relaytxes' ], False )
86
- _ , txid , _ , tx_hex = self .check_p2p_tx_violation (index = 2 )
83
+ _ , txid , _ , tx_hex = self .check_p2p_tx_violation ()
87
84
88
85
self .log .info ("Check that txs from RPC are not sent to blockrelay connection" )
89
86
conn = self .nodes [0 ].add_outbound_p2p_connection (P2PTxInvStore (), p2p_idx = 1 , connection_type = "block-relay-only" )
@@ -96,11 +93,9 @@ def blocks_relay_conn_tests(self):
96
93
conn .sync_send_with_ping ()
97
94
assert (int (txid , 16 ) not in conn .get_invs ())
98
95
99
- def check_p2p_tx_violation (self , index = 1 ):
96
+ def check_p2p_tx_violation (self ):
100
97
self .log .info ('Check that txs from P2P are rejected and result in disconnect' )
101
- input_txid = self .nodes [0 ].getblock (self .nodes [0 ].getblockhash (index ), 2 )['tx' ][0 ]['txid' ]
102
- utxo_to_spend = self .miniwallet .get_utxo (txid = input_txid )
103
- spendtx = self .miniwallet .create_self_transfer (from_node = self .nodes [0 ], utxo_to_spend = utxo_to_spend )
98
+ spendtx = self .miniwallet .create_self_transfer (from_node = self .nodes [0 ])
104
99
105
100
with self .nodes [0 ].assert_debug_log (['transaction sent in violation of protocol peer=0' ]):
106
101
self .nodes [0 ].p2ps [0 ].send_message (msg_tx (spendtx ['tx' ]))
0 commit comments