[Pkg-bitcoin-commits] [bitcoin] 15/126: [tests] Avoid passing around member variables in test_framework

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 bb5e7cb308b58a1c16db1275dfca1a31e2bba71f
Author: John Newbery <john at johnnewbery.com>
Date:   Thu Aug 24 11:37:25 2017 -0400

    [tests] Avoid passing around member variables in test_framework
    
    Github-Pull: #11121
    Rebased-From: 6cf094a0229d051ab8a15189c8a0bc6011919e72
---
 test/functional/assumevalid.py                   |  2 +-
 test/functional/dbcrash.py                       |  2 +-
 test/functional/import-rescan.py                 |  2 +-
 test/functional/proxy_test.py                    |  2 +-
 test/functional/pruning.py                       |  2 +-
 test/functional/rpcbind_test.py                  |  2 +-
 test/functional/smartfees.py                     |  6 +--
 test/functional/test_framework/test_framework.py | 50 ++++++++++++------------
 test/functional/wallet-dump.py                   |  2 +-
 test/functional/wallet.py                        |  2 +-
 test/functional/zmq_test.py                      |  2 +-
 11 files changed, 37 insertions(+), 37 deletions(-)

diff --git a/test/functional/assumevalid.py b/test/functional/assumevalid.py
index 63e6a38..ec48528 100755
--- a/test/functional/assumevalid.py
+++ b/test/functional/assumevalid.py
@@ -60,7 +60,7 @@ class AssumeValidTest(BitcoinTestFramework):
         self.num_nodes = 3
 
     def setup_network(self):
-        self.add_nodes(3, self.options.tmpdir)
+        self.add_nodes(3)
         # Start node0. We don't start the other nodes yet since
         # we need to pre-mine a block with an invalid transaction
         # signature so we can pass in the block hash as assumevalid.
diff --git a/test/functional/dbcrash.py b/test/functional/dbcrash.py
index d393691..b0c6d39 100755
--- a/test/functional/dbcrash.py
+++ b/test/functional/dbcrash.py
@@ -65,7 +65,7 @@ class ChainstateWriteCrashTest(BitcoinTestFramework):
 
     def setup_network(self):
         # Need a bit of extra time for the nodes to start up for this test
-        self.add_nodes(self.num_nodes, self.options.tmpdir, self.extra_args, timewait=90)
+        self.add_nodes(self.num_nodes, timewait=90)
         self.start_nodes()
         # Leave them unconnected, we'll use submitblock directly in this test
 
diff --git a/test/functional/import-rescan.py b/test/functional/import-rescan.py
index be52d5c..e85086f 100755
--- a/test/functional/import-rescan.py
+++ b/test/functional/import-rescan.py
@@ -121,7 +121,7 @@ class ImportRescanTest(BitcoinTestFramework):
             if import_node.prune:
                 extra_args[i] += ["-prune=1"]
 
-        self.add_nodes(self.num_nodes, self.options.tmpdir, extra_args)
+        self.add_nodes(self.num_nodes, extra_args)
         self.start_nodes()
         for i in range(1, self.num_nodes):
             connect_nodes(self.nodes[i], 0)
diff --git a/test/functional/proxy_test.py b/test/functional/proxy_test.py
index 7f5a381..adbbda2 100755
--- a/test/functional/proxy_test.py
+++ b/test/functional/proxy_test.py
@@ -89,7 +89,7 @@ class ProxyTest(BitcoinTestFramework):
             ]
         if self.have_ipv6:
             args[3] = ['-listen', '-proxy=[%s]:%i' % (self.conf3.addr),'-proxyrandomize=0', '-noonion']
-        self.add_nodes(self.num_nodes, self.options.tmpdir, extra_args=args)
+        self.add_nodes(self.num_nodes, extra_args=args)
         self.start_nodes()
 
     def node_test(self, node, proxies, auth, test_onion=True):
diff --git a/test/functional/pruning.py b/test/functional/pruning.py
index fe406e8..9690428 100755
--- a/test/functional/pruning.py
+++ b/test/functional/pruning.py
@@ -57,7 +57,7 @@ class PruneTest(BitcoinTestFramework):
         sync_blocks(self.nodes[0:5])
 
     def setup_nodes(self):
-        self.add_nodes(self.num_nodes, self.options.tmpdir, self.extra_args, timewait=900)
+        self.add_nodes(self.num_nodes, self.extra_args, timewait=900)
         self.start_nodes()
 
     def create_big_chain(self):
diff --git a/test/functional/rpcbind_test.py b/test/functional/rpcbind_test.py
index e9d64af..a766142 100755
--- a/test/functional/rpcbind_test.py
+++ b/test/functional/rpcbind_test.py
@@ -20,7 +20,7 @@ class RPCBindTest(BitcoinTestFramework):
         self.num_nodes = 1
 
     def setup_network(self):
