Skip to content

Commit e8bf39f

Browse files
kwvgUdjinM6
andcommitted
merge bitcoin#19967: Replace (dis)?connect_nodes globals with TestFramework methods
Co-authored-by: UdjinM6 <[email protected]>
1 parent c4ec55f commit e8bf39f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+275
-313
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
wait_until,
3029
)
3130

@@ -116,7 +115,7 @@ def setup_network(self):
116115
# In this test, we're not connecting node2 to node0 or node1. Calls to
117116
# sync_all() should not include node2, since we're not expecting it to
118117
# sync.
119-
connect_nodes(self.nodes[0], 1)
118+
self.connect_nodes(0, 1)
120119
self.sync_all(self.nodes[0:2])
121120

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

186185
self.log.info("Connect node2 and node1")
187-
connect_nodes(self.nodes[1], 2)
186+
self.connect_nodes(1, 2)
188187

189188
self.log.info("Wait for node2 to receive all the blocks from node1")
190189
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 wait_until, get_datadir_path, connect_nodes
14+
from test_framework.util import wait_until, get_datadir_path
1515
import os
1616

1717
class AbortNodeTest(BitcoinTestFramework):
@@ -35,7 +35,7 @@ def run_test(self):
3535
# attempt.
3636
self.nodes[1].generate(3)
3737
with self.nodes[0].assert_debug_log(["Failed to disconnect block"]):
38-
connect_nodes(self.nodes[0], 1)
38+
self.connect_nodes(0, 1)
3939
self.nodes[1].generate(1)
4040

4141
# Check that node0 aborted

test/functional/feature_addressindex.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from test_framework.test_framework import BitcoinTestFramework
1414
from test_framework.test_node import ErrorMatch
1515
from test_framework.script import CScript, OP_CHECKSIG, OP_DUP, OP_EQUAL, OP_EQUALVERIFY, OP_HASH160
16-
from test_framework.util import assert_equal, connect_nodes
16+
from test_framework.util import assert_equal
1717

1818
class AddressIndexTest(BitcoinTestFramework):
1919

@@ -33,9 +33,9 @@ def setup_network(self):
3333
# Nodes 2/3 are used for testing
3434
self.start_node(2, ["-addressindex"])
3535
self.start_node(3, ["-addressindex"])
36-
connect_nodes(self.nodes[0], 1)
37-
connect_nodes(self.nodes[0], 2)
38-
connect_nodes(self.nodes[0], 3)
36+
self.connect_nodes(0, 1)
37+
self.connect_nodes(0, 2)
38+
self.connect_nodes(0, 3)
3939
self.sync_all()
4040
self.import_deterministic_coinbase_privkeys()
4141

@@ -44,12 +44,12 @@ def run_test(self):
4444
self.stop_node(1)
4545
self.nodes[1].assert_start_raises_init_error(["-addressindex=0"], "You need to rebuild the database using -reindex to change -addressindex", match=ErrorMatch.PARTIAL_REGEX)
4646
self.start_node(1, ["-addressindex=0", "-reindex"])
47-
connect_nodes(self.nodes[0], 1)
47+
self.connect_nodes(0, 1)
4848
self.sync_all()
4949
self.stop_node(1)
5050
self.nodes[1].assert_start_raises_init_error(["-addressindex"], "You need to rebuild the database using -reindex to change -addressindex", match=ErrorMatch.PARTIAL_REGEX)
5151
self.start_node(1, ["-addressindex", "-reindex"])
52-
connect_nodes(self.nodes[0], 1)
52+
self.connect_nodes(0, 1)
5353
self.sync_all()
5454

5555
self.log.info("Mining blocks...")

test/functional/feature_dip3_deterministicmns.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from test_framework.blocktools import create_block, create_coinbase, get_masternode_payment
1313
from test_framework.messages import CCbTx, COIN, CTransaction, FromHex, ToHex, uint256_to_string
1414
from test_framework.test_framework import BitcoinTestFramework
15-
from test_framework.util import assert_equal, connect_nodes, force_finish_mnsync, get_bip9_status, p2p_port
15+
from test_framework.util import assert_equal, force_finish_mnsync, get_bip9_status, p2p_port
1616

