Merge #8056: [qa] Remove hardcoded "4 nodes" from test_framework

fad68f7 [qa] Reduce node count for some tests (MarcoFalke)
fac9349 [qa] Remove hardcoded "4 nodes" from test_framework (MarcoFalke)
This commit is contained in:
MarcoFalke 2016-05-20 15:16:51 +02:00 committed by Alexander Block
parent 8eeaa4f212
commit bcecdcd8e9
58 changed files with 286 additions and 134 deletions

View File

@ -9,6 +9,10 @@ from test_framework.util import *
import urllib.parse import urllib.parse
class AbandonConflictTest(BitcoinTestFramework): class AbandonConflictTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 2
self.setup_clean_chain = False
def setup_network(self): def setup_network(self):
self.nodes = [] self.nodes = []

View File

@ -37,11 +37,12 @@ Mine 1 old version block, see that the node rejects.
class BIP65Test(ComparisonTestFramework): class BIP65Test(ComparisonTestFramework):
def __init__(self): def __init__(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
def setup_network(self): def setup_network(self):
# Must set the blockversion for this test # Must set the blockversion for this test
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', '-blockversion=3']], extra_args=[['-debug', '-whitelist=127.0.0.1', '-blockversion=3']],
binary=[self.options.testbinary]) binary=[self.options.testbinary])

View File

@ -11,6 +11,10 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * from test_framework.util import *
class BIP65Test(BitcoinTestFramework): class BIP65Test(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 3
self.setup_clean_chain = False
def setup_network(self): def setup_network(self):
self.nodes = [] self.nodes = []

View File

@ -94,11 +94,12 @@ def all_rlt_txs(txarray):
class BIP68_112_113Test(ComparisonTestFramework): class BIP68_112_113Test(ComparisonTestFramework):
def __init__(self): def __init__(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
def setup_network(self): def setup_network(self):
# Must set the blockversion for this test # Must set the blockversion for this test
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', '-blockversion=4']], extra_args=[['-debug', '-whitelist=127.0.0.1', '-blockversion=4']],
binary=[self.options.testbinary]) binary=[self.options.testbinary])

View File

@ -22,6 +22,10 @@ SEQUENCE_LOCKTIME_MASK = 0x0000ffff
NOT_FINAL_ERROR = "64: non-BIP68-final" NOT_FINAL_ERROR = "64: non-BIP68-final"
class BIP68Test(BitcoinTestFramework): class BIP68Test(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 2
self.setup_clean_chain = False
def setup_network(self): def setup_network(self):
self.nodes = [] self.nodes = []

View File

@ -32,10 +32,11 @@ test that enforcement has triggered
class BIP9SoftForksTest(ComparisonTestFramework): class BIP9SoftForksTest(ComparisonTestFramework):
def __init__(self): def __init__(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
def setup_network(self): 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']], extra_args=[['-debug', '-whitelist=127.0.0.1']],
binary=[self.options.testbinary]) binary=[self.options.testbinary])

View File

@ -45,11 +45,12 @@ Mine 1 old version block, see that the node rejects.
class BIP66Test(ComparisonTestFramework): class BIP66Test(ComparisonTestFramework):
def __init__(self): def __init__(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
def setup_network(self): def setup_network(self):
# Must set the blockversion for this test # Must set the blockversion for this test
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', '-blockversion=2']], extra_args=[['-debug', '-whitelist=127.0.0.1', '-blockversion=2']],
binary=[self.options.testbinary]) binary=[self.options.testbinary])

View File

