Skip to content

Commit 4b16c61

Browse files
Prayankrobot-dreams
Prayank
andcommitted
scripted-diff: test: Replace uses of (dis)?connect_nodes global
-BEGIN VERIFY SCRIPT- # max-depth=0 excludes test/functional/test_framework/... FILES=$(git grep -l --max-depth 0 "connect_nodes" test/functional) # Replace (dis)?connect_nodes(self.nodes[a], b) with self.(dis)?connect_nodes(a, b) sed -i 's/\b\(dis\)\?connect_nodes(self\.nodes\[\(.*\)\]/self.\1connect_nodes(\2/g' $FILES # Remove imports in the middle of a line sed -i 's/\(dis\)\?connect_nodes, //g' $FILES sed -i 's/, \(dis\)\?connect_nodes//g' $FILES # Remove imports on a line by themselves sed -i '/^\s*\(dis\)\?connect_nodes,\?$/d' $FILES sed -i '/^from test_framework\.util import connect_nodes$/d' $FILES -END VERIFY SCRIPT- Co-authored-by: Elliott Jin <[email protected]>
1 parent be38684 commit 4b16c61

38 files changed

+119
-165
lines changed

test/functional/example_test.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from test_framework.test_framework import BitcoinTestFramework
2626
from test_framework.util import (
2727
assert_equal,
28-
connect_nodes,
2928
)
3029

3130
# P2PInterface is a class containing callbacks to be executed when a P2P
@@ -115,7 +114,7 @@ def setup_network(self):
115114
# In this test, we're not connecting node2 to node0 or node1. Calls to
116115
# sync_all() should not include node2, since we're not expecting it to
117116
# sync.
118-
connect_nodes(self.nodes[0], 1)
117+
self.connect_nodes(0, 1)
119118
self.sync_all(self.nodes[0:2])
120119

121120
# Use setup_nodes() to customize the node start behaviour (for example if
@@ -183,7 +182,7 @@ def run_test(self):
183182
self.nodes[1].waitforblockheight(11)
184183

185184
self.log.info("Connect node2 and node1")
186-
connect_nodes(self.nodes[1], 2)
185+
self.connect_nodes(1, 2)
187186

188187
self.log.info("Wait for node2 to receive all the blocks from node1")
189188
self.sync_all()