-        self.add_nodes(self.num_nodes, self.options.tmpdir, None)
+        self.add_nodes(self.num_nodes, None)
 
     def run_bind_test(self, allow_ips, connect_to, addresses, expected):
         '''
diff --git a/test/functional/smartfees.py b/test/functional/smartfees.py
index 6eb6658..caf3592 100755
--- a/test/functional/smartfees.py
+++ b/test/functional/smartfees.py
@@ -153,9 +153,9 @@ class EstimateFeeTest(BitcoinTestFramework):
         But first we need to use one node to create a lot of outputs
         which we will use to generate our transactions.
         """
-        self.add_nodes(3, self.options.tmpdir, extra_args=[["-maxorphantx=1000", "-whitelist=127.0.0.1"],
-                                                           ["-blockmaxsize=17000", "-maxorphantx=1000"],
-                                                           ["-blockmaxsize=8000", "-maxorphantx=1000"]])
+        self.add_nodes(3, extra_args=[["-maxorphantx=1000", "-whitelist=127.0.0.1"],
+                                      ["-blockmaxsize=17000", "-maxorphantx=1000"],
+                                      ["-blockmaxsize=8000", "-maxorphantx=1000"]])
         # Use node0 to mine blocks for input splitting
         # Node1 mines small blocks but that are bigger than the expected transaction rate.
         # NOTE: the CreateNewBlock code starts counting block size at 1,000 bytes,
diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py
index a14ff9c..5e3644a 100755
--- a/test/functional/test_framework/test_framework.py
+++ b/test/functional/test_framework/test_framework.py
@@ -73,9 +73,9 @@ class BitcoinTestFramework(object):
     def setup_chain(self):
         self.log.info("Initializing test directory " + self.options.tmpdir)
         if self.setup_clean_chain:
-            self._initialize_chain_clean(self.options.tmpdir, self.num_nodes)
+            self._initialize_chain_clean()
         else:
-            self._initialize_chain(self.options.tmpdir, self.num_nodes, self.options.cachedir)
+            self._initialize_chain()
 
     def setup_network(self):
         self.setup_nodes()
@@ -91,7 +91,7 @@ class BitcoinTestFramework(object):
         extra_args = None
         if hasattr(self, "extra_args"):
             extra_args = self.extra_args
-        self.add_nodes(self.num_nodes, self.options.tmpdir, extra_args)
+        self.add_nodes(self.num_nodes, extra_args)
         self.start_nodes()
 
     def run_test(self):
@@ -205,7 +205,7 @@ class BitcoinTestFramework(object):
 
     # Public helper methods. These can be accessed by the subclass test scripts.
 
-    def add_nodes(self, num_nodes, dirname, extra_args=None, rpchost=None, timewait=None, binary=None):
+    def add_nodes(self, num_nodes, extra_args=None, rpchost=None, timewait=None, binary=None):
         """Instantiate TestNode objects"""
 
         if extra_args is None:
@@ -215,7 +215,7 @@ class BitcoinTestFramework(object):
         assert_equal(len(extra_args), num_nodes)
         assert_equal(len(binary), num_nodes)
         for i in range(num_nodes):
-            self.nodes.append(TestNode(i, dirname, extra_args[i], rpchost, timewait=timewait, binary=binary[i], stderr=None, mocktime=self.mocktime, coverage_dir=self.options.coveragedir))
+            self.nodes.append(TestNode(i, self.options.tmpdir, extra_args[i], rpchost, timewait=timewait, binary=binary[i], stderr=None, mocktime=self.mocktime, coverage_dir=self.options.coveragedir))
 
     def start_node(self, i, extra_args=None, stderr=None):
         """Start a bitcoind"""
@@ -357,16 +357,16 @@ class BitcoinTestFramework(object):
             rpc_handler.setLevel(logging.DEBUG)
             rpc_logger.addHandler(rpc_handler)
 
-    def _initialize_chain(self, test_dir, num_nodes, cachedir):
+    def _initialize_chain(self):
         """Initialize a pre-mined blockchain for use by the test.
 
         Create a cache of a 200-block-long chain (with wallet) for MAX_NODES
         Afterward, create num_nodes copies from the cache."""
 
-        assert num_nodes <= MAX_NODES
+        assert self.num_nodes <= MAX_NODES
         create_cache = False
         for i in range(MAX_NODES):
-            if not os.path.isdir(os.path.join(cachedir, 'node' + str(i))):
+            if not os.path.isdir(os.path.join(self.options.cachedir, 'node' + str(i))):
                 create_cache = True
                 break
 
@@ -375,16 +375,16 @@ class BitcoinTestFramework(object):
 
             # find and delete old cache directories if any exist
             for i in range(MAX_NODES):
-                if os.path.isdir(os.path.join(cachedir, "node" + str(i))):
-                    shutil.rmtree(os.path.join(cachedir, "node" + str(i)))
+                if os.path.isdir(os.path.join(self.options.cachedir, "node" + str(i))):
+                    shutil.rmtree(os.path.join(self.options.cachedir, "node" + str(i)))
 
             # Create cache directories, run bitcoinds:
             for i in range(MAX_NODES):
-                datadir = initialize_datadir(cachedir, i)
+                datadir = initialize_datadir(self.options.cachedir, i)
                 args = [os.getenv("BITCOIND", "bitcoind"), "-server", "-keypool=1", "-datadir=" + datadir, "-discover=0"]
                 if i > 0:
                     args.append("-connect=127.0.0.1:" + str(p2p_port(0)))
-                self.nodes.append(TestNode(i, cachedir, extra_args=[], rpchost=None, timewait=None, binary=None, stderr=None, mocktime=self.mocktime, coverage_dir=None))
+                self.nodes.append(TestNode(i, self.options.cachedir, extra_args=[], rpchost=None, timewait=None, binary=None, stderr=None, mocktime=self.mocktime, coverage_dir=None))
                 self.nodes[i].args = args
                 self.start_node(i)
 
@@ -415,24 +415,24 @@ class BitcoinTestFramework(object):
             self.nodes = []
             self.disable_mocktime()
             for i in range(MAX_NODES):
-                os.remove(log_filename(cachedir, i, "debug.log"))
-                os.remove(log_filename(cachedir, i, "db.log"))
-                os.remove(log_filename(cachedir, i, "peers.dat"))
-                os.remove(log_filename(cachedir, i, "fee_estimates.dat"))
-
-        for i in range(num_nodes):
-            from_dir = os.path.join(cachedir, "node" + str(i))
-            to_dir = os.path.join(test_dir, "node" + str(i))
+                os.remove(log_filename(self.options.cachedir, i, "debug.log"))
+                os.remove(log_filename(self.options.cachedir, i, "db.log"))
+                os.remove(log_filename(self.options.cachedir, i, "peers.dat"))
+                os.remove(log_filename(self.options.cachedir, i, "fee_estimates.dat"))
+
+        for i in range(self.num_nodes):
+            from_dir = os.path.join(self.options.cachedir, "node" + str(i))
+            to_dir = os.path.join(self.options.tmpdir, "node" + str(i))
             shutil.copytree(from_dir, to_dir)
-            initialize_datadir(test_dir, i)  # Overwrite port/rpcport in bitcoin.conf
+            initialize_datadir(self.options.tmpdir, i)  # Overwrite port/rpcport in bitcoin.conf
 
-    def _initialize_chain_clean(self, test_dir, num_nodes):
+    def _initialize_chain_clean(self):
         """Initialize empty blockchain for use by the test.
 
         Create an empty blockchain and num_nodes wallets.
         Useful if a test case wants complete control over initialization."""
-        for i in range(num_nodes):
-            initialize_datadir(test_dir, i)
+        for i in range(self.num_nodes):
+            initialize_datadir(self.options.tmpdir, i)
 
 class ComparisonTestFramework(BitcoinTestFramework):
     """Test framework for doing p2p comparison testing
@@ -459,7 +459,7 @@ class ComparisonTestFramework(BitcoinTestFramework):
         extra_args = [['-whitelist=127.0.0.1']] * self.num_nodes
         if hasattr(self, "extra_args"):
             extra_args = self.extra_args
-        self.add_nodes(self.num_nodes, self.options.tmpdir, extra_args,
+        self.add_nodes(self.num_nodes, extra_args,
                        binary=[self.options.testbinary] +
                        [self.options.refbinary] * (self.num_nodes - 1))
         self.start_nodes()
diff --git a/test/functional/wallet-dump.py b/test/functional/wallet-dump.py
index a588e23..e0381b9 100755
--- a/test/functional/wallet-dump.py
+++ b/test/functional/wallet-dump.py
@@ -68,7 +68,7 @@ class WalletDumpTest(BitcoinTestFramework):
         # longer than the default 30 seconds due to an expensive
         # CWallet::TopUpKeyPool call, and the encryptwallet RPC made later in
         # the test often takes even longer.
-        self.add_nodes(self.num_nodes, self.options.tmpdir, self.extra_args, timewait=60)
+        self.add_nodes(self.num_nodes, self.extra_args, timewait=60)
         self.start_nodes()
 
     def run_test (self):
diff --git a/test/functional/wallet.py b/test/functional/wallet.py
index 1789610..7190de9 100755
--- a/test/functional/wallet.py
+++ b/test/functional/wallet.py
@@ -21,7 +21,7 @@ class WalletTest(BitcoinTestFramework):
         self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)]
 
     def setup_network(self):
-        self.add_nodes(4, self.options.tmpdir, self.extra_args)
+        self.add_nodes(4, self.extra_args)
         self.start_node(0)
         self.start_node(1)
         self.start_node(2)
diff --git a/test/functional/zmq_test.py b/test/functional/zmq_test.py
index 603b7a1..b5a22ea 100755
--- a/test/functional/zmq_test.py
+++ b/test/functional/zmq_test.py
@@ -42,7 +42,7 @@ class ZMQTest (BitcoinTestFramework):
         ip_address = "tcp://127.0.0.1:28332"
         self.zmqSubSocket.connect(ip_address)
         self.extra_args = [['-zmqpubhashtx=%s' % ip_address, '-zmqpubhashblock=%s' % ip_address], []]
-        self.add_nodes(self.num_nodes, self.options.tmpdir, self.extra_args)
+        self.add_nodes(self.num_nodes, self.extra_args)
         self.start_nodes()
 
     def run_test(self):

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