@ -11,6 +11,10 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * from test_framework.util import *
class BIP66Test(BitcoinTestFramework): class BIP66Test(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 3
self.setup_clean_chain = False
def setup_network(self): def setup_network(self):
self.nodes = [] self.nodes = []

View File

@ -13,7 +13,6 @@ from decimal import Decimal
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.authproxy import JSONRPCException from test_framework.authproxy import JSONRPCException
from test_framework.util import ( from test_framework.util import (
initialize_chain,
assert_equal, assert_equal,
assert_raises, assert_raises,
assert_is_hex_string, assert_is_hex_string,
@ -32,12 +31,13 @@ class BlockchainTest(BitcoinTestFramework):
""" """
def setup_chain(self): def __init__(self):
print("Initializing test directory " + self.options.tmpdir) super().__init__()
initialize_chain(self.options.tmpdir) self.setup_clean_chain = False
self.num_nodes = 1
def setup_network(self, split=False): 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 self.is_network_split = False
self.sync_all() self.sync_all()

View File

@ -11,12 +11,13 @@ from io import BytesIO
class DecodeScriptTest(BitcoinTestFramework): class DecodeScriptTest(BitcoinTestFramework):
"""Tests decoding scripts via RPC command "decodescript".""" """Tests decoding scripts via RPC command "decodescript"."""
def setup_chain(self): def __init__(self):
print('Initializing test directory ' + self.options.tmpdir) super().__init__()
initialize_chain_clean(self.options.tmpdir, 1) self.setup_clean_chain = True
self.num_nodes = 1
def setup_network(self, split=False): 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 self.is_network_split = False
def decodescript_script_sig(self): def decodescript_script_sig(self):

View File

@ -13,12 +13,13 @@ from test_framework.util import *
class DisableWalletTest (BitcoinTestFramework): class DisableWalletTest (BitcoinTestFramework):
def setup_chain(self): def __init__(self):
print("Initializing test directory "+self.options.tmpdir) super().__init__()
initialize_chain_clean(self.options.tmpdir, 1) self.setup_clean_chain = True
self.num_nodes = 1
def setup_network(self, split=False): 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.is_network_split = False
self.sync_all() self.sync_all()

View File

@ -12,6 +12,11 @@ from test_framework.util import *
class ForkNotifyTest(BitcoinTestFramework): class ForkNotifyTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 2
self.setup_clean_chain = False
alert_filename = None # Set by setup_network alert_filename = None # Set by setup_network
def setup_network(self): def setup_network(self):

View File

@ -9,12 +9,13 @@ from test_framework.util import *
# Create one-input, one-output, no-fee transaction: # Create one-input, one-output, no-fee transaction:
class RawTransactionsTest(BitcoinTestFramework): class RawTransactionsTest(BitcoinTestFramework):
def setup_chain(self): def __init__(self):
print(("Initializing test directory "+self.options.tmpdir)) super().__init__()
initialize_chain_clean(self.options.tmpdir, 4) self.setup_clean_chain = True
self.num_nodes = 4
def setup_network(self, split=False): def setup_network(self, split=False):
self.nodes = start_nodes(4, self.options.tmpdir, [['-usehd=0'], ['-usehd=0'], ['-usehd=0'], ['-usehd=0']]) self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, [['-usehd=0'], ['-usehd=0'], ['-usehd=0'], ['-usehd=0']])
connect_nodes_bi(self.nodes,0,1) connect_nodes_bi(self.nodes,0,1)
connect_nodes_bi(self.nodes,1,2) connect_nodes_bi(self.nodes,1,2)
@ -521,7 +522,7 @@ class RawTransactionsTest(BitcoinTestFramework):
stop_nodes(self.nodes) stop_nodes(self.nodes)
wait_bitcoinds() wait_bitcoinds()
self.nodes = start_nodes(4, self.options.tmpdir, [['-usehd=0'], ['-usehd=0'], ['-usehd=0'], ['-usehd=0']]) self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, [['-usehd=0'], ['-usehd=0'], ['-usehd=0'], ['-usehd=0']])
# This test is not meant to test fee estimation and we'd like # This test is not meant to test fee estimation and we'd like
# to be sure all txs are sent at a consistent desired feerate # to be sure all txs are sent at a consistent desired feerate
for node in self.nodes: for node in self.nodes:

View File

@ -26,6 +26,11 @@ class GetBlockTemplateLPTest(BitcoinTestFramework):
Test longpolling with getblocktemplate. Test longpolling with getblocktemplate.
''' '''
def __init__(self):
super().__init__()
self.num_nodes = 4
self.setup_clean_chain = False
def run_test(self): def run_test(self):
print("Warning: this test will take about 70 seconds in the best case. Be patient.") print("Warning: this test will take about 70 seconds in the best case. Be patient.")
wait_to_sync(self.nodes[0]) wait_to_sync(self.nodes[0])

View File

@ -70,6 +70,15 @@ class GetBlockTemplateProposalTest(BitcoinTestFramework):
Test block proposals with getblocktemplate. 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): def run_test(self):
node = self.nodes[0] node = self.nodes[0]
wait_to_sync(node) wait_to_sync(node)

View File

@ -11,9 +11,12 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal from test_framework.util import assert_equal
class GetChainTipsTest (BitcoinTestFramework): class GetChainTipsTest (BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 4
self.setup_clean_chain = False
def run_test (self): def run_test (self):
BitcoinTestFramework.run_test (self)
tips = self.nodes[0].getchaintips () tips = self.nodes[0].getchaintips ()
assert_equal (len (tips), 1) assert_equal (len (tips), 1)

View File

@ -14,8 +14,13 @@ import http.client
import urllib.parse import urllib.parse
class HTTPBasicsTest (BitcoinTestFramework): class HTTPBasicsTest (BitcoinTestFramework):
def setup_nodes(self): def __init__(self):
return start_nodes(4, self.options.tmpdir) super().__init__()
self.num_nodes = 3
self.setup_clean_chain = False
def setup_network(self):
self.nodes = self.setup_nodes()
def run_test(self): def run_test(self):

View File

@ -9,12 +9,13 @@ import decimal
class ImportPrunedFundsTest(BitcoinTestFramework): class ImportPrunedFundsTest(BitcoinTestFramework):
def setup_chain(self): def __init__(self):
print("Initializing test directory "+self.options.tmpdir) super().__init__()
initialize_chain_clean(self.options.tmpdir, 4) self.setup_clean_chain = True
self.num_nodes = 2
def setup_network(self, split=False): 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) connect_nodes_bi(self.nodes,0,1)
self.is_network_split=False self.is_network_split=False
self.sync_all() self.sync_all()

