From 7148b74dc39110f53c665b94fa9d994c6ad6dc1c Mon Sep 17 00:00:00 2001 From: John Newbery Date: Thu, 24 Aug 2017 11:11:56 -0400 Subject: [PATCH] [tests] Functional tests must explicitly set num_nodes --- test/functional/example_test.py | 4 +++- test/functional/fundrawtransaction.py | 1 + test/functional/getblocktemplate_longpoll.py | 3 +++ test/functional/getchaintips.py | 3 +++ test/functional/listsinceblock.py | 1 + test/functional/listtransactions.py | 1 + test/functional/merkle_blocks.py | 1 + test/functional/p2p-segwit.py | 1 + test/functional/proxy_test.py | 3 +++ test/functional/receivedby.py | 1 + test/functional/test_framework/test_framework.py | 12 ++++++------ test/functional/txn_clone.py | 3 +++ test/functional/txn_doublespend.py | 2 ++ test/functional/wallet.py | 1 + test/functional/walletbackup.py | 1 + 15 files changed, 31 insertions(+), 7 deletions(-) diff --git a/test/functional/example_test.py b/test/functional/example_test.py index 044ef36cf..43f3415c8 100755 --- a/test/functional/example_test.py +++ b/test/functional/example_test.py @@ -77,7 +77,9 @@ class ExampleTest(BitcoinTestFramework): # and setup_nodes() methods to customize the test setup as required. def set_test_params(self): - """Override any test parameters for your individual test.""" + """Override test parameters for your individual test. + + This method must be overridden and num_nodes must be exlicitly set.""" self.setup_clean_chain = True self.num_nodes = 3 # Use self.extra_args to change command-line arguments for the nodes diff --git a/test/functional/fundrawtransaction.py b/test/functional/fundrawtransaction.py index dec3d41bf..3326b58c4 100755 --- a/test/functional/fundrawtransaction.py +++ b/test/functional/fundrawtransaction.py @@ -16,6 +16,7 @@ def get_unspent(listunspent, amount): class RawTransactionsTest(BitcoinTestFramework): def set_test_params(self): + self.num_nodes = 4 self.setup_clean_chain = True def setup_network(self, split=False): diff --git a/test/functional/getblocktemplate_longpoll.py b/test/functional/getblocktemplate_longpoll.py index 85d256024..89768bd2f 100755 --- a/test/functional/getblocktemplate_longpoll.py +++ b/test/functional/getblocktemplate_longpoll.py @@ -23,6 +23,9 @@ class LongpollThread(threading.Thread): self.node.getblocktemplate({'longpollid':self.longpollid}) class GetBlockTemplateLPTest(BitcoinTestFramework): + def set_test_params(self): + self.num_nodes = 2 + def run_test(self): self.log.info("Warning: this test will take about 70 seconds in the best case. Be patient.") self.nodes[0].generate(10) diff --git a/test/functional/getchaintips.py b/test/functional/getchaintips.py index 00fc23c6b..21b67bfc6 100755 --- a/test/functional/getchaintips.py +++ b/test/functional/getchaintips.py @@ -14,6 +14,9 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal class GetChainTipsTest (BitcoinTestFramework): + def set_test_params(self): + self.num_nodes = 4 + def run_test (self): tips = self.nodes[0].getchaintips () assert_equal (len (tips), 1) diff --git a/test/functional/listsinceblock.py b/test/functional/listsinceblock.py index ed1315e80..6f428388e 100755 --- a/test/functional/listsinceblock.py +++ b/test/functional/listsinceblock.py @@ -9,6 +9,7 @@ from test_framework.util import assert_equal class ListSinceBlockTest (BitcoinTestFramework): def set_test_params(self): + self.num_nodes = 4 self.setup_clean_chain = True def run_test(self): diff --git a/test/functional/listtransactions.py b/test/functional/listtransactions.py index 5ee85a0da..e4522cc3b 100755 --- a/test/functional/listtransactions.py +++ b/test/functional/listtransactions.py @@ -17,6 +17,7 @@ def txFromHex(hexstring): class ListTransactionsTest(BitcoinTestFramework): def set_test_params(self): + self.num_nodes = 2 self.enable_mocktime() def run_test(self): diff --git a/test/functional/merkle_blocks.py b/test/functional/merkle_blocks.py index 2125c6e17..a58334b2a 100755 --- a/test/functional/merkle_blocks.py +++ b/test/functional/merkle_blocks.py @@ -9,6 +9,7 @@ from test_framework.util import * class MerkleBlockTest(BitcoinTestFramework): def set_test_params(self): + self.num_nodes = 4 self.setup_clean_chain = True # Nodes 0/1 are "wallet" nodes, Nodes 2/3 are used for testing self.extra_args = [[], [], [], ["-txindex"]] diff --git a/test/functional/p2p-segwit.py b/test/functional/p2p-segwit.py index 8c2d2f027..9bb72c819 100755 --- a/test/functional/p2p-segwit.py +++ b/test/functional/p2p-segwit.py @@ -34,6 +34,7 @@ def get_virtual_size(witness_block): class TestNode(NodeConnCB): def set_test_params(self): + self.num_nodes = 3 self.getdataset = set() def on_getdata(self, conn, message): diff --git a/test/functional/proxy_test.py b/test/functional/proxy_test.py index 26cb645da..81b99d1bf 100755 --- a/test/functional/proxy_test.py +++ b/test/functional/proxy_test.py @@ -42,6 +42,9 @@ from test_framework.netutil import test_ipv6_local RANGE_BEGIN = PORT_MIN + 2 * PORT_RANGE # Start after p2p and rpc ports class ProxyTest(BitcoinTestFramework): + def set_test_params(self): + self.num_nodes = 4 + def setup_nodes(self): self.have_ipv6 = test_ipv6_local() # Create two proxies on different ports diff --git a/test/functional/receivedby.py b/test/functional/receivedby.py index 48eb1c51b..db6fc86b8 100755 --- a/test/functional/receivedby.py +++ b/test/functional/receivedby.py @@ -24,6 +24,7 @@ def get_sub_array_from_array(object_array, to_match): class ReceivedByTest(BitcoinTestFramework): def set_test_params(self): + self.num_nodes = 2 self.enable_mocktime() def run_test(self): diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index d860bc559..103651f17 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -48,11 +48,10 @@ BITCOIND_PROC_WAIT_TIMEOUT = 60 class BitcoinTestFramework(object): """Base class for a bitcoin test script. - Individual bitcoin test scripts should subclass this class and override the run_test() method. + Individual bitcoin test scripts should subclass this class and override the set_test_params() and run_test() methods. Individual tests can also override the following methods to customize the test setup: - - set_test_params() - add_options() - setup_chain() - setup_network() @@ -64,12 +63,13 @@ class BitcoinTestFramework(object): def __init__(self): """Sets test framework defaults. Do not override this method. Instead, override the set_test_params() method""" - self.num_nodes = 4 self.setup_clean_chain = False self.nodes = [] self.mocktime = 0 self.set_test_params() + assert hasattr(self, "num_nodes"), "Test must set self.num_nodes in set_test_params()" + def main(self): """Main function. This should not be overridden by the subclass test scripts.""" @@ -177,8 +177,8 @@ class BitcoinTestFramework(object): # Methods to override in subclass test scripts. def set_test_params(self): - """Override this method to change default values for number of nodes, topology, etc""" - pass + """Tests must this method to change default values for number of nodes, topology, etc""" + raise NotImplementedError def add_options(self, parser): """Override this method to add command-line options to the test""" @@ -212,7 +212,7 @@ class BitcoinTestFramework(object): self.start_nodes() def run_test(self): - """Override this method to define test logic""" + """Tests must override this method to define test logic""" raise NotImplementedError # Public helper methods. These can be accessed by the subclass test scripts. diff --git a/test/functional/txn_clone.py b/test/functional/txn_clone.py index fc133050b..740bb2d4c 100755 --- a/test/functional/txn_clone.py +++ b/test/functional/txn_clone.py @@ -8,6 +8,9 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import * class TxnMallTest(BitcoinTestFramework): + def set_test_params(self): + self.num_nodes = 4 + def add_options(self, parser): parser.add_option("--mineblock", dest="mine_block", default=False, action="store_true", help="Test double-spend of 1-confirmed transaction") diff --git a/test/functional/txn_doublespend.py b/test/functional/txn_doublespend.py index ff24fac25..69629ef95 100755 --- a/test/functional/txn_doublespend.py +++ b/test/functional/txn_doublespend.py @@ -8,6 +8,8 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import * class TxnMallTest(BitcoinTestFramework): + def set_test_params(self): + self.num_nodes = 4 def add_options(self, parser): parser.add_option("--mineblock", dest="mine_block", default=False, action="store_true", diff --git a/test/functional/wallet.py b/test/functional/wallet.py index 0e5d641fe..0b3c267a2 100755 --- a/test/functional/wallet.py +++ b/test/functional/wallet.py @@ -8,6 +8,7 @@ from test_framework.util import * class WalletTest(BitcoinTestFramework): def set_test_params(self): + self.num_nodes = 4 self.setup_clean_chain = True self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)] diff --git a/test/functional/walletbackup.py b/test/functional/walletbackup.py index 36714164a..15ea26afa 100755 --- a/test/functional/walletbackup.py +++ b/test/functional/walletbackup.py @@ -38,6 +38,7 @@ from test_framework.util import * class WalletBackupTest(BitcoinTestFramework): def set_test_params(self): + self.num_nodes = 4 self.setup_clean_chain = True # nodes 1, 2,3 are spenders, let's give them a keypool=100 self.extra_args = [["-keypool=100"], ["-keypool=100"], ["-keypool=100"], []]