Skip to content

Commit 28f788e

Browse files
author
MarcoFalke
committed
Merge #11121: TestNode tidyups
7148b74 [tests] Functional tests must explicitly set num_nodes (John Newbery) 5448a14 [tests] don't override __init__() in individual tests (John Newbery) 6cf094a [tests] Avoid passing around member variables in test_framework (John Newbery) 36b6268 [tests] TestNode: separate add_node from start_node (John Newbery) be2a2ab [tests] fix - use rpc_timeout as rpc timeout (John Newbery) Pull request description: Some additional tidyups after the introduction of TestNode: - commit 1 makes TestNode use the correct rpc timeout. This should have been included in #11077 - commit 2 separates `add_node()` from `start_node()` as originally discussed here: bitcoin/bitcoin#10556 (comment) with @kallewoof . The test writer no longer needs to assign to `self.nodes` when starting/stopping nodes. - commit 3 adds a `set_test_params()` method, so individual tests don't need to override `__init__()` and call `super().__init__()` Tree-SHA512: 0adb030623b96675b5c29e2890ce99ccd837ed05f721d0c91b35378c5ac01b6658174aac12f1f77402e1d38b61f39b3c43b4df85c96952565dde1cda05b0db84
2 parents d81dccf + 7148b74 commit 28f788e

Some content is hidden

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

83 files changed

+380
-528
lines changed

test/functional/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ don't have test cases for.
2424
- Use a module-level docstring to describe what the test is testing, and how it
2525
is testing it.
2626
- When subclassing the BitcoinTestFramwork, place overrides for the
27-
`__init__()`, and `setup_xxxx()` methods at the top of the subclass, then
28-
locally-defined helper methods, then the `run_test()` method.
27+
`set_test_params()`, `add_options()` and `setup_xxxx()` methods at the top of
28+
the subclass, then locally-defined helper methods, then the `run_test()` method.
2929

3030
#### General test-writing advice
3131

@@ -36,7 +36,7 @@ don't have test cases for.
3636
- Avoid stop-starting the nodes multiple times during the test if possible. A
3737
stop-start takes several seconds, so doing it several times blows up the
3838
runtime of the test.
39-
- Set the `self.setup_clean_chain` variable in `__init__()` to control whether
39+
- Set the `self.setup_clean_chain` variable in `set_test_params()` to control whether
4040
or not to use the cached data directories. The cached data directories
4141
contain a 200-block pre-mined blockchain and wallets for four nodes. Each node
4242
has 25 mature blocks (25x50=1250 BTC) in its wallet.

test/functional/abandonconflict.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
from test_framework.util import *
1515

1616
class AbandonConflictTest(BitcoinTestFramework):
17-
def __init__(self):
18-
super().__init__()
17+
def set_test_params(self):
1918
self.num_nodes = 2
20-
self.setup_clean_chain = False
2119
self.extra_args = [["-minrelaytxfee=0.00001"], []]
2220

2321
def run_test(self):
@@ -74,7 +72,7 @@ def run_test(self):
7472
# Restart the node with a higher min relay fee so the parent tx is no longer in mempool
7573
# TODO: redo with eviction
7674
self.stop_node(0)
77-
self.nodes[0] = self.start_node(0, self.options.tmpdir, ["-minrelaytxfee=0.0001"])
75+
self.start_node(0, extra_args=["-minrelaytxfee=0.0001"])
7876

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

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

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

122120
# Remove using high relay fee again
123121
self.stop_node(0)
124-
self.nodes[0] = self.start_node(0, self.options.tmpdir, ["-minrelaytxfee=0.0001"])
122+
self.start_node(0, extra_args=["-minrelaytxfee=0.0001"])
125123
assert_equal(len(self.nodes[0].getrawmempool()), 0)
126124
newbalance = self.nodes[0].getbalance()
127125
assert_equal(newbalance, balance - Decimal("24.9996"))

test/functional/assumevalid.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,16 @@ def send_header_for_blocks(self, new_blocks):
5454
self.send_message(headers_message)
5555

5656
class AssumeValidTest(BitcoinTestFramework):
57-
def __init__(self):
58-
super().__init__()
57+
def set_test_params(self):
5958
self.setup_clean_chain = True
6059
self.num_nodes = 3
6160

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

6868
def send_blocks_until_disconnected(self, node):
6969
"""Keep sending blocks to the node until we're disconnected."""
@@ -162,15 +162,13 @@ def run_test(self):
162162
height += 1
163163

164164
# 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)]))
165+
self.start_node(1, extra_args=["-assumevalid=" + hex(block102.sha256)])
167166
node1 = BaseNode() # connects to node1
168167
connections.append(NodeConn('127.0.0.1', p2p_port(1), self.nodes[1], node1))
169168
node1.add_connection(connections[1])
170169
node1.wait_for_verack()
171170

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

