Skip to content

Commit 7148b74

Browse files
committed
[tests] Functional tests must explicitly set num_nodes
1 parent 5448a14 commit 7148b74

15 files changed

+31
-7
lines changed

test/functional/example_test.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ class ExampleTest(BitcoinTestFramework):
7777
# and setup_nodes() methods to customize the test setup as required.
7878

7979
def set_test_params(self):
80-
"""Override any test parameters for your individual test."""
80+
"""Override test parameters for your individual test.
81+
82+
This method must be overridden and num_nodes must be exlicitly set."""
8183
self.setup_clean_chain = True
8284
self.num_nodes = 3
8385
# Use self.extra_args to change command-line arguments for the nodes

test/functional/fundrawtransaction.py

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def get_unspent(listunspent, amount):
1616

1717
class RawTransactionsTest(BitcoinTestFramework):
1818
def set_test_params(self):
19+
self.num_nodes = 4
1920
self.setup_clean_chain = True
2021

2122
def setup_network(self, split=False):

test/functional/getblocktemplate_longpoll.py

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def run(self):
2323
self.node.getblocktemplate({'longpollid':self.longpollid})
2424

2525
class GetBlockTemplateLPTest(BitcoinTestFramework):
26+
def set_test_params(self):
27+
self.num_nodes = 2
28+
2629
def run_test(self):
2730
self.log.info("Warning: this test will take about 70 seconds in the best case. Be patient.")
2831
self.nodes[0].generate(10)

test/functional/getchaintips.py

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
from test_framework.util import assert_equal
1515

1616
class GetChainTipsTest (BitcoinTestFramework):
17+
def set_test_params(self):
18+
self.num_nodes = 4
19+
1720
def run_test (self):
1821
tips = self.nodes[0].getchaintips ()
1922
assert_equal (len (tips), 1)

test/functional/listsinceblock.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
class ListSinceBlockTest (BitcoinTestFramework):
1111
def set_test_params(self):
12+
self.num_nodes = 4
1213
self.setup_clean_chain = True
1314

1415
def run_test(self):

test/functional/listtransactions.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def txFromHex(hexstring):
1717

1818
class ListTransactionsTest(BitcoinTestFramework):
1919
def set_test_params(self):
20+
self.num_nodes = 2
2021
self.enable_mocktime()
2122

2223
def run_test(self):

test/functional/merkle_blocks.py

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
class MerkleBlockTest(BitcoinTestFramework):
1111
def set_test_params(self):
12+
self.num_nodes = 4
1213
self.setup_clean_chain = True
1314
# Nodes 0/1 are "wallet" nodes, Nodes 2/3 are used for testing
1415
self.extra_args = [[], [], [], ["-txindex"]]

test/functional/p2p-segwit.py

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def get_virtual_size(witness_block):
3434

3535
class TestNode(NodeConnCB):
3636
def set_test_params(self):
37+
self.num_nodes = 3
3738
self.getdataset = set()
3839

3940
def on_getdata(self, conn, message):

test/functional/proxy_test.py

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
RANGE_BEGIN = PORT_MIN + 2 * PORT_RANGE # Start after p2p and rpc ports
4343

4444
class ProxyTest(BitcoinTestFramework):
45+
def set_test_params(self):
46+
self.num_nodes = 4
47+
4548
def setup_nodes(self):
4649
self.have_ipv6 = test_ipv6_local()
4750
# Create two proxies on different ports

test/functional/receivedby.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def get_sub_array_from_array(object_array, to_match):
2424

2525
class ReceivedByTest(BitcoinTestFramework):
2626
def set_test_params(self):
27+
self.num_nodes = 2
2728
self.enable_mocktime()
2829

2930
def run_test(self):

test/functional/test_framework/test_framework.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ class TestStatus(Enum):
4848
class BitcoinTestFramework(object):
4949
"""Base class for a bitcoin test script.
5050
51-
Individual bitcoin test scripts should subclass this class and override the run_test() method.
51+
Individual bitcoin test scripts should subclass this class and override the set_test_params() and run_test() methods.
5252
5353
Individual tests can also override the following methods to customize the test setup:
5454
55-
- set_test_params()
5655
- add_options()
5756
- setup_chain()
5857
- setup_network()
@@ -64,12 +63,13 @@ class BitcoinTestFramework(object):
6463

6564
def __init__(self):
6665
"""Sets test framework defaults. Do not override this method. Instead, override the set_test_params() method"""
67-
self.num_nodes = 4
6866
self.setup_clean_chain = False
6967
self.nodes = []
7068
self.mocktime = 0
7169
self.set_test_params()
7270

71+
assert hasattr(self, "num_nodes"), "Test must set self.num_nodes in set_test_params()"
72+
7373
def main(self):
7474
"""Main function. This should not be overridden by the subclass test scripts."""
7575

@@ -177,8 +177,8 @@ def main(self):
177177

178178
# Methods to override in subclass test scripts.
179179
def set_test_params(self):
180-
"""Override this method to change default values for number of nodes, topology, etc"""
181-
pass
180+
"""Tests must this method to change default values for number of nodes, topology, etc"""
181+
raise NotImplementedError
182182

183183
def add_options(self, parser):
184184
"""Override this method to add command-line options to the test"""
@@ -212,7 +212,7 @@ def setup_nodes(self):
212212
self.start_nodes()
213213

214214
def run_test(self):
215-
"""Override this method to define test logic"""
215+
"""Tests must override this method to define test logic"""
216216
raise NotImplementedError
217217

218218
# Public helper methods. These can be accessed by the subclass test scripts.

test/functional/txn_clone.py

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
from test_framework.util import *
99

1010
class TxnMallTest(BitcoinTestFramework):
11+
def set_test_params(self):
12+
self.num_nodes = 4
13+
1114
def add_options(self, parser):
1215
parser.add_option("--mineblock", dest="mine_block", default=False, action="store_true",
1316
help="Test double-spend of 1-confirmed transaction")

test/functional/txn_doublespend.py

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from test_framework.util import *
99

1010
class TxnMallTest(BitcoinTestFramework):
11+
def set_test_params(self):
12+
self.num_nodes = 4
1113

1214
def add_options(self, parser):
1315
parser.add_option("--mineblock", dest="mine_block", default=False, action="store_true",

test/functional/wallet.py

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
class WalletTest(BitcoinTestFramework):
1010
def set_test_params(self):
11+
self.num_nodes = 4
1112
self.setup_clean_chain = True
1213
self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)]
1314

test/functional/walletbackup.py

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
class WalletBackupTest(BitcoinTestFramework):
4040
def set_test_params(self):
41+
self.num_nodes = 4
4142
self.setup_clean_chain = True
4243
# nodes 1, 2,3 are spenders, let's give them a keypool=100
4344
self.extra_args = [["-keypool=100"], ["-keypool=100"], ["-keypool=100"], []]

0 commit comments

Comments
 (0)