Skip to content

Commit 36b6268

Browse files
committed
[tests] TestNode: separate add_node from start_node
Separates the act of creating a TestNode object from starting the node. The test_framework now keeps track of its list of TestNodes, and test writers can call start_node() and stop_node() without having to update the self.nodes list.
1 parent be2a2ab commit 36b6268

36 files changed

+202
-197
lines changed

test/functional/abandonconflict.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def run_test(self):
7474
# Restart the node with a higher min relay fee so the parent tx is no longer in mempool
7575
# TODO: redo with eviction
7676
self.stop_node(0)
77-
self.nodes[0] = self.start_node(0, self.options.tmpdir, ["-minrelaytxfee=0.0001"])
77+
self.start_node(0, extra_args=["-minrelaytxfee=0.0001"])
7878

7979
# Verify txs no longer in either node's mempool
8080
assert_equal(len(self.nodes[0].getrawmempool()), 0)
@@ -101,7 +101,7 @@ def run_test(self):
101101

102102
# Verify that even with a low min relay fee, the tx is not reaccepted from wallet on startup once abandoned
103103
self.stop_node(0)
104-
self.nodes[0] = self.start_node(0, self.options.tmpdir, ["-minrelaytxfee=0.00001"])
104+
self.start_node(0, extra_args=["-minrelaytxfee=0.00001"])
105105
assert_equal(len(self.nodes[0].getrawmempool()), 0)
106106
assert_equal(self.nodes[0].getbalance(), balance)
107107

@@ -121,7 +121,7 @@ def run_test(self):
121121

122122
# Remove using high relay fee again
123123
self.stop_node(0)
124-
self.nodes[0] = self.start_node(0, self.options.tmpdir, ["-minrelaytxfee=0.0001"])
124+
self.start_node(0, extra_args=["-minrelaytxfee=0.0001"])
125125
assert_equal(len(self.nodes[0].getrawmempool()), 0)
126126
newbalance = self.nodes[0].getbalance()
127127
assert_equal(newbalance, balance - Decimal("24.9996"))

test/functional/assumevalid.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ def __init__(self):
6060
self.num_nodes = 3
6161

6262
def setup_network(self):
63+
self.add_nodes(3, self.options.tmpdir)
6364
# Start node0. We don't start the other nodes yet since
6465
# we need to pre-mine a block with an invalid transaction
6566
# signature so we can pass in the block hash as assumevalid.
66-
self.nodes = [self.start_node(0, self.options.tmpdir)]
67+
self.start_node(0)
6768

6869
def send_blocks_until_disconnected(self, node):
6970
"""Keep sending blocks to the node until we're disconnected."""
@@ -162,15 +163,13 @@ def run_test(self):
162163
height += 1
163164

164165
# Start node1 and node2 with assumevalid so they accept a block with a bad signature.
165-
self.nodes.append(self.start_node(1, self.options.tmpdir,
166-
["-assumevalid=" + hex(block102.sha256)]))
166+
self.start_node(1, extra_args=["-assumevalid=" + hex(block102.sha256)])
167167
node1 = BaseNode() # connects to node1
168168
connections.append(NodeConn('127.0.0.1', p2p_port(1), self.nodes[1], node1))
169169
node1.add_connection(connections[1])
170170
node1.wait_for_verack()
171171

172-
self.nodes.append(self.start_node(2, self.options.tmpdir,
173-
["-assumevalid=" + hex(block102.sha256)]))
172+
self.start_node(2, extra_args=["-assumevalid=" + hex(block102.sha256)])
174173
node2 = BaseNode() # connects to node2
175174
connections.append(NodeConn('127.0.0.1', p2p_port(2), self.nodes[2], node2))
176175
node2.add_connection(connections[2])

test/functional/bip9-softforks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ def test_BIP(self, bipName, activated_version, invalidate, invalidatePostSignatu
241241
# Restart all
242242
self.test.clear_all_connections()
243243
self.stop_nodes()
244+
self.nodes = []
244245
shutil.rmtree(self.options.tmpdir + "/node0")
245246
self.setup_chain()
246247
self.setup_network()

test/functional/blockchain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def _test_stopatheight(self):
146146
pass # The node already shut down before response
147147
self.log.debug('Node should stop at this height...')
148148
self.nodes[0].process.wait(timeout=BITCOIND_PROC_WAIT_TIMEOUT)
149-
self.nodes[0] = self.start_node(0, self.options.tmpdir)
149+
self.start_node(0)
150150
assert_equal(self.nodes[0].getblockcount(), 207)
151151

152152

test/functional/bumpfee.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,18 @@ def __init__(self):
3434
super().__init__()
3535
self.num_nodes = 2
3636
self.setup_clean_chain = True
37+
self.extra_args = [["-prematurewitness", "-walletprematurewitness", "-walletrbf={}".format(i)]
38+
for i in range(self.num_nodes)]
3739

38-
def setup_network(self, split=False):
39-
extra_args = [["-prematurewitness", "-walletprematurewitness", "-walletrbf={}".format(i)]
40-
for i in range(self.num_nodes)]
41-
self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir, extra_args)
42-
40+
def run_test(self):
4341
# Encrypt wallet for test_locked_wallet_fails test
4442
self.nodes[1].node_encrypt_wallet(WALLET_PASSPHRASE)
45-
self.nodes[1] = self.start_node(1, self.options.tmpdir, extra_args[1])
43+
self.start_node(1)
4644
self.nodes[1].walletpassphrase(WALLET_PASSPHRASE, WALLET_PASSPHRASE_TIMEOUT)
4745

