[Pkg-bitcoin-commits] [bitcoin] 17/126: [tests] Functional tests must explicitly set num_nodes

Jonas Smedegaard dr at jones.dk
Mon Nov 13 20:00:28 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/0.15.1_dfsg-1
in repository bitcoin.

commit 82bf6fc6d48a232cc0ceb54b136d86914f49013c
Author: John Newbery <john at johnnewbery.com>
Date:   Thu Aug 24 11:11:56 2017 -0400

    [tests] Functional tests must explicitly set num_nodes
    
    Github-Pull: #11121
    Rebased-From: 7148b74dc39110f53c665b94fa9d994c6ad6dc1c
---
 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 de8934f..936aceb 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 dec3d41..3326b58 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 85d2560..89768bd 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 00fc23c..21b67bf 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 ed1315e..6f42838 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 5ee85a0..e4522cc 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 2125c6e..a58334b 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 8c2d2f0..9bb72c8 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 26cb645..81b99d1 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 48eb1c5..db6fc86 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 d860bc5..103651f 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 fc13305..740bb2d 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 ff24fac..69629ef 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 79727f9..de3aa8a 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 3671416..15ea26a 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"], []]

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-bitcoin/bitcoin.git



More information about the Pkg-bitcoin-commits mailing list