1717
class Masternode(object):
1818
pass
@@ -43,7 +43,7 @@ def start_controller_node(self):
4343
self.start_node(0, extra_args=self.extra_args)
4444
for node in self.nodes[1:]:
4545
if node is not None and node.process is not None:
46-
connect_nodes(node, 0)
46+
self.connect_nodes(node.index, 0)
4747

4848
def run_test(self):
4949
self.log.info("funding controller node")
@@ -269,7 +269,7 @@ def start_mn(self, mn):
269269
self.start_node(mn.idx, extra_args = self.extra_args + ['-masternodeblsprivkey=%s' % mn.blsMnkey])
270270
force_finish_mnsync(self.nodes[mn.idx])
271271
mn.node = self.nodes[mn.idx]
272-
connect_nodes(mn.node, 0)
272+
self.connect_nodes(mn.idx, 0)
273273
self.sync_all()
274274

275275
def spend_mn_collateral(self, mn, with_dummy_input_output=False):

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

@@ -213,9 +212,9 @@ def run_test(self):
213212
# so the estimates would not be affected by the splitting transactions
214213
self.start_node(1)
215214
self.start_node(2)
216-
connect_nodes(self.nodes[1], 0)
217-
connect_nodes(self.nodes[0], 2)
218-
connect_nodes(self.nodes[2], 1)
215+
self.connect_nodes(1, 0)
216+
self.connect_nodes(0, 2)
217+
self.connect_nodes(2, 1)
219218

220219
self.sync_all()
221220

test/functional/feature_llmq_chainlocks.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import time
1414

1515
from test_framework.test_framework import DashTestFramework
16-
from test_framework.util import connect_nodes, force_finish_mnsync, isolate_node, reconnect_isolated_node
16+
from test_framework.util import force_finish_mnsync
1717

1818

1919
class LLMQChainLocksTest(DashTestFramework):
@@ -27,7 +27,7 @@ def run_test(self):
2727
# Usually node0 is the one that does this, but in this test we isolate it multiple times
2828
for i in range(len(self.nodes)):
2929
if i != 1:
30-
connect_nodes(self.nodes[i], 1)
30+
self.connect_nodes(i, 1)
3131

3232
self.activate_dip8()
3333

@@ -53,24 +53,24 @@ def run_test(self):
5353
assert block['chainlock']
5454

5555
self.log.info("Isolate node, mine on another, and reconnect")
56-
isolate_node(self.nodes[0])
56+
self.isolate_node(0)
5757
node0_mining_addr = self.nodes[0].getnewaddress()
5858
node0_tip = self.nodes[0].getbestblockhash()
5959
self.nodes[1].generatetoaddress(5, node0_mining_addr)
6060
self.wait_for_chainlocked_block(self.nodes[1], self.nodes[1].getbestblockhash())
6161
assert self.nodes[0].getbestblockhash() == node0_tip
62-
reconnect_isolated_node(self.nodes[0], 1)
62+
self.reconnect_isolated_node(0, 1)
6363
self.nodes[1].generatetoaddress(1, node0_mining_addr)
6464
self.wait_for_chainlocked_block_all_nodes(self.nodes[1].getbestblockhash())
6565

6666
self.log.info("Isolate node, mine on both parts of the network, and reconnect")
67-
isolate_node(self.nodes[0])
67+
self.isolate_node(0)
6868
bad_tip = self.nodes[0].generate(5)[-1]
6969
self.nodes[1].generatetoaddress(1, node0_mining_addr)
7070
good_tip = self.nodes[1].getbestblockhash()
7171
self.wait_for_chainlocked_block(self.nodes[1], good_tip)
7272
assert not self.nodes[0].getblock(self.nodes[0].getbestblockhash())["chainlock"]
73-
reconnect_isolated_node(self.nodes[0], 1)
73+
self.reconnect_isolated_node(0, 1)
7474
self.nodes[1].generatetoaddress(1, node0_mining_addr)
7575
self.wait_for_chainlocked_block_all_nodes(self.nodes[1].getbestblockhash())
7676
assert self.nodes[0].getblock(self.nodes[0].getbestblockhash())["previousblockhash"] == good_tip
@@ -90,7 +90,7 @@ def run_test(self):
9090
self.log.info("Restart it so that it forgets all the chainlock messages from the past")
9191
self.stop_node(0)
9292
self.start_node(0)
93-
connect_nodes(self.nodes[0], 1)
93+
self.connect_nodes(0, 1)
9494
assert self.nodes[0].getbestblockhash() == good_tip
9595
self.nodes[0].invalidateblock(good_tip)
9696
self.log.info("Now try to reorg the chain")
@@ -129,7 +129,7 @@ def run_test(self):
129129