View File

@ -13,10 +13,11 @@ from test_framework.util import *
class InvalidateTest(BitcoinTestFramework): class InvalidateTest(BitcoinTestFramework):
def setup_chain(self): def __init__(self):
print("Initializing test directory "+self.options.tmpdir) super().__init__()
initialize_chain_clean(self.options.tmpdir, 3) self.setup_clean_chain = True
self.num_nodes = 3
def setup_network(self): def setup_network(self):
self.nodes = [] self.nodes = []
self.is_network_split = False self.is_network_split = False

View File

@ -25,6 +25,7 @@ class InvalidBlockRequestTest(ComparisonTestFramework):
''' Can either run this test as 1 node with expected answers, or two and compare them. ''' 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. ''' Change the "outcome" variable from each TestInstance object to only do the comparison. '''
def __init__(self): def __init__(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
def run_test(self): def run_test(self):

View File

@ -19,6 +19,7 @@ class InvalidTxRequestTest(ComparisonTestFramework):
''' Can either run this test as 1 node with expected answers, or two and compare them. ''' 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. ''' Change the "outcome" variable from each TestInstance object to only do the comparison. '''
def __init__(self): def __init__(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
def run_test(self): def run_test(self):

View File

@ -5,8 +5,6 @@
# Exercise the wallet keypool, and interaction with wallet encryption/locking # Exercise the wallet keypool, and interaction with wallet encryption/locking
# Add python-bitcoinrpc to module search path:
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * from test_framework.util import *

View File

@ -17,11 +17,15 @@ def txFromHex(hexstring):
return tx return tx
class ListTransactionsTest(BitcoinTestFramework): class ListTransactionsTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 4
self.setup_clean_chain = False
def setup_nodes(self): def setup_nodes(self):
#This test requires mocktime #This test requires mocktime
enable_mocktime() enable_mocktime()
return start_nodes(4, self.options.tmpdir) return start_nodes(self.num_nodes, self.options.tmpdir)
def run_test(self): def run_test(self):
# Simple send, 0 to 1: # Simple send, 0 to 1:

View File

@ -76,12 +76,13 @@ class MaxBlocksInFlightTest(BitcoinTestFramework):
default=os.getenv("DASHD", "dashd"), default=os.getenv("DASHD", "dashd"),
help="Binary to test max block requests behavior") help="Binary to test max block requests behavior")
def setup_chain(self): def __init__(self):
print("Initializing test directory "+self.options.tmpdir) super().__init__()
initialize_chain_clean(self.options.tmpdir, 1) self.setup_clean_chain = True
self.num_nodes = 1
def setup_network(self): 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']], extra_args=[['-debug', '-whitelist=127.0.0.1']],
binary=[self.options.testbinary]) binary=[self.options.testbinary])

View File

@ -80,17 +80,19 @@ class TestNode(NodeConnCB):
return success return success
class MaxUploadTest(BitcoinTestFramework): class MaxUploadTest(BitcoinTestFramework):
def __init__(self):
self.utxo = []
self.txouts = gen_return_txouts()
def add_options(self, parser): def add_options(self, parser):
parser.add_option("--testbinary", dest="testbinary", parser.add_option("--testbinary", dest="testbinary",
default=os.getenv("DASHD", "dashd"), default=os.getenv("DASHD", "dashd"),
help="dashd binary to test") help="dashd binary to test")
def setup_chain(self): def __init__(self):
initialize_chain_clean(self.options.tmpdir, 2) super().__init__()
self.setup_clean_chain = True
self.num_nodes = 1
self.utxo = []
self.txouts = gen_return_txouts()
def setup_network(self): def setup_network(self):
# Start a node with maxuploadtarget of 200 MB (/24h) # Start a node with maxuploadtarget of 200 MB (/24h)

View File

@ -10,9 +10,6 @@ from test_framework.util import *
class MempoolLimitTest(BitcoinTestFramework): class MempoolLimitTest(BitcoinTestFramework):
def __init__(self):
self.txouts = gen_return_txouts()
def setup_network(self): def setup_network(self):
self.nodes = [] self.nodes = []
self.nodes.append(start_node(0, self.options.tmpdir, ["-maxmempool=5", "-spendzeroconfchange=0", "-debug"])) self.nodes.append(start_node(0, self.options.tmpdir, ["-maxmempool=5", "-spendzeroconfchange=0", "-debug"]))
@ -20,9 +17,12 @@ class MempoolLimitTest(BitcoinTestFramework):
self.sync_all() self.sync_all()
self.relayfee = self.nodes[0].getnetworkinfo()['relayfee'] self.relayfee = self.nodes[0].getnetworkinfo()['relayfee']
def setup_chain(self): def __init__(self):
print("Initializing test directory "+self.options.tmpdir) super().__init__()
initialize_chain_clean(self.options.tmpdir, 2) self.setup_clean_chain = True
self.num_nodes = 1
self.txouts = gen_return_txouts()
def run_test(self): def run_test(self):
txids = [] txids = []