test/functional/feature_abortnode.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"""
1212

1313
from test_framework.test_framework import BitcoinTestFramework
14-
from test_framework.util import get_datadir_path, connect_nodes
14+
from test_framework.util import get_datadir_path
1515
import os
1616

1717

@@ -36,7 +36,7 @@ def run_test(self):
3636
# attempt.
3737
self.nodes[1].generate(3)
3838
with self.nodes[0].assert_debug_log(["Failed to disconnect block"]):
39-
connect_nodes(self.nodes[0], 1)
39+
self.connect_nodes(0, 1)
4040
self.nodes[1].generate(1)
4141

4242
# Check that node0 aborted

test/functional/feature_fee_estimation.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
assert_equal,
1414
assert_greater_than,
1515
assert_greater_than_or_equal,
16-
connect_nodes,
1716
satoshi_round,
1817
)
1918

@@ -232,9 +231,9 @@ def run_test(self):
232231
# so the estimates would not be affected by the splitting transactions
233232
self.start_node(1)
234233
self.start_node(2)
235-
connect_nodes(self.nodes[1], 0)
236-
connect_nodes(self.nodes[0], 2)
237-
connect_nodes(self.nodes[2], 1)
234+
self.connect_nodes(1, 0)
235+
self.connect_nodes(0, 2)
236+
self.connect_nodes(2, 1)
238237

239238
self.sync_all()
240239

test/functional/feature_minchainwork.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import time
1919

2020
from test_framework.test_framework import BitcoinTestFramework
21-
from test_framework.util import connect_nodes, assert_equal
21+
from test_framework.util import assert_equal
2222

2323
# 2 hashes required per regtest block (with no difficulty adjustment)
2424
REGTEST_WORK_PER_BLOCK = 2
@@ -39,7 +39,7 @@ def setup_network(self):
3939
# block relay to inbound peers.
4040
self.setup_nodes()
4141
for i in range(self.num_nodes-1):
42-
connect_nodes(self.nodes[i+1], i)
42+
self.connect_nodes(i+1, i)
4343

4444
def run_test(self):
4545
# Start building a chain on node0. node2 shouldn't be able to sync until node1's

test/functional/feature_notifications.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
from test_framework.test_framework import BitcoinTestFramework
1010
from test_framework.util import (
1111
assert_equal,
12-
connect_nodes,
13-
disconnect_nodes,
1412
hex_str_to_bytes,
1513
)
1614

@@ -75,7 +73,7 @@ def run_test(self):
7573
self.log.info("test -walletnotify after rescan")
7674
# restart node to rescan to force wallet notifications
7775
self.start_node(1)
78-
connect_nodes(self.nodes[0], 1)
76+
self.connect_nodes(0, 1)
7977

8078
self.wait_until(lambda: len(os.listdir(self.walletnotify_dir)) == block_count, timeout=10)
8179

@@ -126,12 +124,12 @@ def run_test(self):
126124
# Bump tx2 as bump2 and generate a block on node 0 while
127125
# disconnected, then reconnect and check for notifications on node 1
128126
# about newly confirmed bump2 and newly conflicted tx2.
129-
disconnect_nodes(self.nodes[0], 1)
127+
self.disconnect_nodes(0, 1)
130128
bump2 = self.nodes[0].bumpfee(tx2)["txid"]
131129
self.nodes[0].generatetoaddress(1, ADDRESS_BCRT1_UNSPENDABLE)
132130
assert_equal(self.nodes[0].gettransaction(bump2)["confirmations"], 1)
133131
assert_equal(tx2 in self.nodes[1].getrawmempool(), True)
134-
connect_nodes(self.nodes[0], 1)
132+
self.connect_nodes(0, 1)
135133
self.sync_blocks()
136134
self.expect_wallet_notify([bump2, tx2])
137135
assert_equal(self.nodes[1].gettransaction(bump2)["confirmations"], 1)

test/functional/feature_pruning.py

+14-16
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
assert_equal,
1919
assert_greater_than,
2020
assert_raises_rpc_error,
21-
connect_nodes,
22-
disconnect_nodes,
2321
)
2422

2523
# Rescans start at the earliest block up to 2 hours before a key timestamp, so
@@ -102,11 +100,11 @@ def setup_network(self):
102100

103101
self.prunedir = os.path.join(self.nodes[2].datadir, self.chain, 'blocks', '')
104102

105-
connect_nodes(self.nodes[0], 1)
106-
connect_nodes(self.nodes[1], 2)
107-
connect_nodes(self.nodes[0], 2)
108-
connect_nodes(self.nodes[0], 3)
109-
connect_nodes(self.nodes[0], 4)
103+
self.connect_nodes(0, 1)
104+
self.connect_nodes(1, 2)
105+
self.connect_nodes(0, 2)
106+
self.connect_nodes(0, 3)
107+
self.connect_nodes(0, 4)
110108
self.sync_blocks(self.nodes[0:5])
111109

112110
def setup_nodes(self):
@@ -148,17 +146,17 @@ def create_chain_with_staleblocks(self):
148146
for _ in range(12):
149147
# Disconnect node 0 so it can mine a longer reorg chain without knowing about node 1's soon-to-be-stale chain
150148
# Node 2 stays connected, so it hears about the stale blocks and then reorg's when node0 reconnects
151-
disconnect_nodes(self.nodes[0], 1)
152-
disconnect_nodes(self.nodes[0], 2)
149+
self.disconnect_nodes(0, 1)
150+
self.disconnect_nodes(0, 2)
153151
# Mine 24 blocks in node 1
154152
mine_large_blocks(self.nodes[1], 24)
155153

156154
# Reorg back with 25 block chain from node 0
157155
mine_large_blocks(self.nodes[0], 25)
158156

159157
# Create connections in the order so both nodes can see the reorg at the same time
160-
connect_nodes(self.nodes[0], 1)
161-
connect_nodes(self.nodes[0], 2)
158+
self.connect_nodes(0, 1)
159+
self.connect_nodes(0, 2)
162160
self.sync_blocks(self.nodes[0:3])
163161

164162
self.log.info("Usage can be over target because of high stale rate: %d" % calc_usage(self.prunedir))
@@ -187,15 +185,15 @@ def reorg_test(self):
187185
self.log.info("New best height: %d" % self.nodes[1].getblockcount())
188186

189187
# Disconnect node1 and generate the new chain
190-
disconnect_nodes(self.nodes[0], 1)
191-
disconnect_nodes(self.nodes[1], 2)
188+
self.disconnect_nodes(0, 1)
189+
self.disconnect_nodes(1, 2)
192190

193191
self.log.info("Generating new longer chain of 300 more blocks")
194192
self.nodes[1].generate(300)
195193

196194
self.log.info("Reconnect nodes")
197-
connect_nodes(self.nodes[0], 1)
198-
connect_nodes(self.nodes[1], 2)
195+
self.connect_nodes(0, 1)
196+
self.connect_nodes(1, 2)
199197
self.sync_blocks(self.nodes[0:3], timeout=120)
200198

201199
self.log.info("Verify height on node 2: %d" % self.nodes[2].getblockcount())
@@ -336,7 +334,7 @@ def wallet_test(self):
336334
# check that wallet loads successfully when restarting a pruned node after IBD.
337335
# this was reported to fail in #7494.
338336
self.log.info("Syncing node 5 to test wallet")
339-
connect_nodes(self.nodes[0], 5)
337+
self.connect_nodes(0, 5)
340338
nds = [self.nodes[0], self.nodes[5]]
341339
self.sync_blocks(nds, wait=5, timeout=300)
342340
self.restart_node(5, extra_args=["-prune=550"]) # restart to trigger rescan

test/functional/feature_segwit.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
assert_equal,
2323
assert_is_hex_string,
2424
assert_raises_rpc_error,
25-
connect_nodes,
2625
hex_str_to_bytes,
2726
try_rpc,
2827
)
@@ -78,7 +77,7 @@ def skip_test_if_missing_module(self):
7877

7978
def setup_network(self):
8079
super().setup_network()
81-
connect_nodes(self.nodes[0], 2)
80+
self.connect_nodes(0, 2)
8281
self.sync_all()
8382

8483
def success_mine(self, node, txid, sign, redeem_script=""):

test/functional/interface_zmq.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from test_framework.messages import CTransaction, hash256, FromHex
1212
from test_framework.util import (
1313
assert_equal,
14-
connect_nodes,
1514
assert_raises_rpc_error,
1615
)
1716
from io import BytesIO
@@ -102,7 +101,7 @@ def test_basic(self):
102101
rawtx = subs[3]
103102

104103
self.restart_node(0, ["-zmqpub%s=%s" % (sub.topic.decode(), address) for sub in [hashblock, hashtx, rawblock, rawtx]])
105-
connect_nodes(self.nodes[0], 1)
104+
self.connect_nodes(0, 1)
106105
for socket in sockets:
107106
socket.connect(address)
108107

@@ -207,7 +206,7 @@ def test_reorg(self):
207206
connect_blocks = self.nodes[1].generatetoaddress(2, ADDRESS_BCRT1_P2WSH_OP_TRUE)
208207

209208
# nodes[0] will reorg chain after connecting back nodes[1]
210-
connect_nodes(self.nodes[0], 1)
209+
self.connect_nodes(0, 1)
211210
self.sync_blocks() # tx in mempool valid but not advertised
212211

213212
# Should receive nodes[1] tip
@@ -264,7 +263,7 @@ def test_sequence(self):
264263
self.nodes[1].generatetoaddress(2, ADDRESS_BCRT1_P2WSH_OP_TRUE)
265264

266265
# nodes[0] will reorg chain after connecting back nodes[1]
267-
connect_nodes(self.nodes[0], 1)
266+
self.connect_nodes(0, 1)
268267

269268
# Then we receive all block (dis)connect notifications for the 2 block reorg
270269
assert_equal((dc_block, "D", None), seq.receive_sequence())
@@ -406,7 +405,7 @@ def test_mempool_sync(self):
406405
seq = ZMQSubscriber(socket, b'sequence')
407406

408407
self.restart_node(0, ['-zmqpub%s=%s' % (seq.topic.decode(), address)])
409-
connect_nodes(self.nodes[0], 1)
408+
self.connect_nodes(0, 1)
410409
socket.connect(address)
411410
# Relax so that the subscriber is ready before publishing zmq messages
412411
sleep(0.2)

test/functional/mempool_persist.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
assert_equal,
4646
assert_greater_than_or_equal,
4747
assert_raises_rpc_error,
48-
connect_nodes,
49-
disconnect_nodes,
5048
)
5149

5250

@@ -83,11 +81,11 @@ def run_test(self):
8381
assert_greater_than_or_equal(tx_creation_time_higher, tx_creation_time)
8482

8583
# disconnect nodes & make a txn that remains in the unbroadcast set.
86-
disconnect_nodes(self.nodes[0], 1)
84+
self.disconnect_nodes(0, 1)
8785
assert(len(self.nodes[0].getpeerinfo()) == 0)
8886
assert(len(self.nodes[0].p2ps) == 0)
8987
self.nodes[0].sendtoaddress(self.nodes[2].getnewaddress(), Decimal("12"))
90-
connect_nodes(self.nodes[0], 2)
88+
self.connect_nodes(0, 2)
9189

9290
self.log.debug("Stop-start the nodes. Verify that node0 has the transactions in its mempool and node1 does not. Verify that node2 calculates its balance correctly after loading wallet transactions.")
9391
self.stop_nodes()

test/functional/mining_basic.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from test_framework.util import (
2626
assert_equal,
2727
assert_raises_rpc_error,
28-
connect_nodes,
2928
)
3029

3130

@@ -56,7 +55,7 @@ def mine_chain(self):
5655
assert_equal(mining_info['currentblocktx'], 0)
5756
assert_equal(mining_info['currentblockweight'], 4000)
5857
self.restart_node(0)
59-
connect_nodes(self.nodes[0], 1)
58+
self.connect_nodes(0, 1)
6059

6160
def run_test(self):
6261
self.mine_chain()

test/functional/p2p_blockfilters.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
from test_framework.test_framework import BitcoinTestFramework
2323
from test_framework.util import (
2424
assert_equal,
25-
connect_nodes,
26-
disconnect_nodes,
2725
)
2826

2927
class CFiltersClient(P2PInterface):
@@ -61,7 +59,7 @@ def run_test(self):
6159
self.sync_blocks(timeout=600)
6260

6361
# Stale blocks by disconnecting nodes 0 & 1, mining, then reconnecting
64-
disconnect_nodes(self.nodes[0], 1)
62+
self.disconnect_nodes(0, 1)
6563

6664
self.nodes[0].generate(1)
6765
self.wait_until(lambda: self.nodes[0].getblockcount() == 1000)
@@ -90,7 +88,7 @@ def run_test(self):
9088
assert_equal(len(response.headers), 1)
9189

9290
self.log.info("Reorg node 0 to a new chain.")
93-
connect_nodes(self.nodes[0], 1)
91+
self.connect_nodes(0, 1)
9492
self.sync_blocks(timeout=600)
9593

9694
main_block_hash = self.nodes[0].getblockhash(1000)

test/functional/p2p_disconnect_ban.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from test_framework.util import (
1010
assert_equal,
1111
assert_raises_rpc_error,
12-
connect_nodes,
1312
)
1413

1514
class DisconnectBanTest(BitcoinTestFramework):
@@ -19,8 +18,8 @@ def set_test_params(self):
1918

2019
def run_test(self):
2120
self.log.info("Connect nodes both way")
22-
connect_nodes(self.nodes[0], 1)
23-
connect_nodes(self.nodes[1], 0)
21+
self.connect_nodes(0, 1)
22+
self.connect_nodes(1, 0)
2423

2524
self.log.info("Test setban and listbanned RPCs")
2625

@@ -78,8 +77,8 @@ def run_test(self):
7877
# Clear ban lists
7978
self.nodes[1].clearbanned()
8079
self.log.info("Connect nodes both way")
81-
connect_nodes(self.nodes[0], 1)
82-
connect_nodes(self.nodes[1], 0)
80+
self.connect_nodes(0, 1)
81+
self.connect_nodes(1, 0)
8382

8483
self.log.info("Test disconnectnode RPCs")
8584

@@ -98,7 +97,7 @@ def run_test(self):
9897
assert not [node for node in self.nodes[0].getpeerinfo() if node['addr'] == address1]
9998

10099
self.log.info("disconnectnode: successfully reconnect node")
101-
connect_nodes(self.nodes[0], 1) # reconnect the node
100+
self.connect_nodes(0, 1) # reconnect the node
102101
assert_equal(len(self.nodes[0].getpeerinfo()), 2)
103102
assert [node for node in self.nodes[0].getpeerinfo() if node['addr'] == address1]
104103

0 commit comments

Comments
 (0)