test/functional/bip65-cltv-p2p.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ def create_transaction(node, coinbase, to_address, amount):
6060
return tx
6161

6262
class BIP65Test(BitcoinTestFramework):
63-
64-
def __init__(self):
65-
super().__init__()
63+
def set_test_params(self):
6664
self.num_nodes = 1
6765
self.extra_args = [['-promiscuousmempoolflags=1', '-whitelist=127.0.0.1']]
6866
self.setup_clean_chain = True

test/functional/bip68-112-113-p2p.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ def all_rlt_txs(txarray):
9292
return txs
9393

9494
class BIP68_112_113Test(ComparisonTestFramework):
95-
def __init__(self):
96-
super().__init__()
95+
def set_test_params(self):
9796
self.num_nodes = 1
97+
self.setup_clean_chain = True
9898
self.extra_args = [['-whitelist=127.0.0.1', '-blockversion=4']]
9999

100100
def run_test(self):

test/functional/bip68-sequence.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
NOT_FINAL_ERROR = "64: non-BIP68-final"
1818

1919
class BIP68Test(BitcoinTestFramework):
20-
def __init__(self):
21-
super().__init__()
20+
def set_test_params(self):
2221
self.num_nodes = 2
23-
self.setup_clean_chain = False
2422
self.extra_args = [[], ["-acceptnonstdtxn=0"]]
2523

2624
def run_test(self):

test/functional/bip9-softforks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@
2828
from test_framework.script import CScript, OP_1NEGATE, OP_CHECKSEQUENCEVERIFY, OP_DROP
2929

3030
class BIP9SoftForksTest(ComparisonTestFramework):
31-
32-
def __init__(self):
33-
super().__init__()
31+
def set_test_params(self):
3432
self.num_nodes = 1
3533
self.extra_args = [['-whitelist=127.0.0.1']]
34+
self.setup_clean_chain = True
3635

3736
def run_test(self):
3837
self.test = TestManager(self, self.options.tmpdir)
@@ -241,6 +240,7 @@ def test_BIP(self, bipName, activated_version, invalidate, invalidatePostSignatu
241240
# Restart all
242241
self.test.clear_all_connections()
243242
self.stop_nodes()
243+
self.nodes = []
244244
shutil.rmtree(self.options.tmpdir + "/node0")
245245
self.setup_chain()
246246
self.setup_network()

test/functional/bipdersig-p2p.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ def create_transaction(node, coinbase, to_address, amount):
4848
return tx
4949

5050
class BIP66Test(BitcoinTestFramework):
51-
52-
def __init__(self):
53-
super().__init__()
51+
def set_test_params(self):
5452
self.num_nodes = 1
5553
self.extra_args = [['-promiscuousmempoolflags=1', '-whitelist=127.0.0.1']]
5654
self.setup_clean_chain = True

test/functional/blockchain.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,8 @@
3030
assert_is_hash_string,
3131
)
3232

33-
3433
class BlockchainTest(BitcoinTestFramework):
35-
36-
def __init__(self):
37-
super().__init__()
38-
self.setup_clean_chain = False
34+
def set_test_params(self):
3935
self.num_nodes = 1
4036
self.extra_args = [['-stopatheight=207']]
4137

@@ -146,7 +142,7 @@ def _test_stopatheight(self):
146142
pass # The node already shut down before response
147143
self.log.debug('Node should stop at this height...')
148144
self.nodes[0].process.wait(timeout=BITCOIND_PROC_WAIT_TIMEOUT)
149-
self.nodes[0] = self.start_node(0, self.options.tmpdir)
145+
self.start_node(0)
150146
assert_equal(self.nodes[0].getblockcount(), 207)
151147

152148

test/functional/bumpfee.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,21 @@
3030

3131

3232
class BumpFeeTest(BitcoinTestFramework):
33-
def __init__(self):
34-
super().__init__()
33+
def set_test_params(self):
3534
self.num_nodes = 2
3635
self.setup_clean_chain = True
36+
self.extra_args = [["-prematurewitness", "-walletprematurewitness", "-walletrbf={}".format(i)]
37+
for i in range(self.num_nodes)]
3738

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-
39+
def run_test(self):
4340
# Encrypt wallet for test_locked_wallet_fails test
4441
self.nodes[1].node_encrypt_wallet(WALLET_PASSPHRASE)
45-
self.nodes[1] = self.start_node(1, self.options.tmpdir, extra_args[1])
42+
self.start_node(1)
4643
self.nodes[1].walletpassphrase(WALLET_PASSPHRASE, WALLET_PASSPHRASE_TIMEOUT)
4744

4845
connect_nodes_bi(self.nodes, 0, 1)
4946
self.sync_all()
5047

51-
def run_test(self):
5248
peer_node, rbf_node = self.nodes
5349
rbf_node_address = rbf_node.getnewaddress()
5450

0 commit comments

Comments
 (0)