View File

@ -13,6 +13,10 @@ MAX_ANCESTORS = 25
MAX_DESCENDANTS = 25 MAX_DESCENDANTS = 25
class MempoolPackagesTest(BitcoinTestFramework): class MempoolPackagesTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 2
self.setup_clean_chain = False
def setup_network(self): def setup_network(self):
self.nodes = [] self.nodes = []

View File

@ -13,6 +13,10 @@ from test_framework.util import *
# Create one-input, one-output, no-fee transaction: # Create one-input, one-output, no-fee transaction:
class MempoolCoinbaseTest(BitcoinTestFramework): class MempoolCoinbaseTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 2
self.setup_clean_chain = False
alert_filename = None # Set by setup_network alert_filename = None # Set by setup_network

View File

@ -14,6 +14,11 @@ from test_framework.util import *
# Create one-input, one-output, no-fee transaction: # Create one-input, one-output, no-fee transaction:
class MempoolCoinbaseTest(BitcoinTestFramework): class MempoolCoinbaseTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 1
self.setup_clean_chain = False
def setup_network(self): def setup_network(self):
# Just need one node for this test # Just need one node for this test
args = ["-checkmempool", "-debug=mempool"] args = ["-checkmempool", "-debug=mempool"]

View File

@ -19,6 +19,11 @@ from test_framework.util import *
# Create one-input, one-output, no-fee transaction: # Create one-input, one-output, no-fee transaction:
class MempoolSpendCoinbaseTest(BitcoinTestFramework): class MempoolSpendCoinbaseTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 1
self.setup_clean_chain = False
def setup_network(self): def setup_network(self):
# Just need one node for this test # Just need one node for this test
args = ["-checkmempool", "-debug=mempool"] args = ["-checkmempool", "-debug=mempool"]

View File

@ -12,9 +12,10 @@ from test_framework.util import *
class MerkleBlockTest(BitcoinTestFramework): class MerkleBlockTest(BitcoinTestFramework):
def setup_chain(self): def __init__(self):
print("Initializing test directory "+self.options.tmpdir) super().__init__()
initialize_chain_clean(self.options.tmpdir, 4) self.setup_clean_chain = True
self.num_nodes = 4
def setup_network(self): def setup_network(self):
self.nodes = [] self.nodes = []

View File

@ -8,18 +8,21 @@
# #
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * from test_framework.util import str_to_b64str, assert_equal
import os
import http.client import http.client
import urllib.parse import urllib.parse
class HTTPBasicsTest (BitcoinTestFramework): 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): def setup_chain(self):
print("Initializing test directory "+self.options.tmpdir) super().setup_chain()
initialize_chain(self.options.tmpdir)
#Append rpcauth to dash.conf before initialization #Append rpcauth to dash.conf before initialization
rpcauth = "rpcauth=rt:93648e835a54c573682c2eb19f882535$7681e9c5b74bdd85e78166031d2058e1069b3ed7ed967c93fc63abba06f31144" rpcauth = "rpcauth=rt:93648e835a54c573682c2eb19f882535$7681e9c5b74bdd85e78166031d2058e1069b3ed7ed967c93fc63abba06f31144"
rpcauth2 = "rpcauth=rt2:f8607b1a88861fac29dfccf9b52ff9f$ff36a0c23c8c62b4846112e50fa888416e94c17bfd4c42f88fd8f55ec6a3137e" rpcauth2 = "rpcauth=rt2:f8607b1a88861fac29dfccf9b52ff9f$ff36a0c23c8c62b4846112e50fa888416e94c17bfd4c42f88fd8f55ec6a3137e"
@ -27,6 +30,9 @@ class HTTPBasicsTest (BitcoinTestFramework):
f.write(rpcauth+"\n") f.write(rpcauth+"\n")
f.write(rpcauth2+"\n") f.write(rpcauth2+"\n")
def setup_network(self):
self.nodes = self.setup_nodes()
def run_test(self): def run_test(self):
################################################## ##################################################

View File

@ -14,6 +14,12 @@ import http.client
import urllib.parse import urllib.parse
class NodeHandlingTest (BitcoinTestFramework): class NodeHandlingTest (BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 4
self.setup_clean_chain = False
def run_test(self): def run_test(self):
########################### ###########################
# setban/listbanned tests # # setban/listbanned tests #

View File

@ -111,8 +111,10 @@ class AcceptBlockTest(BitcoinTestFramework):
default=os.getenv("DASHD", "dashd"), default=os.getenv("DASHD", "dashd"),
help="bitcoind binary to test") help="bitcoind binary to test")
def setup_chain(self): def __init__(self):
initialize_chain_clean(self.options.tmpdir, 2) super().__init__()
self.setup_clean_chain = True
self.num_nodes = 2
def setup_network(self): def setup_network(self):
# Node0 will be used to test behavior of processing unrequested blocks # Node0 will be used to test behavior of processing unrequested blocks

