diff --git a/qa/rpc-tests/addressindex.py b/qa/rpc-tests/addressindex.py index 0ed542923..e655f9bc6 100755 --- a/qa/rpc-tests/addressindex.py +++ b/qa/rpc-tests/addressindex.py @@ -18,7 +18,6 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, - initialize_chain_clean, start_nodes, stop_nodes, connect_nodes, @@ -44,16 +43,17 @@ from binascii import hexlify, unhexlify class AddressIndexTest(BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) + def __init__(self): + super().__init__() + self.num_nodes = 4 + self.setup_clean_chain = True def setup_network(self): # -insightexplorer causes addressindex to be enabled (fAddressIndex = true) args_insight = ('-debug', '-txindex', '-experimentalfeatures', '-insightexplorer') # -lightwallet also causes addressindex to be enabled args_lightwallet = ('-debug', '-txindex', '-experimentalfeatures', '-lightwalletd') - self.nodes = start_nodes(4, self.options.tmpdir, [args_insight] * 3 + [args_lightwallet]) + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, [args_insight] * 3 + [args_lightwallet]) connect_nodes(self.nodes[0], 1) connect_nodes(self.nodes[0], 2) @@ -237,7 +237,7 @@ class AddressIndexTest(BitcoinTestFramework): # Test DisconnectBlock() by invalidating the most recent mined block tip = self.nodes[1].getchaintips()[0] - for i in range(3): + for i in range(self.num_nodes): node = self.nodes[i] # the value 4 UTXO is no longer in our balance check_balance(i, addr1, (expected - 4) * COIN, expected * COIN) diff --git a/qa/rpc-tests/bip65-cltv-p2p.py b/qa/rpc-tests/bip65-cltv-p2p.py index 87796d5e1..61ee6ed95 100755 --- a/qa/rpc-tests/bip65-cltv-p2p.py +++ b/qa/rpc-tests/bip65-cltv-p2p.py @@ -25,10 +25,11 @@ TODO: factor out common code from {bipdersig-p2p,bip65-cltv-p2p}.py. class BIP65Test(ComparisonTestFramework): def __init__(self): + super().__init__() self.num_nodes = 1 def setup_network(self): - self.nodes = start_nodes(1, self.options.tmpdir, + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[['-debug', '-whitelist=127.0.0.1']], binary=[self.options.testbinary]) self.is_network_split = False diff --git a/qa/rpc-tests/bipdersig-p2p.py b/qa/rpc-tests/bipdersig-p2p.py index ec585f6e9..7d5f24985 100755 --- a/qa/rpc-tests/bipdersig-p2p.py +++ b/qa/rpc-tests/bipdersig-p2p.py @@ -25,10 +25,11 @@ TODO: factor out common code from {bipdersig-p2p,bip65-cltv-p2p}.py. class BIP66Test(ComparisonTestFramework): def __init__(self): + super().__init__() self.num_nodes = 1 def setup_network(self): - self.nodes = start_nodes(1, self.options.tmpdir, + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[['-debug', '-whitelist=127.0.0.1']], binary=[self.options.testbinary]) self.is_network_split = False diff --git a/qa/rpc-tests/blockchain.py b/qa/rpc-tests/blockchain.py index 7c1bac285..7f65063a1 100755 --- a/qa/rpc-tests/blockchain.py +++ b/qa/rpc-tests/blockchain.py @@ -12,7 +12,6 @@ import decimal from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( - initialize_chain, assert_equal, start_nodes, connect_nodes_bi, @@ -26,12 +25,13 @@ class BlockchainTest(BitcoinTestFramework): """ - def setup_chain(self): - print("Initializing test directory " + self.options.tmpdir) - initialize_chain(self.options.tmpdir) + def __init__(self): + super().__init__() + self.setup_clean_chain = False + self.num_nodes = 2 def setup_network(self, split=False): - self.nodes = start_nodes(2, self.options.tmpdir) + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir) connect_nodes_bi(self.nodes, 0, 1) self.is_network_split = False self.sync_all() diff --git a/qa/rpc-tests/coinbase_funding_streams.py b/qa/rpc-tests/coinbase_funding_streams.py index 31c081e90..0fd6e84c8 100755 --- a/qa/rpc-tests/coinbase_funding_streams.py +++ b/qa/rpc-tests/coinbase_funding_streams.py @@ -12,7 +12,6 @@ from test_framework.util import ( assert_equal, bitcoind_processes, connect_nodes, - initialize_chain_clean, start_node, BLOSSOM_BRANCH_ID, HEARTWOOD_BRANCH_ID, @@ -20,9 +19,10 @@ from test_framework.util import ( ) class CoinbaseFundingStreamsTest (BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) + def __init__(self): + super().__init__() + self.num_nodes = 2 + self.setup_clean_chain = True def start_node_with(self, index, extra_args=[]): args = [ diff --git a/qa/rpc-tests/decodescript.py b/qa/rpc-tests/decodescript.py index 60cdaa988..9523c96aa 100755 --- a/qa/rpc-tests/decodescript.py +++ b/qa/rpc-tests/decodescript.py @@ -4,7 +4,7 @@ # file COPYING or https://www.opensource.org/licenses/mit-license.php . from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, initialize_chain_clean, \ +from test_framework.util import assert_equal, \ start_nodes, hex_str_to_bytes, bytes_to_hex_str from test_framework.mininode import CTransaction from io import BytesIO @@ -13,12 +13,13 @@ from io import BytesIO class DecodeScriptTest(BitcoinTestFramework): """Tests decoding scripts via RPC command "decodescript".""" - def setup_chain(self): - print('Initializing test directory ' + self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 1) + def __init__(self): + super().__init__() + self.setup_clean_chain = True + self.num_nodes = 1 def setup_network(self, split=False): - self.nodes = start_nodes(1, self.options.tmpdir) + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir) self.is_network_split = False def decodescript_script_sig(self): diff --git a/qa/rpc-tests/disablewallet.py b/qa/rpc-tests/disablewallet.py index 3b32b26ae..f29820414 100755 --- a/qa/rpc-tests/disablewallet.py +++ b/qa/rpc-tests/disablewallet.py @@ -8,17 +8,18 @@ # from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import initialize_chain_clean, start_nodes +from test_framework.util import start_nodes class DisableWalletTest (BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 1) + def __init__(self): + super().__init__() + self.setup_clean_chain = True + self.num_nodes = 1 def setup_network(self, split=False): - self.nodes = start_nodes(1, self.options.tmpdir, [['-disablewallet']]) + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, [['-disablewallet']]) self.is_network_split = False self.sync_all() diff --git a/qa/rpc-tests/feature_zip221.py b/qa/rpc-tests/feature_zip221.py index bfe0f656b..0539343f5 100755 --- a/qa/rpc-tests/feature_zip221.py +++ b/qa/rpc-tests/feature_zip221.py @@ -12,7 +12,6 @@ from test_framework.util import ( assert_equal, bytes_to_hex_str, hex_str_to_bytes, - initialize_chain_clean, start_nodes, ) @@ -24,16 +23,17 @@ CHAIN_HISTORY_ROOT_VERSION = 2010200 # Verify block header field 'hashLightClientRoot' is set correctly for Heartwood blocks. class Zip221Test(BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) + def __init__(self): + super().__init__() + self.num_nodes = 4 + self.setup_clean_chain = True def setup_nodes(self): - return start_nodes(4, self.options.tmpdir, extra_args=[[ + return start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[[ '-nuparams=2bb40e60:1', # Blossom '-nuparams=f5b9230b:10', # Heartwood '-nurejectoldversions=false', - ]] * 4) + ]] * self.num_nodes) def node_for_block(self, height): block_header = CBlockHeader() diff --git a/qa/rpc-tests/finalsaplingroot.py b/qa/rpc-tests/finalsaplingroot.py index 25332f141..257d9893d 100755 --- a/qa/rpc-tests/finalsaplingroot.py +++ b/qa/rpc-tests/finalsaplingroot.py @@ -9,7 +9,6 @@ from test_framework.util import ( assert_equal, connect_nodes_bi, get_coinbase_address, - initialize_chain_clean, start_nodes, wait_and_assert_operationid_status, ) @@ -24,14 +23,15 @@ NULL_FIELD = "0000000000000000000000000000000000000000000000000000000000000000" # is updated when Sapling transactions with outputs (commitments) are mined into a block. class FinalSaplingRootTest(BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) + def __init__(self): + super().__init__() + self.num_nodes = 4 + self.setup_clean_chain = True def setup_network(self, split=False): - self.nodes = start_nodes(4, self.options.tmpdir, extra_args=[[ + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[[ '-txindex' # Avoid JSONRPC error: No information available about transaction - ]] * 4 ) + ]] * self.num_nodes) connect_nodes_bi(self.nodes,0,1) connect_nodes_bi(self.nodes,1,2) connect_nodes_bi(self.nodes,0,2) diff --git a/qa/rpc-tests/forknotify.py b/qa/rpc-tests/forknotify.py index 2374c9dea..b97d1fb77 100755 --- a/qa/rpc-tests/forknotify.py +++ b/qa/rpc-tests/forknotify.py @@ -14,6 +14,11 @@ import os class ForkNotifyTest(BitcoinTestFramework): + def __init__(self): + super().__init__() + self.num_nodes = 2 + self.setup_clean_chain = False + alert_filename = None # Set by setup_network def setup_network(self): diff --git a/qa/rpc-tests/framework.py b/qa/rpc-tests/framework.py index ec676eeb2..7a6765160 100755 --- a/qa/rpc-tests/framework.py +++ b/qa/rpc-tests/framework.py @@ -7,16 +7,16 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_raises, connect_nodes, - initialize_chain_clean, start_node, check_node_log, ) class FrameworkTest (BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) + def __init__(self): + super().__init__() + self.num_nodes = 2 + self.setup_clean_chain = True def start_node_with(self, index, extra_args=[]): args = [] diff --git a/qa/rpc-tests/fundrawtransaction.py b/qa/rpc-tests/fundrawtransaction.py index 708c69b27..14e48d0ad 100755 --- a/qa/rpc-tests/fundrawtransaction.py +++ b/qa/rpc-tests/fundrawtransaction.py @@ -6,7 +6,7 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.authproxy import JSONRPCException from test_framework.util import assert_equal, assert_greater_than, \ - initialize_chain_clean, start_nodes, connect_nodes_bi, stop_nodes, \ + start_nodes, connect_nodes_bi, stop_nodes, \ wait_bitcoinds from decimal import Decimal @@ -14,12 +14,13 @@ from decimal import Decimal # Create one-input, one-output, no-fee transaction: class RawTransactionsTest(BitcoinTestFramework): - def setup_chain(self): - print(("Initializing test directory "+self.options.tmpdir)) - initialize_chain_clean(self.options.tmpdir, 4) + def __init__(self): + super().__init__() + self.setup_clean_chain = True + self.num_nodes = 4 def setup_network(self, split=False): - self.nodes = start_nodes(4, self.options.tmpdir, + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[['-experimentalfeatures', '-developerencryptwallet']] * 4) connect_nodes_bi(self.nodes,0,1) @@ -450,7 +451,7 @@ class RawTransactionsTest(BitcoinTestFramework): stop_nodes(self.nodes) wait_bitcoinds() - self.nodes = start_nodes(4, self.options.tmpdir) + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir) connect_nodes_bi(self.nodes,0,1) connect_nodes_bi(self.nodes,1,2) diff --git a/qa/rpc-tests/getblocktemplate.py b/qa/rpc-tests/getblocktemplate.py index e55e1e9fd..223132da4 100755 --- a/qa/rpc-tests/getblocktemplate.py +++ b/qa/rpc-tests/getblocktemplate.py @@ -5,7 +5,7 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, connect_nodes_bi, \ - initialize_chain_clean, start_nodes + start_nodes class GetBlockTemplateTest(BitcoinTestFramework): @@ -13,12 +13,13 @@ class GetBlockTemplateTest(BitcoinTestFramework): Test getblocktemplate. ''' - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) + def __init__(self): + super().__init__() + self.num_nodes = 2 + self.setup_clean_chain = True def setup_network(self, split=False): - self.nodes = start_nodes(2, self.options.tmpdir) + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir) connect_nodes_bi(self.nodes,0,1) self.is_network_split=False self.sync_all() diff --git a/qa/rpc-tests/getblocktemplate_longpoll.py b/qa/rpc-tests/getblocktemplate_longpoll.py index c2e32b4db..89f5394f2 100755 --- a/qa/rpc-tests/getblocktemplate_longpoll.py +++ b/qa/rpc-tests/getblocktemplate_longpoll.py @@ -49,6 +49,11 @@ class GetBlockTemplateLPTest(BitcoinTestFramework): Test longpolling with getblocktemplate. ''' + def __init__(self): + super().__init__() + self.num_nodes = 4 + self.setup_clean_chain = False + def run_test(self): print("Warning: this test will take about 70 seconds in the best case. Be patient.") self.nodes[0].generate(10) diff --git a/qa/rpc-tests/getblocktemplate_proposals.py b/qa/rpc-tests/getblocktemplate_proposals.py index bce1b1784..94b1616e2 100755 --- a/qa/rpc-tests/getblocktemplate_proposals.py +++ b/qa/rpc-tests/getblocktemplate_proposals.py @@ -5,6 +5,7 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.authproxy import JSONRPCException +from test_framework.util import connect_nodes_bi from binascii import a2b_hex, b2a_hex from hashlib import sha256 @@ -94,6 +95,15 @@ class GetBlockTemplateProposalTest(BitcoinTestFramework): Test block proposals with getblocktemplate. ''' + def __init__(self): + super().__init__() + self.num_nodes = 2 + self.setup_clean_chain = False + + def setup_network(self): + self.nodes = self.setup_nodes() + connect_nodes_bi(self.nodes, 0, 1) + def run_test(self): node = self.nodes[0] node.generate(1) # Mine a block to leave initial block download diff --git a/qa/rpc-tests/getchaintips.py b/qa/rpc-tests/getchaintips.py index c75a89f46..63543f48c 100755 --- a/qa/rpc-tests/getchaintips.py +++ b/qa/rpc-tests/getchaintips.py @@ -12,9 +12,12 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal class GetChainTipsTest (BitcoinTestFramework): + def __init__(self): + super().__init__() + self.num_nodes = 4 + self.setup_clean_chain = False def run_test (self): - BitcoinTestFramework.run_test (self) tips = self.nodes[0].getchaintips () assert_equal (len (tips), 1) diff --git a/qa/rpc-tests/getrawtransaction_insight.py b/qa/rpc-tests/getrawtransaction_insight.py index f32995d68..f54bf85ee 100755 --- a/qa/rpc-tests/getrawtransaction_insight.py +++ b/qa/rpc-tests/getrawtransaction_insight.py @@ -11,7 +11,6 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal -from test_framework.util import initialize_chain_clean from test_framework.util import start_nodes, stop_nodes, connect_nodes from test_framework.util import wait_bitcoinds @@ -20,15 +19,16 @@ from test_framework.mininode import COIN class GetrawtransactionTest(BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) + def __init__(self): + super().__init__() + self.num_nodes = 3 + self.setup_clean_chain = True def setup_network(self): # -insightexplorer causes spentindex to be enabled (fSpentIndex = true) - self.nodes = start_nodes(3, self.options.tmpdir, - [['-debug', '-txindex', '-experimentalfeatures', '-insightexplorer']]*3) + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, + [['-debug', '-txindex', '-experimentalfeatures', '-insightexplorer']] * self.num_nodes) connect_nodes(self.nodes[0], 1) connect_nodes(self.nodes[0], 2) diff --git a/qa/rpc-tests/httpbasics.py b/qa/rpc-tests/httpbasics.py index a98fb0098..ba01583dd 100755 --- a/qa/rpc-tests/httpbasics.py +++ b/qa/rpc-tests/httpbasics.py @@ -8,14 +8,19 @@ # from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, start_nodes, str_to_b64str +from test_framework.util import assert_equal, str_to_b64str import http.client import urllib.parse class HTTPBasicsTest (BitcoinTestFramework): - def setup_nodes(self): - return start_nodes(4, self.options.tmpdir) + def __init__(self): + super().__init__() + self.num_nodes = 3 + self.setup_clean_chain = False + + def setup_network(self): + self.nodes = self.setup_nodes() def run_test(self): diff --git a/qa/rpc-tests/invalidateblock.py b/qa/rpc-tests/invalidateblock.py index c6b3c5822..6907dc21d 100755 --- a/qa/rpc-tests/invalidateblock.py +++ b/qa/rpc-tests/invalidateblock.py @@ -8,15 +8,16 @@ # from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import initialize_chain_clean, start_node, \ +from test_framework.util import start_node, \ connect_nodes_bi, sync_blocks import time class InvalidateTest(BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 3) + def __init__(self): + super().__init__() + self.setup_clean_chain = True + self.num_nodes = 3 def setup_network(self): self.nodes = [] diff --git a/qa/rpc-tests/invalidblockrequest.py b/qa/rpc-tests/invalidblockrequest.py index b77b2f2ad..958938540 100755 --- a/qa/rpc-tests/invalidblockrequest.py +++ b/qa/rpc-tests/invalidblockrequest.py @@ -27,6 +27,7 @@ class InvalidBlockRequestTest(ComparisonTestFramework): ''' Can either run this test as 1 node with expected answers, or two and compare them. Change the "outcome" variable from each TestInstance object to only do the comparison. ''' def __init__(self): + super().__init__() self.num_nodes = 1 def run_test(self): diff --git a/qa/rpc-tests/key_import_export.py b/qa/rpc-tests/key_import_export.py index d841851a0..43f4c85de 100755 --- a/qa/rpc-tests/key_import_export.py +++ b/qa/rpc-tests/key_import_export.py @@ -6,7 +6,7 @@ from decimal import Decimal from functools import reduce from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, assert_greater_than, start_nodes, initialize_chain_clean, connect_nodes_bi +from test_framework.util import assert_equal, assert_greater_than, start_nodes, connect_nodes_bi import logging @@ -15,12 +15,13 @@ logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO) class KeyImportExportTest (BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) + def __init__(self): + super().__init__() + self.num_nodes = 4 + self.setup_clean_chain = True def setup_network(self, split=False): - self.nodes = start_nodes(4, self.options.tmpdir ) + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir ) connect_nodes_bi(self.nodes,0,1) connect_nodes_bi(self.nodes,1,2) connect_nodes_bi(self.nodes,0,2) diff --git a/qa/rpc-tests/keypool.py b/qa/rpc-tests/keypool.py index 5a8260743..ccba07ea9 100755 --- a/qa/rpc-tests/keypool.py +++ b/qa/rpc-tests/keypool.py @@ -5,11 +5,9 @@ # Exercise the wallet keypool, and interaction with wallet encryption/locking -# Add python-bitcoinrpc to module search path: - from test_framework.authproxy import JSONRPCException from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, initialize_chain, \ +from test_framework.util import assert_equal, \ start_nodes, start_node, bitcoind_processes def check_array_result(object_array, to_match, expected): @@ -86,12 +84,13 @@ class KeyPoolTest(BitcoinTestFramework): except JSONRPCException as e: assert_equal(e.error['code'], -12) - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain(self.options.tmpdir) + def __init__(self): + super().__init__() + self.setup_clean_chain = False + self.num_nodes = 1 def setup_network(self): - self.nodes = start_nodes(1, self.options.tmpdir, extra_args=[['-experimentalfeatures', '-developerencryptwallet']]) + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[['-experimentalfeatures', '-developerencryptwallet']]) if __name__ == '__main__': KeyPoolTest().main() diff --git a/qa/rpc-tests/listtransactions.py b/qa/rpc-tests/listtransactions.py index 35d00a6f1..53871ea59 100755 --- a/qa/rpc-tests/listtransactions.py +++ b/qa/rpc-tests/listtransactions.py @@ -31,6 +31,10 @@ def check_array_result(object_array, to_match, expected): raise AssertionError("No objects matched %s"%(str(to_match))) class ListTransactionsTest(BitcoinTestFramework): + def __init__(self): + super().__init__() + self.num_nodes = 4 + self.setup_clean_chain = False def run_test(self): # Simple send, 0 to 1: diff --git a/qa/rpc-tests/maxblocksinflight.py b/qa/rpc-tests/maxblocksinflight.py index f8a67e26e..9211f3ae0 100755 --- a/qa/rpc-tests/maxblocksinflight.py +++ b/qa/rpc-tests/maxblocksinflight.py @@ -6,8 +6,7 @@ from test_framework.mininode import NodeConn, NodeConnCB, NetworkThread, \ EarlyDisconnectError, CInv, msg_inv, mininode_lock from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import initialize_chain_clean, start_nodes, \ - p2p_port +from test_framework.util import start_nodes, p2p_port import os import time @@ -86,12 +85,13 @@ class MaxBlocksInFlightTest(BitcoinTestFramework): default=os.getenv("BITCOIND", "bitcoind"), help="Binary to test max block requests behavior") - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 1) + def __init__(self): + super().__init__() + self.setup_clean_chain = True + self.num_nodes = 1 def setup_network(self): - self.nodes = start_nodes(1, self.options.tmpdir, + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[['-debug', '-whitelist=127.0.0.1']], binary=[self.options.testbinary]) diff --git a/qa/rpc-tests/mempool_limit.py b/qa/rpc-tests/mempool_limit.py index a942b652b..6600376ae 100755 --- a/qa/rpc-tests/mempool_limit.py +++ b/qa/rpc-tests/mempool_limit.py @@ -8,7 +8,6 @@ from test_framework.util import ( assert_equal, get_coinbase_address, fail, - initialize_chain_clean, start_nodes, wait_and_assert_operationid_status, ) @@ -18,10 +17,6 @@ from time import sleep # Test wallet behaviour with Sapling addresses class MempoolLimit(BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory " + self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) - def setup_nodes(self): extra_args = [ ["-debug=mempool", '-mempooltxcostlimit=8000'], # 2 transactions at min cost @@ -30,17 +25,22 @@ class MempoolLimit(BitcoinTestFramework): # Let node 3 hold one more transaction ["-debug=mempool", '-mempooltxcostlimit=12000'], # 3 transactions at min cost ] - return start_nodes(4, self.options.tmpdir, extra_args) + return start_nodes(self.num_nodes, self.options.tmpdir, extra_args) def check_mempool_sizes(self, expected_size, check_node3=True): - for i in range(4 if check_node3 else 3): + for i in range(self.num_nodes if check_node3 else self.num_nodes - 1): mempool = self.nodes[i].getrawmempool() if len(mempool) != expected_size: # print all nodes' mempools before failing - for i in range(4): + for i in range(self.num_nodes): print("Mempool for node {}: {}".format(i, mempool)) fail("Fail: Mempool for node {}: size={}, expected={}".format(i, len(mempool), expected_size)) + def __init__(self): + super().__init__() + self.setup_clean_chain = True + self.num_nodes = 4 + def run_test(self): print("Mining blocks...") self.sync_all() diff --git a/qa/rpc-tests/mempool_nu_activation.py b/qa/rpc-tests/mempool_nu_activation.py index aa402a70a..d7c0bdac6 100755 --- a/qa/rpc-tests/mempool_nu_activation.py +++ b/qa/rpc-tests/mempool_nu_activation.py @@ -5,7 +5,7 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( - assert_equal, assert_true, initialize_chain_clean, + assert_equal, assert_true, start_node, connect_nodes, wait_and_assert_operationid_status, get_coinbase_address ) @@ -17,6 +17,11 @@ class MempoolUpgradeActivationTest(BitcoinTestFramework): alert_filename = None # Set by setup_network + def __init__(self): + super().__init__() + self.num_nodes = 2 + self.setup_clean_chain = True + def setup_network(self): args = ["-checkmempool", "-debug=mempool", "-blockmaxsize=4000", "-nuparams=2bb40e60:200", # Blossom @@ -28,10 +33,6 @@ class MempoolUpgradeActivationTest(BitcoinTestFramework): self.is_network_split = False self.sync_all - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 2) - def run_test(self): self.nodes[1].generate(100) self.sync_all() diff --git a/qa/rpc-tests/mempool_reorg.py b/qa/rpc-tests/mempool_reorg.py index 1dce011bf..e809195dc 100755 --- a/qa/rpc-tests/mempool_reorg.py +++ b/qa/rpc-tests/mempool_reorg.py @@ -15,6 +15,10 @@ from test_framework.util import assert_equal, assert_raises, start_node, connect # Create one-input, one-output, no-fee transaction: class MempoolCoinbaseTest(BitcoinTestFramework): + def __init__(self): + super().__init__() + self.num_nodes = 2 + self.setup_clean_chain = False alert_filename = None # Set by setup_network diff --git a/qa/rpc-tests/mempool_resurrect_test.py b/qa/rpc-tests/mempool_resurrect_test.py index 0cb207133..ef11b29da 100755 --- a/qa/rpc-tests/mempool_resurrect_test.py +++ b/qa/rpc-tests/mempool_resurrect_test.py @@ -15,6 +15,11 @@ from test_framework.util import assert_equal, start_node # Create one-input, one-output, no-fee transaction: class MempoolCoinbaseTest(BitcoinTestFramework): + def __init__(self): + super().__init__() + self.num_nodes = 1 + self.setup_clean_chain = False + def setup_network(self): # Just need one node for this test args = ["-checkmempool", "-debug=mempool"] diff --git a/qa/rpc-tests/mempool_spendcoinbase.py b/qa/rpc-tests/mempool_spendcoinbase.py index 208399332..b692cd513 100755 --- a/qa/rpc-tests/mempool_spendcoinbase.py +++ b/qa/rpc-tests/mempool_spendcoinbase.py @@ -22,6 +22,11 @@ from test_framework.util import assert_equal, assert_greater_than, assert_raises # Create one-input, one-output, no-fee transaction: class MempoolSpendCoinbaseTest(BitcoinTestFramework): + def __init__(self): + super().__init__() + self.num_nodes = 1 + self.setup_clean_chain = False + def setup_network(self): # Just need one node for this test args = ["-checkmempool", "-debug=mempool"] diff --git a/qa/rpc-tests/mempool_tx_expiry.py b/qa/rpc-tests/mempool_tx_expiry.py index 6d3f28602..f3cff7ba3 100755 --- a/qa/rpc-tests/mempool_tx_expiry.py +++ b/qa/rpc-tests/mempool_tx_expiry.py @@ -21,11 +21,11 @@ TX_EXPIRY_DELTA = 10 class MempoolTxExpiryTest(BitcoinTestFramework): def setup_nodes(self): - return start_nodes(4, self.options.tmpdir, + return start_nodes(self.num_nodes, self.options.tmpdir, [[ "-txexpirydelta=%d" % TX_EXPIRY_DELTA, "-debug=mempool" - ]] * 4) + ]] * self.num_nodes) # Test before, at, and after expiry block # chain is at block height 199 when run_test executes diff --git a/qa/rpc-tests/merkle_blocks.py b/qa/rpc-tests/merkle_blocks.py index 85ff0924e..4b7f14680 100755 --- a/qa/rpc-tests/merkle_blocks.py +++ b/qa/rpc-tests/merkle_blocks.py @@ -11,14 +11,15 @@ import string from test_framework.test_framework import BitcoinTestFramework from test_framework.authproxy import JSONRPCException from test_framework.util import assert_equal, assert_raises, \ - initialize_chain_clean, start_node, connect_nodes + start_node, connect_nodes class MerkleBlockTest(BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) + def __init__(self): + super().__init__() + self.setup_clean_chain = True + self.num_nodes = 4 def setup_network(self): self.nodes = [] diff --git a/qa/rpc-tests/mining_shielded_coinbase.py b/qa/rpc-tests/mining_shielded_coinbase.py index bef3493be..83c344011 100755 --- a/qa/rpc-tests/mining_shielded_coinbase.py +++ b/qa/rpc-tests/mining_shielded_coinbase.py @@ -14,7 +14,6 @@ from test_framework.util import ( assert_raises, bitcoind_processes, connect_nodes, - initialize_chain_clean, start_node, wait_and_assert_operationid_status, check_node_log, @@ -22,9 +21,10 @@ from test_framework.util import ( class ShieldCoinbaseTest (BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) + def __init__(self): + super().__init__() + self.num_nodes = 4 + self.setup_clean_chain = True def start_node_with(self, index, extra_args=[]): args = [ diff --git a/qa/rpc-tests/multi_rpc.py b/qa/rpc-tests/multi_rpc.py index bd1b79fd2..74359f553 100755 --- a/qa/rpc-tests/multi_rpc.py +++ b/qa/rpc-tests/multi_rpc.py @@ -8,24 +8,21 @@ # from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import ( - assert_equal, - initialize_chain, - start_nodes, - str_to_b64str, -) -import os +from test_framework.util import str_to_b64str, assert_equal +import os import http.client import urllib.parse class HTTPBasicsTest (BitcoinTestFramework): - def setup_nodes(self): - return start_nodes(4, self.options.tmpdir) + + def __init__(self): + super().__init__() + self.setup_clean_chain = False + self.num_nodes = 1 def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain(self.options.tmpdir) + super().setup_chain() #Append rpcauth to zcash.conf before initialization rpcauth = "rpcauth=rt:93648e835a54c573682c2eb19f882535$7681e9c5b74bdd85e78166031d2058e1069b3ed7ed967c93fc63abba06f31144" rpcauth2 = "rpcauth=rt2:f8607b1a88861fac29dfccf9b52ff9f$ff36a0c23c8c62b4846112e50fa888416e94c17bfd4c42f88fd8f55ec6a3137e" @@ -33,6 +30,9 @@ class HTTPBasicsTest (BitcoinTestFramework): f.write(rpcauth+"\n") f.write(rpcauth2+"\n") + def setup_network(self): + self.nodes = self.setup_nodes() + def run_test(self): ################################################## diff --git a/qa/rpc-tests/nodehandling.py b/qa/rpc-tests/nodehandling.py index fb32cd2cc..8b79c2f46 100755 --- a/qa/rpc-tests/nodehandling.py +++ b/qa/rpc-tests/nodehandling.py @@ -14,6 +14,12 @@ import time import urllib.parse class NodeHandlingTest (BitcoinTestFramework): + + def __init__(self): + super().__init__() + self.num_nodes = 4 + self.setup_clean_chain = False + def run_test(self): ########################### # setban/listbanned tests # diff --git a/qa/rpc-tests/p2p-acceptblock.py b/qa/rpc-tests/p2p-acceptblock.py index 741c3348e..98ce9ba3d 100755 --- a/qa/rpc-tests/p2p-acceptblock.py +++ b/qa/rpc-tests/p2p-acceptblock.py @@ -7,7 +7,7 @@ from test_framework.mininode import CBlockHeader, CInv, NodeConn, NodeConnCB, \ NetworkThread, msg_block, msg_headers, msg_inv, msg_ping, msg_pong, \ mininode_lock from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, initialize_chain_clean, \ +from test_framework.util import assert_equal, \ start_node, p2p_port from test_framework.blocktools import create_block, create_coinbase @@ -117,8 +117,10 @@ class AcceptBlockTest(BitcoinTestFramework): default=os.getenv("BITCOIND", "bitcoind"), help="bitcoind binary to test") - def setup_chain(self): - initialize_chain_clean(self.options.tmpdir, 2) + def __init__(self): + super().__init__() + self.setup_clean_chain = True + self.num_nodes = 2 def setup_network(self): # Node0 will be used to test behavior of processing unrequested blocks diff --git a/qa/rpc-tests/p2p-fullblocktest.py b/qa/rpc-tests/p2p-fullblocktest.py index 433374850..b8db50487 100755 --- a/qa/rpc-tests/p2p-fullblocktest.py +++ b/qa/rpc-tests/p2p-fullblocktest.py @@ -38,6 +38,7 @@ class FullBlockTest(ComparisonTestFramework): ''' Can either run this test as 1 node with expected answers, or two and compare them. Change the "outcome" variable from each TestInstance object to only do the comparison. ''' def __init__(self): + super().__init__() self.num_nodes = 1 self.block_heights = {} self.coinbase_key = CECKey() diff --git a/qa/rpc-tests/p2p_txexpiringsoon.py b/qa/rpc-tests/p2p_txexpiringsoon.py index 3d5d10a78..6472b6fba 100755 --- a/qa/rpc-tests/p2p_txexpiringsoon.py +++ b/qa/rpc-tests/p2p_txexpiringsoon.py @@ -8,18 +8,19 @@ from test_framework.mininode import NodeConn, NetworkThread, CInv, \ msg_mempool, msg_getdata, msg_tx, mininode_lock, SAPLING_PROTO_VERSION from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, connect_nodes_bi, fail, \ - initialize_chain_clean, p2p_port, start_nodes, sync_blocks, sync_mempools + p2p_port, start_nodes, sync_blocks, sync_mempools from tx_expiry_helper import TestNode, create_transaction class TxExpiringSoonTest(BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory " + self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 3) + def __init__(self): + super().__init__() + self.num_nodes = 3 + self.setup_clean_chain = True def setup_network(self): - self.nodes = start_nodes(3, self.options.tmpdir) + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir) connect_nodes_bi(self.nodes, 0, 1) # We don't connect node 2 diff --git a/qa/rpc-tests/p2p_txexpiry_dos.py b/qa/rpc-tests/p2p_txexpiry_dos.py index 0fe5bf698..e1b7e9e1e 100755 --- a/qa/rpc-tests/p2p_txexpiry_dos.py +++ b/qa/rpc-tests/p2p_txexpiry_dos.py @@ -6,8 +6,7 @@ from test_framework.mininode import NodeConn, NetworkThread, \ msg_tx, SAPLING_PROTO_VERSION from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import initialize_chain_clean, start_nodes, \ - p2p_port, assert_equal +from test_framework.util import start_nodes, p2p_port, assert_equal from tx_expiry_helper import TestNode, create_transaction import time @@ -15,12 +14,13 @@ import time class TxExpiryDoSTest(BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory " + self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 1) + def __init__(self): + super().__init__() + self.num_nodes = 1 + self.setup_clean_chain = True def setup_network(self): - self.nodes = start_nodes(1, self.options.tmpdir) + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir) def run_test(self): test_node = TestNode() diff --git a/qa/rpc-tests/paymentdisclosure.py b/qa/rpc-tests/paymentdisclosure.py index 959de48cf..9330f6797 100755 --- a/qa/rpc-tests/paymentdisclosure.py +++ b/qa/rpc-tests/paymentdisclosure.py @@ -5,7 +5,7 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.authproxy import JSONRPCException -from test_framework.util import assert_equal, initialize_chain_clean, \ +from test_framework.util import assert_equal, \ start_node, connect_nodes_bi, wait_and_assert_operationid_status, \ get_coinbase_address @@ -13,9 +13,10 @@ from decimal import Decimal class PaymentDisclosureTest (BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) + def __init__(self): + super().__init__() + self.num_nodes = 3 + self.setup_clean_chain = True def setup_network(self, split=False): args = ['-debug=zrpcunsafe,paymentdisclosure', '-experimentalfeatures', '-paymentdisclosure', '-txindex=1'] diff --git a/qa/rpc-tests/post_heartwood_rollback.py b/qa/rpc-tests/post_heartwood_rollback.py index 0310d7849..4f11545ea 100755 --- a/qa/rpc-tests/post_heartwood_rollback.py +++ b/qa/rpc-tests/post_heartwood_rollback.py @@ -12,7 +12,6 @@ from test_framework.util import ( assert_equal, bitcoind_processes, connect_nodes_bi, - initialize_chain, nuparams, start_node, start_nodes, @@ -29,12 +28,8 @@ NO_CANOPY = [nuparams(BLOSSOM_BRANCH_ID, 205), nuparams(HEARTWOOD_BRANCH_ID, 21 class PostHeartwoodRollbackTest (BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain(self.options.tmpdir) - def setup_nodes(self): - return start_nodes(4, self.options.tmpdir, extra_args=[ + return start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[ HAS_CANOPY, HAS_CANOPY, NO_CANOPY, diff --git a/qa/rpc-tests/proxy_test.py b/qa/rpc-tests/proxy_test.py index af4595d14..d26f90f7c 100755 --- a/qa/rpc-tests/proxy_test.py +++ b/qa/rpc-tests/proxy_test.py @@ -36,6 +36,10 @@ addnode connect to generic DNS name class ProxyTest(BitcoinTestFramework): def __init__(self): + super().__init__() + self.num_nodes = 4 + self.setup_clean_chain = False + self.have_ipv6 = test_ipv6_local() # Create two proxies on different ports # ... one unauthenticated @@ -77,7 +81,7 @@ class ProxyTest(BitcoinTestFramework): ] if self.have_ipv6: args[3] = ['-listen', '-debug=net', '-debug=proxy', '-proxy=[%s]:%i' % (self.conf3.addr),'-proxyrandomize=0', '-noonion'] - return start_nodes(4, self.options.tmpdir, extra_args=args) + return start_nodes(self.num_nodes, self.options.tmpdir, extra_args=args) def node_test(self, node, proxies, auth, test_onion=True): rv = [] diff --git a/qa/rpc-tests/pruning.py b/qa/rpc-tests/pruning.py index 7cad82846..cbebeca6b 100755 --- a/qa/rpc-tests/pruning.py +++ b/qa/rpc-tests/pruning.py @@ -13,7 +13,7 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.authproxy import JSONRPCException -from test_framework.util import initialize_chain_clean, start_node, \ +from test_framework.util import start_node, \ connect_nodes, stop_node, sync_blocks import os.path @@ -25,6 +25,10 @@ def calc_usage(blockdir): class PruneTest(BitcoinTestFramework): def __init__(self): + super().__init__() + self.setup_clean_chain = True + self.num_nodes = 3 + self.utxo = [] self.address = ["",""] @@ -46,10 +50,6 @@ class PruneTest(BitcoinTestFramework): self.txouts = self.txouts + script_pubkey - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 3) - def setup_network(self): self.nodes = [] self.is_network_split = False diff --git a/qa/rpc-tests/rawtransactions.py b/qa/rpc-tests/rawtransactions.py index 707a8bb17..0c5ae32fb 100755 --- a/qa/rpc-tests/rawtransactions.py +++ b/qa/rpc-tests/rawtransactions.py @@ -10,7 +10,7 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.authproxy import JSONRPCException -from test_framework.util import assert_equal, initialize_chain_clean, \ +from test_framework.util import assert_equal, \ start_nodes, connect_nodes_bi, assert_raises from decimal import Decimal @@ -18,12 +18,13 @@ from decimal import Decimal # Create one-input, one-output, no-fee transaction: class RawTransactionsTest(BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 3) + def __init__(self): + super().__init__() + self.setup_clean_chain = True + self.num_nodes = 3 def setup_network(self, split=False): - self.nodes = start_nodes(3, self.options.tmpdir) + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir) #connect to a local machine for debugging #url = "http://bitcoinrpc:DP6DvqZtqXarpeNWyN3LZTFchCCyCUuHwNF7E8pX99x1@%s:%d" % ('127.0.0.1', 18232) diff --git a/qa/rpc-tests/receivedby.py b/qa/rpc-tests/receivedby.py index 41db262b4..e124b0fde 100755 --- a/qa/rpc-tests/receivedby.py +++ b/qa/rpc-tests/receivedby.py @@ -53,6 +53,11 @@ def check_array_result(object_array, to_match, expected, should_not_find = False class ReceivedByTest(BitcoinTestFramework): + def __init__(self): + super().__init__() + self.num_nodes = 4 + self.setup_clean_chain = False + def run_test(self): ''' listreceivedbyaddress Test diff --git a/qa/rpc-tests/reindex.py b/qa/rpc-tests/reindex.py index b66257a51..432d1e002 100755 --- a/qa/rpc-tests/reindex.py +++ b/qa/rpc-tests/reindex.py @@ -8,15 +8,16 @@ # from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, initialize_chain_clean, \ +from test_framework.util import assert_equal, \ start_node, stop_node, wait_bitcoinds class ReindexTest(BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 1) + def __init__(self): + super().__init__() + self.setup_clean_chain = True + self.num_nodes = 1 def setup_network(self): self.nodes = [] diff --git a/qa/rpc-tests/remove_sprout_shielding.py b/qa/rpc-tests/remove_sprout_shielding.py index 2aa5bbcae..29ff2acc9 100755 --- a/qa/rpc-tests/remove_sprout_shielding.py +++ b/qa/rpc-tests/remove_sprout_shielding.py @@ -8,7 +8,6 @@ from test_framework.authproxy import JSONRPCException from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, - initialize_chain, start_nodes, get_coinbase_address, wait_and_assert_operationid_status, nuparams, BLOSSOM_BRANCH_ID, HEARTWOOD_BRANCH_ID, CANOPY_BRANCH_ID @@ -23,12 +22,8 @@ HAS_CANOPY = ['-nurejectoldversions=false', ] class RemoveSproutShieldingTest (BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain(self.options.tmpdir) - def setup_nodes(self): - return start_nodes(4, self.options.tmpdir, extra_args=[HAS_CANOPY]*4) + return start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[HAS_CANOPY] * self.num_nodes) def run_test (self): diff --git a/qa/rpc-tests/rest.py b/qa/rpc-tests/rest.py index c6e266afe..bcc7ef9ad 100755 --- a/qa/rpc-tests/rest.py +++ b/qa/rpc-tests/rest.py @@ -9,7 +9,7 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, assert_greater_than, \ - initialize_chain_clean, start_nodes, connect_nodes_bi + start_nodes, connect_nodes_bi import struct import binascii @@ -51,12 +51,13 @@ def http_post_call(host, port, path, requestdata = '', response_object = 0): class RESTTest (BitcoinTestFramework): FORMAT_SEPARATOR = "." - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 3) + def __init__(self): + super().__init__() + self.setup_clean_chain = True + self.num_nodes = 3 def setup_network(self, split=False): - self.nodes = start_nodes(3, self.options.tmpdir) + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir) connect_nodes_bi(self.nodes,0,1) connect_nodes_bi(self.nodes,1,2) connect_nodes_bi(self.nodes,0,2) diff --git a/qa/rpc-tests/rewind_index.py b/qa/rpc-tests/rewind_index.py index 27d55891f..00816822d 100755 --- a/qa/rpc-tests/rewind_index.py +++ b/qa/rpc-tests/rewind_index.py @@ -4,7 +4,7 @@ # file COPYING or https://www.opensource.org/licenses/mit-license.php . from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, initialize_chain_clean, \ +from test_framework.util import assert_equal, \ start_nodes, start_node, connect_nodes_bi, bitcoind_processes, \ nuparams, OVERWINTER_BRANCH_ID, SAPLING_BRANCH_ID @@ -15,15 +15,16 @@ FAKE_OVERWINTER = [nuparams(OVERWINTER_BRANCH_ID, 10), nuparams(SAPLING_BRANCH_I class RewindBlockIndexTest (BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 3) + def __init__(self): + super().__init__() + self.num_nodes = 3 + self.setup_clean_chain = True def setup_network(self, split=False): # Node 0 - Overwinter, then Sprout, then Overwinter again # Node 1 - Sprout # Node 2 - Overwinter - self.nodes = start_nodes(3, self.options.tmpdir, extra_args=[ + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[ FAKE_OVERWINTER, FAKE_SPROUT, FAKE_OVERWINTER, diff --git a/qa/rpc-tests/rpcbind_test.py b/qa/rpc-tests/rpcbind_test.py index afb2f04db..8c877464e 100755 --- a/qa/rpc-tests/rpcbind_test.py +++ b/qa/rpc-tests/rpcbind_test.py @@ -37,7 +37,7 @@ def run_bind_test(tmpdir, allow_ips, connect_to, addresses, expected): if allow_ips: base_args += ['-rpcallowip=' + x for x in allow_ips] binds = ['-rpcbind='+addr for addr in addresses] - nodes = start_nodes(1, tmpdir, [base_args + binds], connect_to) + nodes = start_nodes(self.num_nodes, tmpdir, [base_args + binds], connect_to) try: pid = bitcoind_processes[0].pid assert_equal(set(get_bind_addrs(pid)), set(expected)) @@ -51,7 +51,7 @@ def run_allowip_test(tmpdir, allow_ips, rpchost, rpcport): at a non-localhost IP. ''' base_args = ['-disablewallet', '-nolisten'] + ['-rpcallowip='+x for x in allow_ips] - nodes = start_nodes(1, tmpdir, [base_args]) + nodes = start_nodes(self.num_nodes, tmpdir, [base_args]) try: # connect to node through non-loopback interface url = "http://rt:rt@%s:%d" % (rpchost, rpcport,) diff --git a/qa/rpc-tests/sapling_rewind_check.py b/qa/rpc-tests/sapling_rewind_check.py index 05c0bae72..03065aac0 100755 --- a/qa/rpc-tests/sapling_rewind_check.py +++ b/qa/rpc-tests/sapling_rewind_check.py @@ -28,7 +28,7 @@ length computation (40b5d5e3ea4b602c34c4efaba0b9f6171dddfef5) corrects the issue from test_framework.test_framework import BitcoinTestFramework from test_framework.util import (assert_equal, assert_true, - initialize_chain_clean, start_nodes, start_node, connect_nodes_bi, + start_nodes, start_node, connect_nodes_bi, bitcoind_processes, nuparams, OVERWINTER_BRANCH_ID, SAPLING_BRANCH_ID) @@ -39,14 +39,15 @@ HAS_SAPLING = [nuparams(OVERWINTER_BRANCH_ID, 10), nuparams(SAPLING_BRANCH_ID, 1 NO_SAPLING = [nuparams(OVERWINTER_BRANCH_ID, 10), nuparams(SAPLING_BRANCH_ID, 150)] class SaplingRewindTest(BitcoinTestFramework): - def setup_chain(self): - logging.info("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) + def __init__(self): + super().__init__() + self.num_nodes = 3 + self.setup_clean_chain = True # This mirrors how the network was setup in the bash test def setup_network(self, split=False): logging.info("Initializing the network in "+self.options.tmpdir) - self.nodes = start_nodes(3, self.options.tmpdir, extra_args=[ + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[ HAS_SAPLING, # The first two nodes have a correct view of the network, HAS_SAPLING, # the third will rewind after upgrading. NO_SAPLING diff --git a/qa/rpc-tests/shorter_block_times.py b/qa/rpc-tests/shorter_block_times.py index e57602cc4..d3ff5e079 100755 --- a/qa/rpc-tests/shorter_block_times.py +++ b/qa/rpc-tests/shorter_block_times.py @@ -8,21 +8,21 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( assert_equal, get_coinbase_address, - initialize_chain_clean, start_nodes, wait_and_assert_operationid_status, ) class ShorterBlockTimes(BitcoinTestFramework): - def setup_nodes(self): - return start_nodes(4, self.options.tmpdir, [[ - '-nuparams=2bb40e60:106', # Blossom - ]] * 4) + def __init__(self): + super().__init__() + self.num_nodes = 4 + self.setup_clean_chain = True - def setup_chain(self): - print("Initializing test directory " + self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) + def setup_nodes(self): + return start_nodes(self.num_nodes, self.options.tmpdir, [[ + '-nuparams=2bb40e60:106', # Blossom + ]] * self.num_nodes) def run_test(self): print("Mining blocks...") diff --git a/qa/rpc-tests/signrawtransactions.py b/qa/rpc-tests/signrawtransactions.py index 97ec39384..2c8e36817 100755 --- a/qa/rpc-tests/signrawtransactions.py +++ b/qa/rpc-tests/signrawtransactions.py @@ -4,19 +4,19 @@ # file COPYING or https://www.opensource.org/licenses/mit-license.php . from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import assert_equal, initialize_chain_clean, \ - start_nodes +from test_framework.util import assert_equal, start_nodes class SignRawTransactionsTest(BitcoinTestFramework): """Tests transaction signing via RPC command "signrawtransaction".""" - def setup_chain(self): - print('Initializing test directory ' + self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 1) + def __init__(self): + super().__init__() + self.setup_clean_chain = True + self.num_nodes = 1 def setup_network(self, split=False): - self.nodes = start_nodes(1, self.options.tmpdir) + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir) self.is_network_split = False def successful_signing_test(self): diff --git a/qa/rpc-tests/smartfees.py b/qa/rpc-tests/smartfees.py index 6ebaf4355..44086fa4f 100755 --- a/qa/rpc-tests/smartfees.py +++ b/qa/rpc-tests/smartfees.py @@ -142,6 +142,11 @@ def check_estimates(node, fees_seen, max_invalid, print_estimates = True): class EstimateFeeTest(BitcoinTestFramework): + def __init__(self): + super().__init__() + self.num_nodes = 3 + self.setup_clean_chain = False + def setup_network(self): ''' We'll setup the network to have 3 nodes that all mine with different parameters. diff --git a/qa/rpc-tests/sprout_sapling_migration.py b/qa/rpc-tests/sprout_sapling_migration.py index 56bc28839..ebc96c58f 100755 --- a/qa/rpc-tests/sprout_sapling_migration.py +++ b/qa/rpc-tests/sprout_sapling_migration.py @@ -6,7 +6,7 @@ from decimal import Decimal from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, assert_true, get_coinbase_address, \ - initialize_chain_clean, start_nodes, wait_and_assert_operationid_status, \ + start_nodes, wait_and_assert_operationid_status, \ wait_and_assert_operationid_status_result SAPLING_ADDR = 'zregtestsapling1ssqj3f3majnl270985gqcdqedd9t4nlttjqskccwevj2v20sc25deqspv3masufnwcdy67cydyy' @@ -49,9 +49,14 @@ def check_migration_status(node, destination_address, migration_state): class SproutSaplingMigration(BitcoinTestFramework): + def __init__(self): + super().__init__() + self.num_nodes = 4 + self.setup_clean_chain = True + def setup_nodes(self): extra_args = [[ - ]] * 4 + ]] * self.num_nodes # Add migration parameters to nodes[0] extra_args[0] = extra_args[0] + [ '-migration', @@ -60,11 +65,7 @@ class SproutSaplingMigration(BitcoinTestFramework): ] assert_equal(3, len(extra_args[0])) assert_equal(0, len(extra_args[1])) - return start_nodes(4, self.options.tmpdir, extra_args) - - def setup_chain(self): - print("Initializing test directory " + self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) + return start_nodes(self.num_nodes, self.options.tmpdir, extra_args) def run_migration_test(self, node, sproutAddr, saplingAddr, target_height): # Make sure we are in a good state to run the test diff --git a/qa/rpc-tests/test_framework/test_framework.py b/qa/rpc-tests/test_framework/test_framework.py index a8a3da5e8..1ab9e3024 100755 --- a/qa/rpc-tests/test_framework/test_framework.py +++ b/qa/rpc-tests/test_framework/test_framework.py @@ -16,7 +16,6 @@ import traceback from .authproxy import JSONRPCException from .util import ( initialize_chain, - assert_equal, start_nodes, connect_nodes_bi, sync_blocks, @@ -32,21 +31,26 @@ from .util import ( class BitcoinTestFramework(object): - # These may be over-ridden by subclasses: + def __init__(self): + self.num_nodes = 4 + self.setup_clean_chain = False + self.nodes = None + def run_test(self): - for node in self.nodes: - assert_equal(node.getblockcount(), 200) - assert_equal(node.getbalance(), 25*10) + raise NotImplementedError def add_options(self, parser): pass def setup_chain(self): print("Initializing test directory "+self.options.tmpdir) - initialize_chain(self.options.tmpdir) + if self.setup_clean_chain: + initialize_chain_clean(self.options.tmpdir, self.num_nodes) + else: + initialize_chain(self.options.tmpdir, self.num_nodes) def setup_nodes(self): - return start_nodes(4, self.options.tmpdir) + return start_nodes(self.num_nodes, self.options.tmpdir) def setup_network(self, split = False): self.nodes = self.setup_nodes() @@ -181,9 +185,10 @@ class BitcoinTestFramework(object): class ComparisonTestFramework(BitcoinTestFramework): - # Can override the num_nodes variable to indicate how many nodes to run. def __init__(self): + super().__init__() self.num_nodes = 2 + self.setup_clean_chain = True def add_options(self, parser): parser.add_option("--testbinary", dest="testbinary", @@ -193,10 +198,6 @@ class ComparisonTestFramework(BitcoinTestFramework): default=os.getenv("BITCOIND", "bitcoind"), help="bitcoind binary to use for reference nodes (if any)") - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, self.num_nodes) - def setup_network(self): self.nodes = start_nodes( self.num_nodes, self.options.tmpdir, diff --git a/qa/rpc-tests/test_framework/util.py b/qa/rpc-tests/test_framework/util.py index f05a2edd5..c8036a44f 100644 --- a/qa/rpc-tests/test_framework/util.py +++ b/qa/rpc-tests/test_framework/util.py @@ -186,10 +186,10 @@ def wait_for_bitcoind_start(process, url, i): raise # unknown JSON RPC exception time.sleep(0.25) -def initialize_chain(test_dir): +def initialize_chain(test_dir, num_nodes): """ - Create (or copy from cache) a 200-block-long chain and - 4 wallets. + Create a cache of a 200-block-long chain (with wallet) for MAX_NODES + Afterward, create num_nodes copies from the cache """ # Due to the consensus change fix for the timejacking attack, we need to @@ -213,18 +213,22 @@ def initialize_chain(test_dir): print("initialize_chain(): Removing stale cache") shutil.rmtree("cache") - if (not os.path.isdir(os.path.join("cache","node0")) - or not os.path.isdir(os.path.join("cache","node1")) - or not os.path.isdir(os.path.join("cache","node2")) - or not os.path.isdir(os.path.join("cache","node3"))): + assert num_nodes <= MAX_NODES + create_cache = False + for i in range(MAX_NODES): + if not os.path.isdir(os.path.join('cache', 'node'+str(i))): + create_cache = True + break + + if create_cache: #find and delete old cache directories if any exist - for i in range(4): + for i in range(MAX_NODES): if os.path.isdir(os.path.join("cache","node"+str(i))): shutil.rmtree(os.path.join("cache","node"+str(i))) # Create cache directories, run bitcoinds: - for i in range(4): + for i in range(MAX_NODES): datadir=initialize_datadir("cache", i) args = [ os.getenv("BITCOIND", "bitcoind"), "-keypool=1", "-datadir="+datadir, "-discover=0" ] args.extend([ @@ -241,15 +245,18 @@ def initialize_chain(test_dir): print("initialize_chain: RPC successfully started") rpcs = [] - for i in range(4): + for i in range(MAX_NODES): try: rpcs.append(get_rpc_proxy(rpc_url(i), i)) except: sys.stderr.write("Error connecting to "+rpc_url(i)+"\n") sys.exit(1) - # Create a 200-block-long chain; each of the 4 nodes + # Create a 200-block-long chain; each of the 4 first nodes # gets 25 mature blocks and 25 immature. + # Note: To preserve compatibility with older versions of + # initialize_chain, only 4 nodes will generate coins. + # # Blocks are created with timestamps 2.5 minutes apart (matching the # chain defaulting above to Sapling active), starting 200 * 2.5 minutes # before the current time. @@ -268,13 +275,13 @@ def initialize_chain(test_dir): # Shut them down, and clean up cache directories: stop_nodes(rpcs) wait_bitcoinds() - for i in range(4): + for i in range(MAX_NODES): os.remove(log_filename("cache", i, "debug.log")) os.remove(log_filename("cache", i, "db.log")) os.remove(log_filename("cache", i, "peers.dat")) os.remove(log_filename("cache", i, "fee_estimates.dat")) - for i in range(4): + for i in range(num_nodes): from_dir = os.path.join("cache", "node"+str(i)) to_dir = os.path.join(test_dir, "node"+str(i)) shutil.copytree(from_dir, to_dir) diff --git a/qa/rpc-tests/turnstile.py b/qa/rpc-tests/turnstile.py index 18cd34629..4b02b9619 100755 --- a/qa/rpc-tests/turnstile.py +++ b/qa/rpc-tests/turnstile.py @@ -32,7 +32,7 @@ from test_framework.util import ( get_coinbase_address, start_node, start_nodes, sync_blocks, sync_mempools, - initialize_chain_clean, connect_nodes_bi, + connect_nodes_bi, wait_and_assert_operationid_status, bitcoind_processes, check_node_log @@ -44,12 +44,13 @@ TURNSTILE_ARGS = ['-experimentalfeatures', class TurnstileTest (BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory " + self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 3) + def __init__(self): + super().__init__() + self.num_nodes = 3 + self.setup_clean_chain = True def setup_network(self, split=False): - self.nodes = start_nodes(3, self.options.tmpdir) + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir) connect_nodes_bi(self.nodes,0,1) connect_nodes_bi(self.nodes,1,2) self.is_network_split=False diff --git a/qa/rpc-tests/txn_doublespend.py b/qa/rpc-tests/txn_doublespend.py index 2751fc70e..12d7f76dc 100755 --- a/qa/rpc-tests/txn_doublespend.py +++ b/qa/rpc-tests/txn_doublespend.py @@ -14,6 +14,11 @@ from test_framework.util import assert_equal, connect_nodes, \ class TxnMallTest(BitcoinTestFramework): + def __init__(self): + super().__init__() + self.num_nodes = 4 + self.setup_clean_chain = False + 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/qa/rpc-tests/wallet.py b/qa/rpc-tests/wallet.py index b09316716..310d9b44b 100755 --- a/qa/rpc-tests/wallet.py +++ b/qa/rpc-tests/wallet.py @@ -6,7 +6,7 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.authproxy import JSONRPCException from test_framework.util import assert_equal, assert_greater_than, \ - initialize_chain_clean, start_nodes, start_node, connect_nodes_bi, \ + start_nodes, start_node, connect_nodes_bi, \ stop_nodes, sync_blocks, sync_mempools, wait_and_assert_operationid_status, \ wait_bitcoinds @@ -14,9 +14,10 @@ from decimal import Decimal class WalletTest (BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) + def __init__(self): + super().__init__() + self.setup_clean_chain = True + self.num_nodes = 4 def setup_network(self, split=False): self.nodes = start_nodes(3, self.options.tmpdir) diff --git a/qa/rpc-tests/wallet_nullifiers.py b/qa/rpc-tests/wallet_nullifiers.py index 07c1f1d0d..ee62e5a96 100755 --- a/qa/rpc-tests/wallet_nullifiers.py +++ b/qa/rpc-tests/wallet_nullifiers.py @@ -13,8 +13,8 @@ from decimal import Decimal class WalletNullifiersTest (BitcoinTestFramework): def setup_nodes(self): - return start_nodes(4, self.options.tmpdir, - extra_args=[['-experimentalfeatures', '-developerencryptwallet']] * 4) + return start_nodes(self.num_nodes, self.options.tmpdir, + extra_args=[['-experimentalfeatures', '-developerencryptwallet']] * self.num_nodes) def run_test (self): # add zaddr to node 0 diff --git a/qa/rpc-tests/wallet_overwintertx.py b/qa/rpc-tests/wallet_overwintertx.py index 218de5109..78b7ce1fb 100755 --- a/qa/rpc-tests/wallet_overwintertx.py +++ b/qa/rpc-tests/wallet_overwintertx.py @@ -9,7 +9,6 @@ from test_framework.util import ( assert_greater_than, connect_nodes_bi, get_coinbase_address, - initialize_chain_clean, start_nodes, wait_and_assert_operationid_status, ) @@ -19,16 +18,17 @@ from decimal import Decimal class WalletOverwinterTxTest (BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) + def __init__(self): + super().__init__() + self.num_nodes = 4 + self.setup_clean_chain = True def setup_network(self, split=False): - self.nodes = start_nodes(4, self.options.tmpdir, extra_args=[[ + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[[ "-nuparams=2bb40e60:200", "-debug=zrpcunsafe", "-txindex", - ]] * 4 ) + ]] * self.num_nodes) connect_nodes_bi(self.nodes,0,1) connect_nodes_bi(self.nodes,1,2) connect_nodes_bi(self.nodes,0,2) diff --git a/qa/rpc-tests/wallet_sapling.py b/qa/rpc-tests/wallet_sapling.py index 26a1b68ea..7f9d52b5f 100755 --- a/qa/rpc-tests/wallet_sapling.py +++ b/qa/rpc-tests/wallet_sapling.py @@ -8,7 +8,6 @@ from test_framework.authproxy import JSONRPCException from test_framework.util import ( assert_equal, get_coinbase_address, - start_nodes, wait_and_assert_operationid_status, ) @@ -17,9 +16,6 @@ from decimal import Decimal # Test wallet behaviour with Sapling addresses class WalletSaplingTest(BitcoinTestFramework): - def setup_nodes(self): - return start_nodes(4, self.options.tmpdir) - def run_test(self): # Sanity-check the test harness assert_equal(self.nodes[0].getblockcount(), 200) diff --git a/qa/rpc-tests/walletbackup.py b/qa/rpc-tests/walletbackup.py index d22a26088..463fe63b0 100755 --- a/qa/rpc-tests/walletbackup.py +++ b/qa/rpc-tests/walletbackup.py @@ -35,7 +35,7 @@ and confirm again balances are correct. from test_framework.test_framework import BitcoinTestFramework from test_framework.authproxy import JSONRPCException -from test_framework.util import assert_equal, initialize_chain_clean, \ +from test_framework.util import assert_equal, \ start_nodes, start_node, connect_nodes, stop_node, \ sync_blocks, sync_mempools @@ -50,9 +50,10 @@ logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO, str class WalletBackupTest(BitcoinTestFramework): - def setup_chain(self): - logging.info("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 4) + def __init__(self): + super().__init__() + self.setup_clean_chain = True + self.num_nodes = 4 # This mirrors how the network was setup in the bash test def setup_network(self, split=False): @@ -63,7 +64,7 @@ class WalletBackupTest(BitcoinTestFramework): # nodes 1, 2,3 are spenders, let's give them a keypool=100 extra_args = [["-keypool=100", ed0], ["-keypool=100", ed1], ["-keypool=100", ed2], []] - self.nodes = start_nodes(4, self.options.tmpdir, extra_args) + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, extra_args) connect_nodes(self.nodes[0], 3) connect_nodes(self.nodes[1], 3) connect_nodes(self.nodes[2], 3) diff --git a/qa/rpc-tests/zapwallettxes.py b/qa/rpc-tests/zapwallettxes.py index 165b2451f..9985eb89b 100755 --- a/qa/rpc-tests/zapwallettxes.py +++ b/qa/rpc-tests/zapwallettxes.py @@ -5,18 +5,19 @@ from test_framework.test_framework import BitcoinTestFramework from test_framework.authproxy import JSONRPCException -from test_framework.util import assert_equal, initialize_chain_clean, \ +from test_framework.util import assert_equal, \ start_nodes, start_node, connect_nodes_bi, bitcoind_processes class ZapWalletTXesTest (BitcoinTestFramework): - def setup_chain(self): - print("Initializing test directory "+self.options.tmpdir) - initialize_chain_clean(self.options.tmpdir, 3) + def __init__(self): + super().__init__() + self.setup_clean_chain = True + self.num_nodes = 3 def setup_network(self, split=False): - self.nodes = start_nodes(3, self.options.tmpdir) + self.nodes = start_nodes(self.num_nodes, self.options.tmpdir) connect_nodes_bi(self.nodes,0,1) connect_nodes_bi(self.nodes,1,2) connect_nodes_bi(self.nodes,0,2) diff --git a/qa/rpc-tests/zcjoinsplit.py b/qa/rpc-tests/zcjoinsplit.py index 821c1256c..85af3c1fb 100755 --- a/qa/rpc-tests/zcjoinsplit.py +++ b/qa/rpc-tests/zcjoinsplit.py @@ -10,6 +10,10 @@ from test_framework.util import assert_equal, start_node, \ class JoinSplitTest(BitcoinTestFramework): + def __init__(self): + super().__init__() + self.num_nodes = 1 + def setup_network(self): self.nodes = [] self.is_network_split = False diff --git a/qa/rpc-tests/zmq_test.py b/qa/rpc-tests/zmq_test.py index 551ffaf09..c679bc8f7 100755 --- a/qa/rpc-tests/zmq_test.py +++ b/qa/rpc-tests/zmq_test.py @@ -15,6 +15,10 @@ import struct class ZMQTest(BitcoinTestFramework): + def __init__(self): + super().__init__() + self.num_nodes = 4 + port = 28332 def setup_nodes(self): @@ -23,7 +27,7 @@ class ZMQTest(BitcoinTestFramework): self.zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashblock") self.zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashtx") self.zmqSubSocket.connect("tcp://127.0.0.1:%i" % self.port) - return start_nodes(4, self.options.tmpdir, extra_args=[ + return start_nodes(self.num_nodes, self.options.tmpdir, extra_args=[ ['-zmqpubhashtx=tcp://127.0.0.1:'+str(self.port), '-zmqpubhashblock=tcp://127.0.0.1:'+str(self.port)], [], [],