4846
connect_nodes_bi(self.nodes, 0, 1)
4947
self.sync_all()
5048

51-
def run_test(self):
5249
peer_node, rbf_node = self.nodes
5350
rbf_node_address = rbf_node.getnewaddress()
5451

test/functional/create_cache.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def __init__(self):
1818

1919
# Test network and test nodes are not required:
2020
self.num_nodes = 0
21-
self.nodes = []
2221

2322
def setup_network(self):
2423
pass

test/functional/dbcrash.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ def __init__(self):
6565

6666
def setup_network(self):
6767
# Need a bit of extra time for the nodes to start up for this test
68-
self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir, self.extra_args, timewait=90)
68+
self.add_nodes(self.num_nodes, self.options.tmpdir, self.extra_args, timewait=90)
69+
self.start_nodes()
6970
# Leave them unconnected, we'll use submitblock directly in this test
7071

7172
def restart_node(self, node_index, expected_tip):
@@ -78,7 +79,7 @@ def restart_node(self, node_index, expected_tip):
7879
while time.time() - time_start < 120:
7980
try:
8081
# Any of these RPC calls could throw due to node crash
81-
self.nodes[node_index] = self.start_node(node_index, self.options.tmpdir, self.extra_args[node_index], timewait=90)
82+
self.start_node(node_index)
8283
self.nodes[node_index].waitforblock(expected_tip)
8384
utxo_hash = self.nodes[node_index].gettxoutsetinfo()['hash_serialized_2']
8485
return utxo_hash

test/functional/disconnect_ban.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ def run_test(self):
6868
assert_equal(len(self.nodes[1].listbanned()), 3)
6969

7070
self.stop_node(1)
71+
self.start_node(1)
7172

72-
self.nodes[1] = self.start_node(1, self.options.tmpdir)
7373
listAfterShutdown = self.nodes[1].listbanned()
7474
assert_equal("127.0.0.0/24", listAfterShutdown[0]['address'])
7575
assert_equal("127.0.0.0/32", listAfterShutdown[1]['address'])

test/functional/forknotify.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import time
88

99
from test_framework.test_framework import BitcoinTestFramework
10-
from test_framework.util import *
1110

1211
class ForkNotifyTest(BitcoinTestFramework):
1312

@@ -17,18 +16,12 @@ def __init__(self):
1716
self.setup_clean_chain = False
1817

1918
def setup_network(self):
20-
self.nodes = []
2119
self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")
2220
with open(self.alert_filename, 'w', encoding='utf8'):
2321
pass # Just open then close to create zero-length file
24-
self.nodes.append(self.start_node(0, self.options.tmpdir,
25-
["-blockversion=2", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""]))
26-
# Node1 mines block.version=211 blocks
27-
self.nodes.append(self.start_node(1, self.options.tmpdir,
28-
["-blockversion=211"]))
29-
connect_nodes(self.nodes[1], 0)
30-
31-
self.sync_all()
22+
self.extra_args = [["-blockversion=2", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""],
23+
["-blockversion=211"]]
24+
super().setup_network()
3225

3326
def run_test(self):
3427
# Mine 51 up-version blocks

test/functional/fundrawtransaction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,11 +449,11 @@ def run_test(self):
449449
############################################################
450450
# locked wallet test
451451
self.stop_node(0)
452+
self.nodes[1].node_encrypt_wallet("test")
452453
self.stop_node(2)
453454
self.stop_node(3)
454-
self.nodes[1].node_encrypt_wallet("test")
455455

456-
self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir)
456+
self.start_nodes()
457457
# This test is not meant to test fee estimation and we'd like
458458
# to be sure all txs are sent at a consistent desired feerate
459459
for node in self.nodes:

0 commit comments

Comments
 (0)