View File

@ -46,6 +46,12 @@ class TestNode(SingleNodeConnCB):
self.sync_with_ping() self.sync_with_ping()
class FeeFilterTest(BitcoinTestFramework): class FeeFilterTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 2
self.setup_clean_chain = False
def setup_network(self): def setup_network(self):
# Node1 will be used to generate txs which should be relayed from Node0 # Node1 will be used to generate txs which should be relayed from Node0
# to our test node # to our test node

View File

@ -29,6 +29,7 @@ class FullBlockTest(ComparisonTestFramework):
''' Can either run this test as 1 node with expected answers, or two and compare them. ''' 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. ''' Change the "outcome" variable from each TestInstance object to only do the comparison. '''
def __init__(self): def __init__(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
self.block_heights = {} self.block_heights = {}
self.coinbase_key = CECKey() self.coinbase_key = CECKey()

View File

@ -59,8 +59,10 @@ class TestNode(NodeConnCB):
class VersionBitsWarningTest(BitcoinTestFramework): class VersionBitsWarningTest(BitcoinTestFramework):
def setup_chain(self): def __init__(self):
initialize_chain_clean(self.options.tmpdir, 1) super().__init__()
self.setup_clean_chain = True
self.num_nodes = 1
def setup_network(self): def setup_network(self):
self.nodes = [] self.nodes = []

View File

@ -14,11 +14,11 @@ from test_framework.mininode import COIN, MAX_BLOCK_SIZE
class PrioritiseTransactionTest(BitcoinTestFramework): class PrioritiseTransactionTest(BitcoinTestFramework):
def __init__(self): def __init__(self):
self.txouts = gen_return_txouts() super().__init__()
self.setup_clean_chain = True
self.num_nodes = 1
def setup_chain(self): self.txouts = gen_return_txouts()
print("Initializing test directory "+self.options.tmpdir)
initialize_chain_clean(self.options.tmpdir, 1)
def setup_network(self): def setup_network(self):
self.nodes = [] self.nodes = []

View File

@ -36,6 +36,10 @@ addnode connect to generic DNS name
class ProxyTest(BitcoinTestFramework): class ProxyTest(BitcoinTestFramework):
def __init__(self): def __init__(self):
super().__init__()
self.num_nodes = 4
self.setup_clean_chain = False
self.have_ipv6 = test_ipv6_local() self.have_ipv6 = test_ipv6_local()
# Create two proxies on different ports # Create two proxies on different ports
# ... one unauthenticated # ... one unauthenticated
@ -77,7 +81,7 @@ class ProxyTest(BitcoinTestFramework):
] ]
if self.have_ipv6: if self.have_ipv6:
args[3] = ['-listen', '-debug=net', '-debug=proxy', '-proxy=[%s]:%i' % (self.conf3.addr),'-proxyrandomize=0', '-noonion'] 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): def node_test(self, node, proxies, auth, test_onion=True):
rv = [] rv = []

View File

@ -20,14 +20,14 @@ def calc_usage(blockdir):
class PruneTest(BitcoinTestFramework): class PruneTest(BitcoinTestFramework):
def __init__(self): def __init__(self):
super().__init__()
self.setup_clean_chain = True
self.num_nodes = 3
self.utxo = [] self.utxo = []
self.address = ["",""] self.address = ["",""]
self.txouts = gen_return_txouts() self.txouts = gen_return_txouts()
def setup_chain(self):
print("Initializing test directory "+self.options.tmpdir)
initialize_chain_clean(self.options.tmpdir, 3)
def setup_network(self): def setup_network(self):
self.nodes = [] self.nodes = []
self.is_network_split = False self.is_network_split = False

View File

@ -14,12 +14,13 @@ from test_framework.util import *
# Create one-input, one-output, no-fee transaction: # Create one-input, one-output, no-fee transaction:
class RawTransactionsTest(BitcoinTestFramework): class RawTransactionsTest(BitcoinTestFramework):
def setup_chain(self): def __init__(self):
print("Initializing test directory "+self.options.tmpdir) super().__init__()
initialize_chain_clean(self.options.tmpdir, 3) self.setup_clean_chain = True
self.num_nodes = 3
def setup_network(self, split=False): 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 #connect to a local machine for debugging
#url = "http://bitcoinrpc:DP6DvqZtqXarpeNWyN3LZTFchCCyCUuHwNF7E8pX99x1@%s:%d" % ('127.0.0.1', 18332) #url = "http://bitcoinrpc:DP6DvqZtqXarpeNWyN3LZTFchCCyCUuHwNF7E8pX99x1@%s:%d" % ('127.0.0.1', 18332)

View File

