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

+3-3
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

+4-5
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

+1
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

+1-1
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

+4-7
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

-1
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

+3-2
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

+1-1
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

+3-10
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

+2-2
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:

test/functional/import-rescan.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ def setup_network(self):
121121
if import_node.prune:
122122
extra_args[i] += ["-prune=1"]
123123

124-
self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir, extra_args)
124+
self.add_nodes(self.num_nodes, self.options.tmpdir, extra_args)
125+
self.start_nodes()
125126
for i in range(1, self.num_nodes):
126127
connect_nodes(self.nodes[i], 0)
127128

test/functional/importmulti.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ def run_test (self):
429429

430430
# restart nodes to check for proper serialization/deserialization of watch only address
431431
self.stop_nodes()
432-
self.nodes = self.start_nodes(2, self.options.tmpdir)
432+
self.start_nodes()
433433
address_assert = self.nodes[1].validateaddress(watchonly_address)
434434
assert_equal(address_assert['iswatchonly'], True)
435435
assert_equal(address_assert['ismine'], False)

test/functional/keypool-topup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def run_test(self):
3535
self.stop_node(1)
3636

3737
shutil.copyfile(self.tmpdir + "/node1/regtest/wallet.dat", self.tmpdir + "/wallet.bak")
38-
self.nodes[1] = self.start_node(1, self.tmpdir, self.extra_args[1])
38+
self.start_node(1, self.extra_args[1])
3939
connect_nodes_bi(self.nodes, 0, 1)
4040

4141
self.log.info("Generate keys for wallet")
@@ -61,7 +61,7 @@ def run_test(self):
6161

6262
self.log.info("Verify keypool is restored and balance is correct")
6363

64-
self.nodes[1] = self.start_node(1, self.tmpdir, self.extra_args[1])
64+
self.start_node(1, self.extra_args[1])
6565
connect_nodes_bi(self.nodes, 0, 1)
6666
self.sync_all()
6767

test/functional/keypool.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def run_test(self):
1919
# Encrypt wallet and wait to terminate
2020
nodes[0].node_encrypt_wallet('test')
2121
# Restart node 0
22-
nodes[0] = self.start_node(0, self.options.tmpdir)
22+
self.start_node(0)
2323
# Keep creating keys
2424
addr = nodes[0].getnewaddress()
2525
addr_data = nodes[0].validateaddress(addr)

test/functional/listtransactions.py

-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ def __init__(self):
2020
super().__init__()
2121
self.num_nodes = 4
2222
self.setup_clean_chain = False
23-
24-
def setup_nodes(self):
25-
#This test requires mocktime
2623
self.enable_mocktime()
27-
self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir)
2824

2925
def run_test(self):
3026
# Simple send, 0 to 1:

test/functional/maxuploadtarget.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def run_test(self):
147147
#stop and start node 0 with 1MB maxuploadtarget, whitelist 127.0.0.1
148148
self.log.info("Restarting nodes with -whitelist=127.0.0.1")
149149
self.stop_node(0)
150-
self.nodes[0] = self.start_node(0, self.options.tmpdir, ["-whitelist=127.0.0.1", "-maxuploadtarget=1", "-blockmaxsize=999000"])
150+
self.start_node(0, ["-whitelist=127.0.0.1", "-maxuploadtarget=1", "-blockmaxsize=999000"])
151151

152152
#recreate/reconnect a test node
153153
test_nodes = [TestNode()]

test/functional/mempool_persist.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -63,26 +63,23 @@ def run_test(self):
6363

6464
self.log.debug("Stop-start node0 and node1. Verify that node0 has the transactions in its mempool and node1 does not.")
6565
self.stop_nodes()
66-
self.nodes = []
67-
self.nodes.append(self.start_node(0, self.options.tmpdir))
68-
self.nodes.append(self.start_node(1, self.options.tmpdir))
66+
self.start_node(0)
67+
self.start_node(1)
6968
# Give bitcoind a second to reload the mempool
7069
time.sleep(1)
7170
wait_until(lambda: len(self.nodes[0].getrawmempool()) == 5)
7271
assert_equal(len(self.nodes[1].getrawmempool()), 0)
7372