130130
self.log.info("Isolate a node and let it create some transactions which won't get IS locked")
131131
force_finish_mnsync(self.nodes[0])
132-
isolate_node(self.nodes[0])
132+
self.isolate_node(0)
133133
txs = []
134134
for i in range(3):
135135
txs.append(self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1))
@@ -155,7 +155,7 @@ def run_test(self):
155155
# Enable network on first node again, which will cause the blocks to propagate and IS locks to happen retroactively
156156
# for the mined TXs, which will then allow the network to create a CLSIG
157157
self.log.info("Re-enable network on first node and wait for chainlock")
158-
reconnect_isolated_node(self.nodes[0], 1)
158+
self.reconnect_isolated_node(0, 1)
159159
self.wait_for_chainlocked_block(self.nodes[0], self.nodes[0].getbestblockhash(), timeout=30)
160160

161161
def create_chained_txs(self, node, amount):

test/functional/feature_llmq_connections.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import time
1414

1515
from test_framework.test_framework import DashTestFramework
16-
from test_framework.util import assert_greater_than_or_equal, connect_nodes, Options, wait_until
16+
from test_framework.util import assert_greater_than_or_equal, Options, wait_until
1717

1818
# Probes should age after this many seconds.
1919
# NOTE: mine_quorum() can bump mocktime quite often internally so make sure this number is high enough.
@@ -119,7 +119,7 @@ def check_reconnects(self, expected_connection_count):
119119

120120
# Also re-connect non-masternode connections
121121
for i in range(1, len(self.nodes)):
122-
connect_nodes(self.nodes[i], 0)
122+
self.connect_nodes(i, 0)
123123
self.nodes[i].ping()
124124
# wait for ping/pong so that we can be sure that spork propagation works
125125
time.sleep(1) # needed to make sure we don't check before the ping is actually sent (fPingQueued might be true but SendMessages still not called)

test/functional/feature_llmq_data_recovery.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import time
77
from test_framework.mininode import logger
88
from test_framework.test_framework import DashTestFramework
9-
from test_framework.util import force_finish_mnsync, connect_nodes, wait_until
9+
from test_framework.util import force_finish_mnsync, wait_until
1010

1111
'''
1212
feature_llmq_data_recovery.py
@@ -29,19 +29,19 @@ def set_test_params(self):
2929
self.set_dash_llmq_test_params(4, 3)
3030

3131
def restart_mn(self, mn, reindex=False, qvvec_sync=[], qdata_recovery_enabled=True):
32-
args = self.extra_args[mn.nodeIdx] + ['-masternodeblsprivkey=%s' % mn.keyOperator,
32+
args = self.extra_args[mn.node.index] + ['-masternodeblsprivkey=%s' % mn.keyOperator,
3333
'-llmq-data-recovery=%d' % qdata_recovery_enabled]
3434
for llmq_sync in qvvec_sync:
3535
args.append('-llmq-qvvec-sync=%s:%d' % (llmq_type_strings[llmq_sync[0]], llmq_sync[1]))
3636
if reindex:
3737
args.append('-reindex')
3838
bb_hash = mn.node.getbestblockhash()
39-
self.restart_node(mn.nodeIdx, args)
39+
self.restart_node(mn.node.index, args)
4040
wait_until(lambda: mn.node.getbestblockhash() == bb_hash)
4141
else:
42-
self.restart_node(mn.nodeIdx, args)
42+
self.restart_node(mn.node.index, args)
4343
force_finish_mnsync(mn.node)
44-
connect_nodes(mn.node, 0)
44+
self.connect_nodes(mn.node.index, 0)
4545
if qdata_recovery_enabled:
4646
# trigger recovery threads and wait for them to start
4747
self.nodes[0].generate(1)

test/functional/feature_llmq_is_migration.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from test_framework.messages import CTransaction, FromHex, hash256, ser_compact_size, ser_string
88
from test_framework.test_framework import DashTestFramework
9-
from test_framework.util import wait_until, connect_nodes
9+
from test_framework.util import wait_until
1010

1111
'''
1212
feature_llmq_is_migration.py
@@ -33,7 +33,7 @@ def run_test(self):
3333