@ -27,10 +27,15 @@ def get_sub_array_from_array(object_array, to_match):
class ReceivedByTest(BitcoinTestFramework): class ReceivedByTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 4
self.setup_clean_chain = False
def setup_nodes(self): def setup_nodes(self):
#This test requires mocktime #This test requires mocktime
enable_mocktime() enable_mocktime()
return start_nodes(4, self.options.tmpdir) return start_nodes(self.num_nodes, self.options.tmpdir)
def run_test(self): def run_test(self):
''' '''

View File

@ -12,9 +12,10 @@ import time
class ReindexTest(BitcoinTestFramework): class ReindexTest(BitcoinTestFramework):
def setup_chain(self): def __init__(self):
print("Initializing test directory "+self.options.tmpdir) super().__init__()
initialize_chain_clean(self.options.tmpdir, 1) self.setup_clean_chain = True
self.num_nodes = 1
def setup_network(self): def setup_network(self):
self.nodes = [] self.nodes = []

View File

@ -68,6 +68,11 @@ def make_utxo(node, amount, confirmed=True, scriptPubKey=CScript([1])):
class ReplaceByFeeTest(BitcoinTestFramework): class ReplaceByFeeTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 1
self.setup_clean_chain = False
def setup_network(self): def setup_network(self):
self.nodes = [] self.nodes = []
self.nodes.append(start_node(0, self.options.tmpdir, ["-maxorphantx=1000", "-debug", self.nodes.append(start_node(0, self.options.tmpdir, ["-maxorphantx=1000", "-debug",

View File

@ -47,12 +47,13 @@ def http_post_call(host, port, path, requestdata = '', response_object = 0):
class RESTTest (BitcoinTestFramework): class RESTTest (BitcoinTestFramework):
FORMAT_SEPARATOR = "." FORMAT_SEPARATOR = "."
def setup_chain(self): def __init__(self):
print("Initializing test directory "+self.options.tmpdir) super().__init__()
initialize_chain_clean(self.options.tmpdir, 3) self.setup_clean_chain = True
self.num_nodes = 3
def setup_network(self, split=False): 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,0,1)
connect_nodes_bi(self.nodes,1,2) connect_nodes_bi(self.nodes,1,2)
connect_nodes_bi(self.nodes,0,2) connect_nodes_bi(self.nodes,0,2)

View File

@ -24,7 +24,7 @@ def run_bind_test(tmpdir, allow_ips, connect_to, addresses, expected):
if allow_ips: if allow_ips:
base_args += ['-rpcallowip=' + x for x in allow_ips] base_args += ['-rpcallowip=' + x for x in allow_ips]
binds = ['-rpcbind='+addr for addr in addresses] 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: try:
pid = bitcoind_processes[0].pid pid = bitcoind_processes[0].pid
assert_equal(set(get_bind_addrs(pid)), set(expected)) assert_equal(set(get_bind_addrs(pid)), set(expected))
@ -38,7 +38,7 @@ def run_allowip_test(tmpdir, allow_ips, rpchost, rpcport):
at a non-localhost IP. at a non-localhost IP.
''' '''
base_args = ['-disablewallet', '-nolisten'] + ['-rpcallowip='+x for x in allow_ips] 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: try:
# connect to node through non-loopback interface # connect to node through non-loopback interface
url = "http://rt:rt@%s:%d" % (rpchost, rpcport,) url = "http://rt:rt@%s:%d" % (rpchost, rpcport,)

View File

@ -208,12 +208,14 @@ class TestNode(BaseNode):
BaseNode.__init__(self) BaseNode.__init__(self)
class SendHeadersTest(BitcoinTestFramework): class SendHeadersTest(BitcoinTestFramework):
def setup_chain(self): def __init__(self):
initialize_chain_clean(self.options.tmpdir, 2) super().__init__()
self.setup_clean_chain = True
self.num_nodes = 2
def setup_network(self): def setup_network(self):
self.nodes = [] self.nodes = []
self.nodes = start_nodes(2, self.options.tmpdir, [["-debug", "-logtimemicros=1"]]*2) self.nodes = start_nodes(self.num_nodes, self.options.tmpdir, [["-debug", "-logtimemicros=1"]]*2)
connect_nodes(self.nodes[0], 1) connect_nodes(self.nodes[0], 1)
# mine count blocks and return the new tip # mine count blocks and return the new tip

View File

@ -10,12 +10,13 @@ from test_framework.util import *
class SignMessagesTest(BitcoinTestFramework): class SignMessagesTest(BitcoinTestFramework):
"""Tests RPC commands for signing and verifying messages.""" """Tests RPC commands for signing and verifying messages."""
def setup_chain(self): def __init__(self):
print('Initializing test directory ' + self.options.tmpdir) super().__init__()
initialize_chain_clean(self.options.tmpdir, 1) self.setup_clean_chain = True
self.num_nodes = 1
def setup_network(self, split=False): 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 self.is_network_split = False
def run_test(self): def run_test(self):

View File

@ -10,12 +10,13 @@ from test_framework.util import *
class SignRawTransactionsTest(BitcoinTestFramework): class SignRawTransactionsTest(BitcoinTestFramework):
"""Tests transaction signing via RPC command "signrawtransaction".""" """Tests transaction signing via RPC command "signrawtransaction"."""
def setup_chain(self): def __init__(self):
print('Initializing test directory ' + self.options.tmpdir) super().__init__()
initialize_chain_clean(self.options.tmpdir, 1) self.setup_clean_chain = True
self.num_nodes = 1
def setup_network(self, split=False): 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 self.is_network_split = False
def successful_signing_test(self): def successful_signing_test(self):

View File

@ -167,6 +167,11 @@ def check_estimates(node, fees_seen, max_invalid, print_estimates = True):
class EstimateFeeTest(BitcoinTestFramework): class EstimateFeeTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 3
self.setup_clean_chain = False
def setup_network(self): def setup_network(self):
''' '''
We'll setup the network to have 3 nodes that all mine with different parameters. We'll setup the network to have 3 nodes that all mine with different parameters.

View File

@ -15,7 +15,6 @@ import traceback
from .util import ( from .util import (
initialize_chain, initialize_chain,
assert_equal,
start_nodes, start_nodes,
connect_nodes_bi, connect_nodes_bi,
sync_blocks, sync_blocks,
@ -32,21 +31,26 @@ from .authproxy import JSONRPCException
class BitcoinTestFramework(object): 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): def run_test(self):
for node in self.nodes: raise NotImplementedError
assert_equal(node.getblockcount(), 200)
assert_equal(node.getbalance(), 25*500)
def add_options(self, parser): def add_options(self, parser):
pass pass
def setup_chain(self): def setup_chain(self):
print("Initializing test directory "+self.options.tmpdir) 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): 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): def setup_network(self, split = False):
self.nodes = self.setup_nodes() self.nodes = self.setup_nodes()
@ -181,9 +185,10 @@ class BitcoinTestFramework(object):
class ComparisonTestFramework(BitcoinTestFramework): class ComparisonTestFramework(BitcoinTestFramework):
# Can override the num_nodes variable to indicate how many nodes to run.
def __init__(self): def __init__(self):
super().__init__()
self.num_nodes = 2 self.num_nodes = 2
self.setup_clean_chain = True
def add_options(self, parser): def add_options(self, parser):
parser.add_option("--testbinary", dest="testbinary", parser.add_option("--testbinary", dest="testbinary",
@ -193,10 +198,6 @@ class ComparisonTestFramework(BitcoinTestFramework):
default=os.getenv("DASHD", "dashd"), default=os.getenv("DASHD", "dashd"),
help="bitcoind binary to use for reference nodes (if any)") 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): def setup_network(self):
self.nodes = start_nodes( self.nodes = start_nodes(
self.num_nodes, self.options.tmpdir, self.num_nodes, self.options.tmpdir,

View File

@ -196,24 +196,28 @@ def wait_for_bitcoind_start(process, url, i):
raise # unkown JSON RPC exception raise # unkown JSON RPC exception
time.sleep(0.25) 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 Create a cache of a 200-block-long chain (with wallet) for MAX_NODES
4 wallets. Afterward, create num_nodes copies from the cache
""" """
if (not os.path.isdir(os.path.join("cache","node0")) assert num_nodes <= MAX_NODES
or not os.path.isdir(os.path.join("cache","node1")) create_cache = False
or not os.path.isdir(os.path.join("cache","node2")) for i in range(MAX_NODES):
or not os.path.isdir(os.path.join("cache","node3"))): 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 #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))): if os.path.isdir(os.path.join("cache","node"+str(i))):
shutil.rmtree(os.path.join("cache","node"+str(i))) shutil.rmtree(os.path.join("cache","node"+str(i)))
# Create cache directories, run dashds: # Create cache directories, run dashds:
for i in range(4): for i in range(MAX_NODES):
datadir=initialize_datadir("cache", i) datadir=initialize_datadir("cache", i)
args = [ os.getenv("DASHD", "dashd"), "-server", "-keypool=1", "-datadir="+datadir, "-discover=0" ] args = [ os.getenv("DASHD", "dashd"), "-server", "-keypool=1", "-datadir="+datadir, "-discover=0" ]
if i > 0: if i > 0:
@ -226,15 +230,18 @@ def initialize_chain(test_dir):
print("initialize_chain: RPC succesfully started") print("initialize_chain: RPC succesfully started")
rpcs = [] rpcs = []
for i in range(4): for i in range(MAX_NODES):
try: try:
rpcs.append(get_rpc_proxy(rpc_url(i), i)) rpcs.append(get_rpc_proxy(rpc_url(i), i))
except: except:
sys.stderr.write("Error connecting to "+url+"\n") sys.stderr.write("Error connecting to "+url+"\n")
sys.exit(1) 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. # 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 156 seconds apart # blocks are created with timestamps 156 seconds apart
# starting from 31356 seconds in the past # starting from 31356 seconds in the past
enable_mocktime() enable_mocktime()
@ -252,13 +259,13 @@ def initialize_chain(test_dir):
stop_nodes(rpcs) stop_nodes(rpcs)
wait_bitcoinds() wait_bitcoinds()
disable_mocktime() disable_mocktime()
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, "debug.log"))
os.remove(log_filename("cache", i, "db.log")) os.remove(log_filename("cache", i, "db.log"))
os.remove(log_filename("cache", i, "peers.dat")) os.remove(log_filename("cache", i, "peers.dat"))
os.remove(log_filename("cache", i, "fee_estimates.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)) from_dir = os.path.join("cache", "node"+str(i))
to_dir = os.path.join(test_dir, "node"+str(i)) to_dir = os.path.join(test_dir, "node"+str(i))
shutil.copytree(from_dir, to_dir) shutil.copytree(from_dir, to_dir)

View File

@ -12,6 +12,11 @@ from test_framework.util import *
class TxnMallTest(BitcoinTestFramework): class TxnMallTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 4
self.setup_clean_chain = False
def add_options(self, parser): def add_options(self, parser):
parser.add_option("--mineblock", dest="mine_block", default=False, action="store_true", parser.add_option("--mineblock", dest="mine_block", default=False, action="store_true",
help="Test double-spend of 1-confirmed transaction") help="Test double-spend of 1-confirmed transaction")

View File

@ -12,6 +12,11 @@ from test_framework.util import *
class TxnMallTest(BitcoinTestFramework): class TxnMallTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 4
self.setup_clean_chain = False
def add_options(self, parser): def add_options(self, parser):
parser.add_option("--mineblock", dest="mine_block", default=False, action="store_true", parser.add_option("--mineblock", dest="mine_block", default=False, action="store_true",
help="Test double-spend of 1-confirmed transaction") help="Test double-spend of 1-confirmed transaction")

View File

@ -19,9 +19,10 @@ class WalletTest (BitcoinTestFramework):
raise AssertionError("Fee of %s DASH too high! (Should be %s DASH)"%(str(fee), str(target_fee))) raise AssertionError("Fee of %s DASH too high! (Should be %s DASH)"%(str(fee), str(target_fee)))
return curr_balance return curr_balance
def setup_chain(self): def __init__(self):
print("Initializing test directory "+self.options.tmpdir) super().__init__()
initialize_chain_clean(self.options.tmpdir, 4) self.setup_clean_chain = True
self.num_nodes = 4
def setup_network(self, split=False): def setup_network(self, split=False):
self.nodes = start_nodes(3, self.options.tmpdir) self.nodes = start_nodes(3, self.options.tmpdir)

View File

@ -41,15 +41,16 @@ logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO, str
class WalletBackupTest(BitcoinTestFramework): class WalletBackupTest(BitcoinTestFramework):
def setup_chain(self): def __init__(self):
logging.info("Initializing test directory "+self.options.tmpdir) super().__init__()
initialize_chain_clean(self.options.tmpdir, 4) self.setup_clean_chain = True
self.num_nodes = 4
# This mirrors how the network was setup in the bash test # This mirrors how the network was setup in the bash test
def setup_network(self, split=False): def setup_network(self, split=False):
# nodes 1, 2,3 are spenders, let's give them a keypool=100 # nodes 1, 2,3 are spenders, let's give them a keypool=100
extra_args = [["-keypool=100"], ["-keypool=100"], ["-keypool=100"], []] extra_args = [["-keypool=100"], ["-keypool=100"], ["-keypool=100"], []]
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[0], 3)
connect_nodes(self.nodes[1], 3) connect_nodes(self.nodes[1], 3)
connect_nodes(self.nodes[2], 3) connect_nodes(self.nodes[2], 3)

View File

@ -9,12 +9,13 @@ from test_framework.util import *
class ZapWalletTXesTest (BitcoinTestFramework): class ZapWalletTXesTest (BitcoinTestFramework):
def setup_chain(self): def __init__(self):
print("Initializing test directory "+self.options.tmpdir) super().__init__()
initialize_chain_clean(self.options.tmpdir, 3) self.setup_clean_chain = True
self.num_nodes = 3
def setup_network(self, split=False): 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,0,1)
connect_nodes_bi(self.nodes,1,2) connect_nodes_bi(self.nodes,1,2)
connect_nodes_bi(self.nodes,0,2) connect_nodes_bi(self.nodes,0,2)

View File

@ -17,6 +17,10 @@ import urllib.parse
class ZMQTest (BitcoinTestFramework): class ZMQTest (BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 4
port = 28332 port = 28332
def setup_nodes(self): def setup_nodes(self):
@ -25,7 +29,7 @@ class ZMQTest (BitcoinTestFramework):
self.zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashblock") self.zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashblock")
self.zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashtx") self.zmqSubSocket.setsockopt(zmq.SUBSCRIBE, b"hashtx")
self.zmqSubSocket.connect("tcp://127.0.0.1:%i" % self.port) 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)], ['-zmqpubhashtx=tcp://127.0.0.1:'+str(self.port), '-zmqpubhashblock=tcp://127.0.0.1:'+str(self.port)],
[], [],
[], [],