7473
self.log.debug("Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file.")
7574
self.stop_nodes()
76-
self.nodes = []
77-
self.nodes.append(self.start_node(0, self.options.tmpdir, ["-persistmempool=0"]))
75+
self.start_node(0, extra_args=["-persistmempool=0"])
7876
# Give bitcoind a second to reload the mempool
7977
time.sleep(1)
8078
assert_equal(len(self.nodes[0].getrawmempool()), 0)
8179

8280
self.log.debug("Stop-start node0. Verify that it has the transactions in its mempool.")
8381
self.stop_nodes()
84-
self.nodes = []
85-
self.nodes.append(self.start_node(0, self.options.tmpdir))
82+
self.start_node(0)
8683
wait_until(lambda: len(self.nodes[0].getrawmempool()) == 5)
8784

8885
if __name__ == '__main__':

test/functional/multiwallet.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ def run_test(self):
2323
self.stop_node(0)
2424

2525
# should not initialize if there are duplicate wallets
26-
self.assert_start_raises_init_error(0, self.options.tmpdir, ['-wallet=w1', '-wallet=w1'], 'Error loading wallet w1. Duplicate -wallet filename specified.')
26+
self.assert_start_raises_init_error(0, ['-wallet=w1', '-wallet=w1'], 'Error loading wallet w1. Duplicate -wallet filename specified.')
2727

2828
# should not initialize if wallet file is a directory
2929
os.mkdir(os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w11'))
30-
self.assert_start_raises_init_error(0, self.options.tmpdir, ['-wallet=w11'], 'Error loading wallet w11. -wallet filename must be a regular file.')
30+
self.assert_start_raises_init_error(0, ['-wallet=w11'], 'Error loading wallet w11. -wallet filename must be a regular file.')
3131

3232
# should not initialize if wallet file is a symlink
3333
os.symlink(os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w1'), os.path.join(self.options.tmpdir, 'node0', 'regtest', 'w12'))
34-
self.assert_start_raises_init_error(0, self.options.tmpdir, ['-wallet=w12'], 'Error loading wallet w12. -wallet filename must be a regular file.')
34+
self.assert_start_raises_init_error(0, ['-wallet=w12'], 'Error loading wallet w12. -wallet filename must be a regular file.')
3535

36-
self.nodes[0] = self.start_node(0, self.options.tmpdir, self.extra_args[0])
36+
self.start_node(0, self.extra_args[0])
3737

3838
w1 = self.nodes[0].get_wallet_rpc("w1")
3939
w2 = self.nodes[0].get_wallet_rpc("w2")

test/functional/p2p-segwit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ def test_upgrade_after_activation(self, node_id):
14961496

14971497
# Restart with the new binary
14981498
self.stop_node(node_id)
1499-
self.nodes[node_id] = self.start_node(node_id, self.options.tmpdir)
1499+
self.start_node(node_id, extra_args=[])
15001500
connect_nodes(self.nodes[0], node_id)
15011501

15021502
sync_blocks(self.nodes)

test/functional/p2p-versionbits-warning.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def run_test(self):
112112
# Empty out the alert file
113113
with open(self.alert_filename, 'w', encoding='utf8') as _:
114114
pass
115-
self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir, self.extra_args)
115+
self.start_nodes()
116116

117117
# Connecting one block should be enough to generate an error.
118118
self.nodes[0].generate(1)
@@ -123,7 +123,7 @@ def run_test(self):
123123
self.test_versionbits_in_alert_file()
124124

125125
# Test framework expects the node to still be running...
126-
self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir, self.extra_args)
126+
self.start_nodes()
127127

128128
if __name__ == '__main__':
129129
VersionBitsWarningTest().main()

test/functional/proxy_test.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ def setup_nodes(self):
8989
]
9090
if self.have_ipv6:
9191
args[3] = ['-listen', '-proxy=[%s]:%i' % (self.conf3.addr),'-proxyrandomize=0', '-noonion']
92-
self.nodes = self.start_nodes(self.num_nodes, self.options.tmpdir, extra_args=args)
92+
self.add_nodes(self.num_nodes, self.options.tmpdir, extra_args=args)
93+
self.start_nodes()
9394

9495
def node_test(self, node, proxies, auth, test_onion=True):
9596
rv = []

0 commit comments

Comments
 (0)