3434
for i in range(len(self.nodes)):
3535
if i != 1:
36-
connect_nodes(self.nodes[i], 0)
36+
self.connect_nodes(i, 0)
3737

3838
self.activate_dip8()
3939

test/functional/feature_llmq_is_retroactive.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import time
1717

1818
from test_framework.test_framework import DashTestFramework
19-
from test_framework.util import set_node_times, isolate_node, reconnect_isolated_node
19+
from test_framework.util import set_node_times
2020

2121

2222
class LLMQ_IS_RetroactiveSigning(DashTestFramework):
@@ -69,13 +69,13 @@ def run_test(self):
6969
self.wait_for_chainlocked_block_all_nodes(block)
7070

7171
self.log.info("testing normal signing with partially known TX")
72-
isolate_node(self.nodes[3])
72+
self.isolate_node(3)
7373
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
7474
# Make sure nodes 1 and 2 received the TX before we continue,
7575
# otherwise it might announce the TX to node 3 when reconnecting
7676
self.wait_for_tx(txid, self.nodes[1])
7777
self.wait_for_tx(txid, self.nodes[2])
78-
reconnect_isolated_node(self.nodes[3], 0)
78+
self.reconnect_isolated_node(3, 0)
7979
# Make sure nodes actually try re-connecting quorum connections
8080
self.bump_mocktime(30)
8181
self.wait_for_mnauth(self.nodes[3], 2)
@@ -88,26 +88,26 @@ def run_test(self):
8888
self.wait_for_instantlock(txid, self.nodes[0])
8989

9090
self.log.info("testing retroactive signing with unknown TX")
91-
isolate_node(self.nodes[3])
91+
self.isolate_node(3)
9292
rawtx = self.nodes[0].createrawtransaction([], {self.nodes[0].getnewaddress(): 1})
9393
rawtx = self.nodes[0].fundrawtransaction(rawtx)['hex']
9494
rawtx = self.nodes[0].signrawtransactionwithwallet(rawtx)['hex']
9595
txid = self.nodes[3].sendrawtransaction(rawtx)
9696
# Make node 3 consider the TX as safe
9797
self.bump_mocktime(10 * 60 + 1)
9898
block = self.nodes[3].generatetoaddress(1, self.nodes[0].getnewaddress())[0]
99-
reconnect_isolated_node(self.nodes[3], 0)
99+
self.reconnect_isolated_node(3, 0)
100100
self.wait_for_chainlocked_block_all_nodes(block)
101101
self.nodes[0].setmocktime(self.mocktime)
102102

103103
self.log.info("testing retroactive signing with partially known TX")
104-
isolate_node(self.nodes[3])
104+
self.isolate_node(3)
105105
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1)
106106
# Make sure nodes 1 and 2 received the TX before we continue,
107107
# otherwise it might announce the TX to node 3 when reconnecting
108108
self.wait_for_tx(txid, self.nodes[1])
109109
self.wait_for_tx(txid, self.nodes[2])
110-
reconnect_isolated_node(self.nodes[3], 0)
110+
self.reconnect_isolated_node(3, 0)
111111
# Make sure nodes actually try re-connecting quorum connections
112112
self.bump_mocktime(30)
113113
self.wait_for_mnauth(self.nodes[3], 2)
@@ -136,7 +136,7 @@ def cycle_llmqs(self):
136136

