[tests] don't override __init__() in individual tests
Almost all test scripts currently need to override the __init__() method. When they do that they need to call into super().__init__() as the base class does some generic initialization. This commit makes the base class __init__() call into set_test_params() method. Individual test cases can override set_test_params() to setup their test parameters.
This commit is contained in:
parent
6cf094a022
commit
5448a1471d
82 changed files with 145 additions and 322 deletions
|
@ -24,8 +24,8 @@ don't have test cases for.
|
|||
- Use a module-level docstring to describe what the test is testing, and how it
|
||||
is testing it.
|
||||
- When subclassing the BitcoinTestFramwork, place overrides for the
|
||||
`__init__()`, and `setup_xxxx()` methods at the top of the subclass, then
|
||||
locally-defined helper methods, then the `run_test()` method.
|
||||
`set_test_params()`, `add_options()` and `setup_xxxx()` methods at the top of
|
||||
the subclass, then locally-defined helper methods, then the `run_test()` method.
|
||||
|
||||
#### General test-writing advice
|
||||
|
||||
|
@ -36,7 +36,7 @@ don't have test cases for.
|
|||
- Avoid stop-starting the nodes multiple times during the test if possible. A
|
||||
stop-start takes several seconds, so doing it several times blows up the
|
||||
runtime of the test.
|
||||
- Set the `self.setup_clean_chain` variable in `__init__()` to control whether
|
||||
- Set the `self.setup_clean_chain` variable in `set_test_params()` to control whether
|
||||
or not to use the cached data directories. The cached data directories
|
||||
contain a 200-block pre-mined blockchain and wallets for four nodes. Each node
|
||||
has 25 mature blocks (25x50=1250 BTC) in its wallet.
|
||||
|
|
|
@ -14,10 +14,8 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
from test_framework.util import *
|
||||
|
||||
class AbandonConflictTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 2
|
||||
self.setup_clean_chain = False
|
||||
self.extra_args = [["-minrelaytxfee=0.00001"], []]
|
||||
|
||||
def run_test(self):
|
||||
|
|
|
@ -54,8 +54,7 @@ class BaseNode(NodeConnCB):
|
|||
self.send_message(headers_message)
|
||||
|
||||
class AssumeValidTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 3
|
||||
|
||||
|
|
|
@ -60,9 +60,7 @@ def create_transaction(node, coinbase, to_address, amount):
|
|||
return tx
|
||||
|
||||
class BIP65Test(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
self.extra_args = [['-promiscuousmempoolflags=1', '-whitelist=127.0.0.1']]
|
||||
self.setup_clean_chain = True
|
||||
|
|
|
@ -92,9 +92,9 @@ def all_rlt_txs(txarray):
|
|||
return txs
|
||||
|
||||
class BIP68_112_113Test(ComparisonTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
self.setup_clean_chain = True
|
||||
self.extra_args = [['-whitelist=127.0.0.1', '-blockversion=4']]
|
||||
|
||||
def run_test(self):
|
||||
|
|
|
@ -17,10 +17,8 @@ SEQUENCE_LOCKTIME_MASK = 0x0000ffff
|
|||
NOT_FINAL_ERROR = "64: non-BIP68-final"
|
||||
|
||||
class BIP68Test(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 2
|
||||
self.setup_clean_chain = False
|
||||
self.extra_args = [[], ["-acceptnonstdtxn=0"]]
|
||||
|
||||
def run_test(self):
|
||||
|
|
|
@ -28,11 +28,10 @@ from test_framework.comptool import TestInstance, TestManager
|
|||
from test_framework.script import CScript, OP_1NEGATE, OP_CHECKSEQUENCEVERIFY, OP_DROP
|
||||
|
||||
class BIP9SoftForksTest(ComparisonTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
self.extra_args = [['-whitelist=127.0.0.1']]
|
||||
self.setup_clean_chain = True
|
||||
|
||||
def run_test(self):
|
||||
self.test = TestManager(self, self.options.tmpdir)
|
||||
|
|
|
@ -48,9 +48,7 @@ def create_transaction(node, coinbase, to_address, amount):
|
|||
return tx
|
||||
|
||||
class BIP66Test(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
self.extra_args = [['-promiscuousmempoolflags=1', '-whitelist=127.0.0.1']]
|
||||
self.setup_clean_chain = True
|
||||
|
|
|
@ -30,12 +30,8 @@ from test_framework.util import (
|
|||
assert_is_hash_string,
|
||||
)
|
||||
|
||||
|
||||
class BlockchainTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setup_clean_chain = False
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
self.extra_args = [['-stopatheight=207']]
|
||||
|
||||
|
|
|
@ -30,8 +30,7 @@ WALLET_PASSPHRASE_TIMEOUT = 3600
|
|||
|
||||
|
||||
class BumpFeeTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 2
|
||||
self.setup_clean_chain = True
|
||||
self.extra_args = [["-prematurewitness", "-walletprematurewitness", "-walletrbf={}".format(i)]
|
||||
|
|
|
@ -12,11 +12,9 @@ tests are being run in parallel.
|
|||
from test_framework.test_framework import BitcoinTestFramework
|
||||
|
||||
class CreateCache(BitcoinTestFramework):
|
||||
# Test network and test nodes are not required:
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
# Test network and test nodes are not required:
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 0
|
||||
|
||||
def setup_network(self):
|
||||
|
|
|
@ -43,8 +43,7 @@ except AttributeError:
|
|||
pass
|
||||
|
||||
class ChainstateWriteCrashTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 4
|
||||
self.setup_clean_chain = False
|
||||
|
||||
|
|
|
@ -10,9 +10,7 @@ from test_framework.mininode import *
|
|||
from io import BytesIO
|
||||
|
||||
class DecodeScriptTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
|
||||
|
|
|
@ -11,11 +11,8 @@
|
|||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import *
|
||||
|
||||
|
||||
class DisableWalletTest (BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
self.extra_args = [["-disablewallet"]]
|
||||
|
|
|
@ -14,11 +14,8 @@ from test_framework.util import (
|
|||
)
|
||||
|
||||
class DisconnectBanTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 2
|
||||
self.setup_clean_chain = False
|
||||
|
||||
def run_test(self):
|
||||
self.log.info("Test setban and listbanned RPCs")
|
||||
|
|
|
@ -73,15 +73,11 @@ def custom_function():
|
|||
class ExampleTest(BitcoinTestFramework):
|
||||
# Each functional test is a subclass of the BitcoinTestFramework class.
|
||||
|
||||
# Override the __init__(), add_options(), setup_chain(), setup_network()
|
||||
# Override the set_test_params(), add_options(), setup_chain(), setup_network()
|
||||
# and setup_nodes() methods to customize the test setup as required.
|
||||
|
||||
def __init__(self):
|
||||
"""Initialize the test
|
||||
|
||||
Call super().__init__() first, and then override any test parameters
|
||||
for your individual test."""
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
"""Override any test parameters for your individual test."""
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 3
|
||||
# Use self.extra_args to change command-line arguments for the nodes
|
||||
|
|
|
@ -9,11 +9,8 @@ import time
|
|||
from test_framework.test_framework import BitcoinTestFramework
|
||||
|
||||
class ForkNotifyTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 2
|
||||
self.setup_clean_chain = False
|
||||
|
||||
def setup_network(self):
|
||||
self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")
|
||||
|
|
|
@ -14,13 +14,9 @@ def get_unspent(listunspent, amount):
|
|||
return utx
|
||||
raise AssertionError('Could not find unspent with amount={}'.format(amount))
|
||||
|
||||
|
||||
class RawTransactionsTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 4
|
||||
|
||||
def setup_network(self, split=False):
|
||||
self.setup_nodes()
|
||||
|
|
|
@ -23,11 +23,6 @@ class LongpollThread(threading.Thread):
|
|||
self.node.getblocktemplate({'longpollid':self.longpollid})
|
||||
|
||||
class GetBlockTemplateLPTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.num_nodes = 4
|
||||
self.setup_clean_chain = False
|
||||
|
||||
def run_test(self):
|
||||
self.log.info("Warning: this test will take about 70 seconds in the best case. Be patient.")
|
||||
self.nodes[0].generate(10)
|
||||
|
|
|
@ -14,13 +14,7 @@ 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):
|
||||
|
||||
tips = self.nodes[0].getchaintips ()
|
||||
assert_equal (len (tips), 1)
|
||||
assert_equal (tips[0]['branchlen'], 0)
|
||||
|
|
|
@ -11,10 +11,8 @@ import http.client
|
|||
import urllib.parse
|
||||
|
||||
class HTTPBasicsTest (BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 3
|
||||
self.setup_clean_chain = False
|
||||
|
||||
def setup_network(self):
|
||||
self.setup_nodes()
|
||||
|
|
|
@ -111,8 +111,7 @@ TIMESTAMP_WINDOW = 2 * 60 * 60
|
|||
|
||||
|
||||
class ImportRescanTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 2 + len(IMPORT_NODES)
|
||||
|
||||
def setup_network(self):
|
||||
|
|
|
@ -7,8 +7,7 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
from test_framework.util import *
|
||||
|
||||
class ImportMultiTest (BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 2
|
||||
self.setup_clean_chain = True
|
||||
|
||||
|
|
|
@ -6,11 +6,8 @@
|
|||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import *
|
||||
|
||||
|
||||
class ImportPrunedFundsTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 2
|
||||
|
||||
|
|
|
@ -8,9 +8,7 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
from test_framework.util import *
|
||||
|
||||
class InvalidateTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 3
|
||||
|
||||
|
|
|
@ -23,9 +23,9 @@ 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__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
self.setup_clean_chain = True
|
||||
|
||||
def run_test(self):
|
||||
test = TestManager(self, self.options.tmpdir)
|
||||
|
|
|
@ -19,9 +19,9 @@ class InvalidTxRequestTest(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__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
self.setup_clean_chain = True
|
||||
|
||||
def run_test(self):
|
||||
test = TestManager(self, self.options.tmpdir)
|
||||
|
|
|
@ -20,8 +20,7 @@ from test_framework.util import (
|
|||
)
|
||||
|
||||
class KeypoolRestoreTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 2
|
||||
self.extra_args = [['-usehd=0'], ['-usehd=1', '-keypool=100', '-keypoolmin=20']]
|
||||
|
|
|
@ -8,6 +8,8 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
from test_framework.util import *
|
||||
|
||||
class KeyPoolTest(BitcoinTestFramework):
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
|
||||
def run_test(self):
|
||||
nodes = self.nodes
|
||||
|
@ -78,10 +80,5 @@ class KeyPoolTest(BitcoinTestFramework):
|
|||
assert_equal(wi['keypoolsize_hd_internal'], 100)
|
||||
assert_equal(wi['keypoolsize'], 100)
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setup_clean_chain = False
|
||||
self.num_nodes = 1
|
||||
|
||||
if __name__ == '__main__':
|
||||
KeyPoolTest().main()
|
||||
|
|
|
@ -8,11 +8,8 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
from test_framework.util import assert_equal
|
||||
|
||||
class ListSinceBlockTest (BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 4
|
||||
|
||||
def run_test(self):
|
||||
self.nodes[2].generate(101)
|
||||
|
|
|
@ -16,10 +16,7 @@ def txFromHex(hexstring):
|
|||
return tx
|
||||
|
||||
class ListTransactionsTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.num_nodes = 4
|
||||
self.setup_clean_chain = False
|
||||
def set_test_params(self):
|
||||
self.enable_mocktime()
|
||||
|
||||
def run_test(self):
|
||||
|
|
|
@ -31,8 +31,7 @@ class TestNode(NodeConnCB):
|
|||
|
||||
class MaxUploadTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
self.extra_args = [["-maxuploadtarget=800", "-blockmaxsize=999000"]]
|
||||
|
|
|
@ -8,9 +8,7 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
from test_framework.util import *
|
||||
|
||||
class MempoolLimitTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
self.extra_args = [["-maxmempool=5", "-spendzeroconfchange=0"]]
|
||||
|
|
|
@ -12,10 +12,8 @@ MAX_ANCESTORS = 25
|
|||
MAX_DESCENDANTS = 25
|
||||
|
||||
class MempoolPackagesTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 2
|
||||
self.setup_clean_chain = False
|
||||
self.extra_args = [["-maxorphantx=1000"], ["-maxorphantx=1000", "-limitancestorcount=5"]]
|
||||
|
||||
# Build a transaction that spends parent_txid:vout
|
||||
|
|
|
@ -36,12 +36,8 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
from test_framework.util import *
|
||||
|
||||
class MempoolPersistTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
# We need 3 nodes for this test. Node1 does not have a persistent mempool.
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 3
|
||||
self.setup_clean_chain = False
|
||||
self.extra_args = [[], ["-persistmempool=0"], []]
|
||||
|
||||
def run_test(self):
|
||||
|
|
|
@ -13,10 +13,8 @@ from test_framework.util import *
|
|||
|
||||
# Create one-input, one-output, no-fee transaction:
|
||||
class MempoolCoinbaseTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 2
|
||||
self.setup_clean_chain = False
|
||||
self.extra_args = [["-checkmempool"]] * 2
|
||||
|
||||
alert_filename = None # Set by setup_network
|
||||
|
|
|
@ -9,12 +9,8 @@ from test_framework.util import *
|
|||
|
||||
# Create one-input, one-output, no-fee transaction:
|
||||
class MempoolCoinbaseTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
self.setup_clean_chain = False
|
||||
# Just need one node for this test
|
||||
self.extra_args = [["-checkmempool"]]
|
||||
|
||||
def run_test(self):
|
||||
|
|
|
@ -17,11 +17,8 @@ from test_framework.util import *
|
|||
|
||||
# Create one-input, one-output, no-fee transaction:
|
||||
class MempoolSpendCoinbaseTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
self.setup_clean_chain = False
|
||||
self.extra_args = [["-checkmempool"]]
|
||||
|
||||
def run_test(self):
|
||||
|
|
|
@ -8,11 +8,8 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
from test_framework.util import *
|
||||
|
||||
class MerkleBlockTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 4
|
||||
# Nodes 0/1 are "wallet" nodes, Nodes 2/3 are used for testing
|
||||
self.extra_args = [[], [], [], ["-txindex"]]
|
||||
|
||||
|
|
|
@ -25,9 +25,7 @@ def assert_template(node, block, expect, rehash=True):
|
|||
assert_equal(rsp, expect)
|
||||
|
||||
class MiningTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 2
|
||||
self.setup_clean_chain = False
|
||||
|
||||
|
|
|
@ -12,10 +12,7 @@ import http.client
|
|||
import urllib.parse
|
||||
|
||||
class HTTPBasicsTest (BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setup_clean_chain = False
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 2
|
||||
|
||||
def setup_chain(self):
|
||||
|
|
|
@ -12,9 +12,7 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
from test_framework.util import assert_equal, assert_raises_jsonrpc
|
||||
|
||||
class MultiWalletTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
self.extra_args = [['-wallet=w1', '-wallet=w2', '-wallet=w3']]
|
||||
|
|
|
@ -17,10 +17,8 @@ from test_framework.util import (
|
|||
p2p_port,
|
||||
)
|
||||
|
||||
|
||||
class NetTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 2
|
||||
|
||||
|
|
|
@ -37,8 +37,7 @@ def trueDummy(tx):
|
|||
|
||||
class NULLDUMMYTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
self.setup_clean_chain = True
|
||||
self.extra_args = [['-whitelist=127.0.0.1', '-walletprematurewitness']]
|
||||
|
|
|
@ -60,8 +60,7 @@ class AcceptBlockTest(BitcoinTestFramework):
|
|||
default=os.getenv("BITCOIND", "bitcoind"),
|
||||
help="bitcoind binary to test")
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 2
|
||||
self.extra_args = [[], ["-whitelist=127.0.0.1"]]
|
||||
|
|
|
@ -89,8 +89,7 @@ class TestNode(NodeConnCB):
|
|||
wait_until(lambda: not self.connected, timeout=timeout, lock=mininode_lock)
|
||||
|
||||
class CompactBlocksTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
# Node0 = pre-segwit, node1 = segwit-aware
|
||||
self.num_nodes = 2
|
||||
|
|
|
@ -37,11 +37,8 @@ class TestNode(NodeConnCB):
|
|||
self.txinvs = []
|
||||
|
||||
class FeeFilterTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 2
|
||||
self.setup_clean_chain = False
|
||||
|
||||
def run_test(self):
|
||||
node1 = self.nodes[1]
|
||||
|
|
|
@ -49,12 +49,11 @@ class CBrokenBlock(CBlock):
|
|||
return r
|
||||
|
||||
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__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
self.setup_clean_chain = True
|
||||
self.block_heights = {}
|
||||
self.coinbase_key = CECKey()
|
||||
self.coinbase_key.set_secretbytes(b"horsebattery")
|
||||
|
|
|
@ -92,8 +92,7 @@ class CNodeNoVerackIdle(CLazyNode):
|
|||
conn.send_message(msg_getaddr())
|
||||
|
||||
class P2PLeakTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
self.extra_args = [['-banscore='+str(banscore)]]
|
||||
|
||||
|
|
|
@ -13,9 +13,7 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
from test_framework.util import *
|
||||
|
||||
class P2PMempoolTests(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
self.extra_args = [["-peerbloomfilters=0"]]
|
||||
|
|
|
@ -33,8 +33,7 @@ def get_virtual_size(witness_block):
|
|||
return vsize
|
||||
|
||||
class TestNode(NodeConnCB):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.getdataset = set()
|
||||
|
||||
def on_getdata(self, conn, message):
|
||||
|
@ -109,9 +108,7 @@ def sign_P2PK_witness_input(script, txTo, inIdx, hashtype, value, key):
|
|||
|
||||
|
||||
class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 3
|
||||
self.extra_args = [["-whitelist=127.0.0.1"], ["-whitelist=127.0.0.1", "-acceptnonstdtxn=0"], ["-whitelist=127.0.0.1", "-vbparams=segwit:0:0"]]
|
||||
|
|
|
@ -33,8 +33,7 @@ class TestNode(NodeConnCB):
|
|||
pass
|
||||
|
||||
class TimeoutsTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
|
||||
|
|
|
@ -28,8 +28,7 @@ class TestNode(NodeConnCB):
|
|||
pass
|
||||
|
||||
class VersionBitsWarningTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
|
||||
|
|
|
@ -35,8 +35,7 @@ def node_sync_via_rpc(nodes):
|
|||
unidirectional_node_sync_via_rpc(node_src, node_dest)
|
||||
|
||||
class PreciousTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 3
|
||||
|
||||
|
|
|
@ -9,9 +9,7 @@ from test_framework.util import *
|
|||
from test_framework.mininode import COIN, MAX_BLOCK_BASE_SIZE
|
||||
|
||||
class PrioritiseTransactionTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 2
|
||||
self.extra_args = [["-printpriority=1"], ["-printpriority=1"]]
|
||||
|
|
|
@ -41,13 +41,7 @@ from test_framework.netutil import test_ipv6_local
|
|||
|
||||
RANGE_BEGIN = PORT_MIN + 2 * PORT_RANGE # Start after p2p and rpc ports
|
||||
|
||||
|
||||
class ProxyTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.num_nodes = 4
|
||||
self.setup_clean_chain = False
|
||||
|
||||
def setup_nodes(self):
|
||||
self.have_ipv6 = test_ipv6_local()
|
||||
# Create two proxies on different ports
|
||||
|
|
|
@ -26,9 +26,7 @@ def calc_usage(blockdir):
|
|||
return sum(os.path.getsize(blockdir+f) for f in os.listdir(blockdir) if os.path.isfile(blockdir+f)) / (1024. * 1024.)
|
||||
|
||||
class PruneTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 6
|
||||
|
||||
|
|
|
@ -17,9 +17,7 @@ from test_framework.util import *
|
|||
|
||||
# Create one-input, one-output, no-fee transaction:
|
||||
class RawTransactionsTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 3
|
||||
|
||||
|
|
|
@ -23,11 +23,7 @@ def get_sub_array_from_array(object_array, to_match):
|
|||
return []
|
||||
|
||||
class ReceivedByTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.num_nodes = 4
|
||||
self.setup_clean_chain = False
|
||||
def set_test_params(self):
|
||||
self.enable_mocktime()
|
||||
|
||||
def run_test(self):
|
||||
|
|
|
@ -15,8 +15,7 @@ import time
|
|||
|
||||
class ReindexTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
|
||||
|
|
|
@ -61,10 +61,8 @@ def make_utxo(node, amount, confirmed=True, scriptPubKey=CScript([1])):
|
|||
|
||||
class ReplaceByFeeTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
self.setup_clean_chain = False
|
||||
self.extra_args= [["-maxorphantx=1000",
|
||||
"-whitelist=127.0.0.1",
|
||||
"-limitancestorcount=50",
|
||||
|
|
|
@ -8,11 +8,9 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
from test_framework.util import assert_equal, assert_raises_jsonrpc
|
||||
|
||||
class ResendWalletTransactionsTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.extra_args = [['--walletbroadcast=false']]
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
self.extra_args = [['--walletbroadcast=false']]
|
||||
|
||||
def run_test(self):
|
||||
# Should raise RPC_WALLET_ERROR (-4) if walletbroadcast is disabled.
|
||||
|
|
|
@ -43,8 +43,7 @@ def http_post_call(host, port, path, requestdata = '', response_object = 0):
|
|||
class RESTTest (BitcoinTestFramework):
|
||||
FORMAT_SEPARATOR = "."
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 3
|
||||
|
||||
|
|
|
@ -11,11 +11,8 @@ from test_framework.test_framework import BitcoinTestFramework, SkipTest
|
|||
from test_framework.util import *
|
||||
from test_framework.netutil import *
|
||||
|
||||
|
||||
class RPCBindTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
|
||||
|
|
|
@ -10,15 +10,8 @@ from test_framework.util import (
|
|||
assert_raises_jsonrpc,
|
||||
)
|
||||
|
||||
|
||||
class NamedArgumentTest(BitcoinTestFramework):
|
||||
"""
|
||||
Test named arguments on RPC calls.
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setup_clean_chain = False
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
|
||||
def run_test(self):
|
||||
|
|
|
@ -75,9 +75,7 @@ def find_unspent(node, min_value):
|
|||
return utxo
|
||||
|
||||
class SegWitTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 3
|
||||
self.extra_args = [["-walletprematurewitness", "-rpcserialversion=0"],
|
||||
|
|
|
@ -174,8 +174,7 @@ class TestNode(NodeConnCB):
|
|||
self.send_message(getblocks_message)
|
||||
|
||||
class SendHeadersTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 2
|
||||
|
||||
|
|
|
@ -7,9 +7,7 @@
|
|||
from test_framework.test_framework import BitcoinTestFramework
|
||||
|
||||
class SignMessagesTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
|
||||
|
|
|
@ -9,8 +9,7 @@ from test_framework.util import *
|
|||
|
||||
|
||||
class SignRawTransactionsTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
|
||||
|
|
|
@ -141,11 +141,8 @@ def check_estimates(node, fees_seen, max_invalid, print_estimates = True):
|
|||
|
||||
|
||||
class EstimateFeeTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 3
|
||||
self.setup_clean_chain = False
|
||||
|
||||
def setup_network(self):
|
||||
"""
|
||||
|
|
|
@ -48,58 +48,30 @@ BITCOIND_PROC_WAIT_TIMEOUT = 60
|
|||
class BitcoinTestFramework(object):
|
||||
"""Base class for a bitcoin test script.
|
||||
|
||||
Individual bitcoin test scripts should subclass this class and override the following methods:
|
||||
Individual bitcoin test scripts should subclass this class and override the run_test() method.
|
||||
|
||||
- __init__()
|
||||
Individual tests can also override the following methods to customize the test setup:
|
||||
|
||||
- set_test_params()
|
||||
- add_options()
|
||||
- setup_chain()
|
||||
- setup_network()
|
||||
- run_test()
|
||||
- setup_nodes()
|
||||
|
||||
The main() method should not be overridden.
|
||||
The __init__() and main() methods should not be overridden.
|
||||
|
||||
This class also contains various public and private helper methods."""
|
||||
|
||||
# Methods to override in subclass test scripts.
|
||||
def __init__(self):
|
||||
"""Sets test framework defaults. Do not override this method. Instead, override the set_test_params() method"""
|
||||
self.num_nodes = 4
|
||||
self.setup_clean_chain = False
|
||||
self.nodes = []
|
||||
self.mocktime = 0
|
||||
|
||||
def add_options(self, parser):
|
||||
pass
|
||||
|
||||
def setup_chain(self):
|
||||
self.log.info("Initializing test directory " + self.options.tmpdir)
|
||||
if self.setup_clean_chain:
|
||||
self._initialize_chain_clean()
|
||||
else:
|
||||
self._initialize_chain()
|
||||
|
||||
def setup_network(self):
|
||||
self.setup_nodes()
|
||||
|
||||
# Connect the nodes as a "chain". This allows us
|
||||
# to split the network between nodes 1 and 2 to get
|
||||
# two halves that can work on competing chains.
|
||||
for i in range(self.num_nodes - 1):
|
||||
connect_nodes_bi(self.nodes, i, i + 1)
|
||||
self.sync_all()
|
||||
|
||||
def setup_nodes(self):
|
||||
extra_args = None
|
||||
if hasattr(self, "extra_args"):
|
||||
extra_args = self.extra_args
|
||||
self.add_nodes(self.num_nodes, extra_args)
|
||||
self.start_nodes()
|
||||
|
||||
def run_test(self):
|
||||
raise NotImplementedError
|
||||
|
||||
# Main function. This should not be overridden by the subclass test scripts.
|
||||
self.set_test_params()
|
||||
|
||||
def main(self):
|
||||
"""Main function. This should not be overridden by the subclass test scripts."""
|
||||
|
||||
parser = optparse.OptionParser(usage="%prog [options]")
|
||||
parser.add_option("--nocleanup", dest="nocleanup", default=False, action="store_true",
|
||||
|
@ -203,6 +175,46 @@ class BitcoinTestFramework(object):
|
|||
logging.shutdown()
|
||||
sys.exit(TEST_EXIT_FAILED)
|
||||
|
||||
# Methods to override in subclass test scripts.
|
||||
def set_test_params(self):
|
||||
"""Override this method to change default values for number of nodes, topology, etc"""
|
||||
pass
|
||||
|
||||
def add_options(self, parser):
|
||||
"""Override this method to add command-line options to the test"""
|
||||
pass
|
||||
|
||||
def setup_chain(self):
|
||||
"""Override this method to customize blockchain setup"""
|
||||
self.log.info("Initializing test directory " + self.options.tmpdir)
|
||||
if self.setup_clean_chain:
|
||||
self._initialize_chain_clean()
|
||||
else:
|
||||
self._initialize_chain()
|
||||
|
||||
def setup_network(self):
|
||||
"""Override this method to customize test network topology"""
|
||||
self.setup_nodes()
|
||||
|
||||
# Connect the nodes as a "chain". This allows us
|
||||
# to split the network between nodes 1 and 2 to get
|
||||
# two halves that can work on competing chains.
|
||||
for i in range(self.num_nodes - 1):
|
||||
connect_nodes_bi(self.nodes, i, i + 1)
|
||||
self.sync_all()
|
||||
|
||||
def setup_nodes(self):
|
||||
"""Override this method to customize test node setup"""
|
||||
extra_args = None
|
||||
if hasattr(self, "extra_args"):
|
||||
extra_args = self.extra_args
|
||||
self.add_nodes(self.num_nodes, extra_args)
|
||||
self.start_nodes()
|
||||
|
||||
def run_test(self):
|
||||
"""Override this method to define test logic"""
|
||||
raise NotImplementedError
|
||||
|
||||
# Public helper methods. These can be accessed by the subclass test scripts.
|
||||
|
||||
def add_nodes(self, num_nodes, extra_args=None, rpchost=None, timewait=None, binary=None):
|
||||
|
@ -442,8 +454,7 @@ class ComparisonTestFramework(BitcoinTestFramework):
|
|||
- 2 binaries: 1 test binary, 1 ref binary
|
||||
- n>2 binaries: 1 test binary, n-1 ref binaries"""
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 2
|
||||
self.setup_clean_chain = True
|
||||
|
||||
|
|
|
@ -8,12 +8,6 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
from test_framework.util import *
|
||||
|
||||
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")
|
||||
|
|
|
@ -9,11 +9,6 @@ from test_framework.util import *
|
|||
|
||||
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")
|
||||
|
|
|
@ -13,9 +13,7 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
|
||||
|
||||
class UptimeTest(BitcoinTestFramework):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
self.setup_clean_chain = True
|
||||
|
||||
|
|
|
@ -17,9 +17,7 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
from test_framework.util import assert_equal
|
||||
|
||||
class WalletAccountsTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
self.extra_args = [[]]
|
||||
|
|
|
@ -56,10 +56,7 @@ def read_dump(file_name, addrs, hd_master_addr_old):
|
|||
|
||||
|
||||
class WalletDumpTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setup_clean_chain = False
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 1
|
||||
self.extra_args = [["-keypool=90"]]
|
||||
|
||||
|
|
|
@ -13,9 +13,7 @@ from test_framework.util import (
|
|||
)
|
||||
|
||||
class WalletEncryptionTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 1
|
||||
|
||||
|
|
|
@ -11,11 +11,8 @@ from test_framework.util import (
|
|||
)
|
||||
import shutil
|
||||
|
||||
|
||||
class WalletHDTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 2
|
||||
self.extra_args = [['-usehd=0'], ['-usehd=1', '-keypool=0']]
|
||||
|
|
|
@ -7,17 +7,8 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
from test_framework.util import *
|
||||
|
||||
class WalletTest(BitcoinTestFramework):
|
||||
|
||||
def check_fee_amount(self, curr_balance, balance_with_fee, fee_per_byte, tx_size):
|
||||
"""Return curr_balance after asserting the fee was in range"""
|
||||
fee = balance_with_fee - curr_balance
|
||||
assert_fee_amount(fee, tx_size, fee_per_byte * 1000)
|
||||
return curr_balance
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 4
|
||||
self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)]
|
||||
|
||||
def setup_network(self):
|
||||
|
@ -30,8 +21,13 @@ class WalletTest(BitcoinTestFramework):
|
|||
connect_nodes_bi(self.nodes,0,2)
|
||||
self.sync_all([self.nodes[0:3]])
|
||||
|
||||
def run_test(self):
|
||||
def check_fee_amount(self, curr_balance, balance_with_fee, fee_per_byte, tx_size):
|
||||
"""Return curr_balance after asserting the fee was in range"""
|
||||
fee = balance_with_fee - curr_balance
|
||||
assert_fee_amount(fee, tx_size, fee_per_byte * 1000)
|
||||
return curr_balance
|
||||
|
||||
def run_test(self):
|
||||
# Check that there's no UTXO on none of the nodes
|
||||
assert_equal(len(self.nodes[0].listunspent()), 0)
|
||||
assert_equal(len(self.nodes[1].listunspent()), 0)
|
||||
|
|
|
@ -37,11 +37,8 @@ from test_framework.test_framework import BitcoinTestFramework
|
|||
from test_framework.util import *
|
||||
|
||||
class WalletBackupTest(BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 4
|
||||
# nodes 1, 2,3 are spenders, let's give them a keypool=100
|
||||
self.extra_args = [["-keypool=100"], ["-keypool=100"], ["-keypool=100"], []]
|
||||
|
||||
|
|
|
@ -20,9 +20,7 @@ from test_framework.util import (assert_equal,
|
|||
)
|
||||
|
||||
class ZapWalletTXesTest (BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.setup_clean_chain = True
|
||||
self.num_nodes = 2
|
||||
|
||||
|
|
|
@ -13,9 +13,7 @@ from test_framework.util import (assert_equal,
|
|||
)
|
||||
|
||||
class ZMQTest (BitcoinTestFramework):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
def set_test_params(self):
|
||||
self.num_nodes = 2
|
||||
|
||||
def setup_nodes(self):
|
||||
|
|
Loading…
Reference in a new issue