137137
def test_all_nodes_session_timeout(self, do_cycle_llmqs):
138138
set_node_times(self.nodes, self.mocktime)
139-
isolate_node(self.nodes[3])
139+
self.isolate_node(3)
140140
rawtx = self.nodes[0].createrawtransaction([], {self.nodes[0].getnewaddress(): 1})
141141
rawtx = self.nodes[0].fundrawtransaction(rawtx)['hex']
142142
rawtx = self.nodes[0].signrawtransactionwithwallet(rawtx)['hex']
@@ -150,7 +150,7 @@ def test_all_nodes_session_timeout(self, do_cycle_llmqs):
150150
# Make the signing session for the IS lock timeout on nodes 1-3
151151
self.bump_mocktime(61)
152152
time.sleep(2) # make sure Cleanup() is called
153-
reconnect_isolated_node(self.nodes[3], 0)
153+
self.reconnect_isolated_node(3, 0)
154154
# Make sure nodes actually try re-connecting quorum connections
155155
self.bump_mocktime(30)
156156
self.wait_for_mnauth(self.nodes[3], 2)
@@ -167,7 +167,7 @@ def test_all_nodes_session_timeout(self, do_cycle_llmqs):
167167

168168
def test_single_node_session_timeout(self, do_cycle_llmqs):
169169
set_node_times(self.nodes, self.mocktime)
170-
isolate_node(self.nodes[3])
170+
self.isolate_node(3)
171171
rawtx = self.nodes[0].createrawtransaction([], {self.nodes[0].getnewaddress(): 1})
172172
rawtx = self.nodes[0].fundrawtransaction(rawtx)['hex']
173173
rawtx = self.nodes[0].signrawtransactionwithwallet(rawtx)['hex']
@@ -176,7 +176,7 @@ def test_single_node_session_timeout(self, do_cycle_llmqs):
176176
# Make the signing session for the IS lock timeout on node 3
177177
self.bump_mocktime(61)
178178
time.sleep(2) # make sure Cleanup() is called
179-
reconnect_isolated_node(self.nodes[3], 0)
179+
self.reconnect_isolated_node(3, 0)
180180
# Make sure nodes actually try re-connecting quorum connections
181181
self.bump_mocktime(30)
182182
self.wait_for_mnauth(self.nodes[3], 2)

test/functional/feature_llmq_rotation.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from test_framework.util import (
1818
assert_equal,
1919
assert_greater_than_or_equal,
20-
connect_nodes,
2120
wait_until,
2221
)
2322

@@ -67,7 +66,7 @@ def run_test(self):
6766

6867
for i in range(len(self.nodes)):
6968
if i != 1:
70-
connect_nodes(self.nodes[i], 0)
69+
self.connect_nodes(i, 0)
7170

7271
self.activate_dip8()
7372

test/functional/feature_llmq_signing.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from test_framework.messages import CSigShare, msg_qsigshare, uint256_to_string
1414
from test_framework.mininode import P2PInterface
1515
from test_framework.test_framework import DashTestFramework
16-
from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes, force_finish_mnsync, hex_str_to_bytes, wait_until
16+
from test_framework.util import assert_equal, assert_raises_rpc_error, force_finish_mnsync, hex_str_to_bytes, wait_until
1717

1818

1919
class LLMQSigningTest(DashTestFramework):
@@ -184,7 +184,7 @@ def assert_sigs_nochange(hasrecsigs, isconflicting1, isconflicting2, timeout):
184184
assert_sigs_nochange(False, False, False, 3)
185185
# Need to re-connect so that it later gets the recovered sig
186186
mn.node.setnetworkactive(True)
187-
connect_nodes(mn.node, 0)
187+
self.connect_nodes(mn.node.index, 0)
188188
force_finish_mnsync(mn.node)
189189
# Make sure intra-quorum connections were also restored
190190
self.bump_mocktime(1) # need this to bypass quorum connection retry timeout

0 commit comments

Comments
 (0)