Browse Source

[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.
0.16
John Newbery 8 years ago
parent
commit
5448a1471d
  1. 6
      test/functional/README.md
  2. 4
      test/functional/abandonconflict.py
  3. 3
      test/functional/assumevalid.py
  4. 4
      test/functional/bip65-cltv-p2p.py
  5. 4
      test/functional/bip68-112-113-p2p.py
  6. 4
      test/functional/bip68-sequence.py
  7. 5
      test/functional/bip9-softforks.py
  8. 4
      test/functional/bipdersig-p2p.py
  9. 6
      test/functional/blockchain.py
  10. 3
      test/functional/bumpfee.py
  11. 6
      test/functional/create_cache.py
  12. 3
      test/functional/dbcrash.py
  13. 4
      test/functional/decodescript.py
  14. 5
      test/functional/disablewallet.py
  15. 5
      test/functional/disconnect_ban.py
  16. 10
      test/functional/example_test.py
  17. 5
      test/functional/forknotify.py
  18. 6
      test/functional/fundrawtransaction.py
  19. 5
      test/functional/getblocktemplate_longpoll.py
  20. 6
      test/functional/getchaintips.py
  21. 4
      test/functional/httpbasics.py
  22. 3
      test/functional/import-rescan.py
  23. 3
      test/functional/importmulti.py
  24. 5
      test/functional/importprunedfunds.py
  25. 4
      test/functional/invalidateblock.py
  26. 4
      test/functional/invalidblockrequest.py
  27. 4
      test/functional/invalidtxrequest.py
  28. 3
      test/functional/keypool-topup.py
  29. 7
      test/functional/keypool.py
  30. 5
      test/functional/listsinceblock.py
  31. 5
      test/functional/listtransactions.py
  32. 3
      test/functional/maxuploadtarget.py
  33. 4
      test/functional/mempool_limit.py
  34. 4
      test/functional/mempool_packages.py
  35. 6
      test/functional/mempool_persist.py
  36. 4
      test/functional/mempool_reorg.py
  37. 6
      test/functional/mempool_resurrect_test.py
  38. 5
      test/functional/mempool_spendcoinbase.py
  39. 5
      test/functional/merkle_blocks.py
  40. 4
      test/functional/mining.py
  41. 5
      test/functional/multi_rpc.py
  42. 4
      test/functional/multiwallet.py
  43. 4
      test/functional/net.py
  44. 3
      test/functional/nulldummy.py
  45. 3
      test/functional/p2p-acceptblock.py
  46. 3
      test/functional/p2p-compactblocks.py
  47. 5
      test/functional/p2p-feefilter.py
  48. 5
      test/functional/p2p-fullblocktest.py
  49. 3
      test/functional/p2p-leaktests.py
  50. 4
      test/functional/p2p-mempool.py
  51. 7
      test/functional/p2p-segwit.py
  52. 3
      test/functional/p2p-timeouts.py
  53. 3
      test/functional/p2p-versionbits-warning.py
  54. 3
      test/functional/preciousblock.py
  55. 4
      test/functional/prioritise_transaction.py
  56. 6
      test/functional/proxy_test.py
  57. 4
      test/functional/pruning.py
  58. 4
      test/functional/rawtransactions.py
  59. 6
      test/functional/receivedby.py
  60. 3
      test/functional/reindex.py
  61. 4
      test/functional/replace-by-fee.py
  62. 6
      test/functional/resendwallettransactions.py
  63. 3
      test/functional/rest.py
  64. 5
      test/functional/rpcbind_test.py
  65. 9
      test/functional/rpcnamedargs.py
  66. 4
      test/functional/segwit.py
  67. 3
      test/functional/sendheaders.py
  68. 4
      test/functional/signmessages.py
  69. 3
      test/functional/signrawtransactions.py
  70. 5
      test/functional/smartfees.py
  71. 89
      test/functional/test_framework/test_framework.py
  72. 6
      test/functional/txn_clone.py
  73. 5
      test/functional/txn_doublespend.py
  74. 4
      test/functional/uptime.py
  75. 4
      test/functional/wallet-accounts.py
  76. 5
      test/functional/wallet-dump.py
  77. 4
      test/functional/wallet-encryption.py
  78. 5
      test/functional/wallet-hd.py
  79. 18
      test/functional/wallet.py
  80. 5
      test/functional/walletbackup.py
  81. 4
      test/functional/zapwallettxes.py
  82. 4
      test/functional/zmq_test.py

6
test/functional/README.md

@ -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 - Use a module-level docstring to describe what the test is testing, and how it
is testing it. is testing it.
- When subclassing the BitcoinTestFramwork, place overrides for the - When subclassing the BitcoinTestFramwork, place overrides for the
`__init__()`, and `setup_xxxx()` methods at the top of the subclass, then `set_test_params()`, `add_options()` and `setup_xxxx()` methods at the top of
locally-defined helper methods, then the `run_test()` method. the subclass, then locally-defined helper methods, then the `run_test()` method.
#### General test-writing advice #### 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 - 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 stop-start takes several seconds, so doing it several times blows up the
runtime of the test. 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 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 contain a 200-block pre-mined blockchain and wallets for four nodes. Each node
has 25 mature blocks (25x50=1250 BTC) in its wallet. has 25 mature blocks (25x50=1250 BTC) in its wallet.

4
test/functional/abandonconflict.py

@ -14,10 +14,8 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * from test_framework.util import *
class AbandonConflictTest(BitcoinTestFramework): class AbandonConflictTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.num_nodes = 2 self.num_nodes = 2
self.setup_clean_chain = False
self.extra_args = [["-minrelaytxfee=0.00001"], []] self.extra_args = [["-minrelaytxfee=0.00001"], []]
def run_test(self): def run_test(self):

3
test/functional/assumevalid.py

@ -54,8 +54,7 @@ class BaseNode(NodeConnCB):
self.send_message(headers_message) self.send_message(headers_message)
class AssumeValidTest(BitcoinTestFramework): class AssumeValidTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 3 self.num_nodes = 3

4
test/functional/bip65-cltv-p2p.py

@ -60,9 +60,7 @@ def create_transaction(node, coinbase, to_address, amount):
return tx return tx
class BIP65Test(BitcoinTestFramework): class BIP65Test(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
self.extra_args = [['-promiscuousmempoolflags=1', '-whitelist=127.0.0.1']] self.extra_args = [['-promiscuousmempoolflags=1', '-whitelist=127.0.0.1']]
self.setup_clean_chain = True self.setup_clean_chain = True

4
test/functional/bip68-112-113-p2p.py

@ -92,9 +92,9 @@ def all_rlt_txs(txarray):
return txs return txs
class BIP68_112_113Test(ComparisonTestFramework): class BIP68_112_113Test(ComparisonTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
self.setup_clean_chain = True
self.extra_args = [['-whitelist=127.0.0.1', '-blockversion=4']] self.extra_args = [['-whitelist=127.0.0.1', '-blockversion=4']]
def run_test(self): def run_test(self):

4
test/functional/bip68-sequence.py

@ -17,10 +17,8 @@ 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): def set_test_params(self):
super().__init__()
self.num_nodes = 2 self.num_nodes = 2
self.setup_clean_chain = False
self.extra_args = [[], ["-acceptnonstdtxn=0"]] self.extra_args = [[], ["-acceptnonstdtxn=0"]]
def run_test(self): def run_test(self):

5
test/functional/bip9-softforks.py

@ -28,11 +28,10 @@ from test_framework.comptool import TestInstance, TestManager
from test_framework.script import CScript, OP_1NEGATE, OP_CHECKSEQUENCEVERIFY, OP_DROP from test_framework.script import CScript, OP_1NEGATE, OP_CHECKSEQUENCEVERIFY, OP_DROP
class BIP9SoftForksTest(ComparisonTestFramework): class BIP9SoftForksTest(ComparisonTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
self.extra_args = [['-whitelist=127.0.0.1']] self.extra_args = [['-whitelist=127.0.0.1']]
self.setup_clean_chain = True
def run_test(self): def run_test(self):
self.test = TestManager(self, self.options.tmpdir) self.test = TestManager(self, self.options.tmpdir)

4
test/functional/bipdersig-p2p.py

@ -48,9 +48,7 @@ def create_transaction(node, coinbase, to_address, amount):
return tx return tx
class BIP66Test(BitcoinTestFramework): class BIP66Test(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
self.extra_args = [['-promiscuousmempoolflags=1', '-whitelist=127.0.0.1']] self.extra_args = [['-promiscuousmempoolflags=1', '-whitelist=127.0.0.1']]
self.setup_clean_chain = True self.setup_clean_chain = True

6
test/functional/blockchain.py

@ -30,12 +30,8 @@ from test_framework.util import (
assert_is_hash_string, assert_is_hash_string,
) )
class BlockchainTest(BitcoinTestFramework): class BlockchainTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = False
self.num_nodes = 1 self.num_nodes = 1
self.extra_args = [['-stopatheight=207']] self.extra_args = [['-stopatheight=207']]

3
test/functional/bumpfee.py

@ -30,8 +30,7 @@ WALLET_PASSPHRASE_TIMEOUT = 3600
class BumpFeeTest(BitcoinTestFramework): class BumpFeeTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.num_nodes = 2 self.num_nodes = 2
self.setup_clean_chain = True self.setup_clean_chain = True
self.extra_args = [["-prematurewitness", "-walletprematurewitness", "-walletrbf={}".format(i)] self.extra_args = [["-prematurewitness", "-walletprematurewitness", "-walletrbf={}".format(i)]

6
test/functional/create_cache.py

@ -12,11 +12,9 @@ tests are being run in parallel.
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
class CreateCache(BitcoinTestFramework): class CreateCache(BitcoinTestFramework):
# Test network and test nodes are not required:
def __init__(self): def set_test_params(self):
super().__init__()
# Test network and test nodes are not required:
self.num_nodes = 0 self.num_nodes = 0
def setup_network(self): def setup_network(self):

3
test/functional/dbcrash.py

@ -43,8 +43,7 @@ except AttributeError:
pass pass
class ChainstateWriteCrashTest(BitcoinTestFramework): class ChainstateWriteCrashTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.num_nodes = 4 self.num_nodes = 4
self.setup_clean_chain = False self.setup_clean_chain = False

4
test/functional/decodescript.py

@ -10,9 +10,7 @@ from test_framework.mininode import *
from io import BytesIO from io import BytesIO
class DecodeScriptTest(BitcoinTestFramework): class DecodeScriptTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 1 self.num_nodes = 1

5
test/functional/disablewallet.py

@ -11,11 +11,8 @@
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * from test_framework.util import *
class DisableWalletTest (BitcoinTestFramework): class DisableWalletTest (BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 1 self.num_nodes = 1
self.extra_args = [["-disablewallet"]] self.extra_args = [["-disablewallet"]]

5
test/functional/disconnect_ban.py

@ -14,11 +14,8 @@ from test_framework.util import (
) )
class DisconnectBanTest(BitcoinTestFramework): class DisconnectBanTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.num_nodes = 2 self.num_nodes = 2
self.setup_clean_chain = False
def run_test(self): def run_test(self):
self.log.info("Test setban and listbanned RPCs") self.log.info("Test setban and listbanned RPCs")

10
test/functional/example_test.py

@ -73,15 +73,11 @@ def custom_function():
class ExampleTest(BitcoinTestFramework): class ExampleTest(BitcoinTestFramework):
# Each functional test is a subclass of the BitcoinTestFramework class. # 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. # and setup_nodes() methods to customize the test setup as required.
def __init__(self): def set_test_params(self):
"""Initialize the test """Override any test parameters for your individual test."""
Call super().__init__() first, and then override any test parameters
for your individual test."""
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 3 self.num_nodes = 3
# Use self.extra_args to change command-line arguments for the nodes # Use self.extra_args to change command-line arguments for the nodes

5
test/functional/forknotify.py

@ -9,11 +9,8 @@ import time
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
class ForkNotifyTest(BitcoinTestFramework): class ForkNotifyTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.num_nodes = 2 self.num_nodes = 2
self.setup_clean_chain = False
def setup_network(self): def setup_network(self):
self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt") self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")

6
test/functional/fundrawtransaction.py

@ -14,13 +14,9 @@ def get_unspent(listunspent, amount):
return utx return utx
raise AssertionError('Could not find unspent with amount={}'.format(amount)) raise AssertionError('Could not find unspent with amount={}'.format(amount))
class RawTransactionsTest(BitcoinTestFramework): class RawTransactionsTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 4
def setup_network(self, split=False): def setup_network(self, split=False):
self.setup_nodes() self.setup_nodes()

5
test/functional/getblocktemplate_longpoll.py

@ -23,11 +23,6 @@ class LongpollThread(threading.Thread):
self.node.getblocktemplate({'longpollid':self.longpollid}) self.node.getblocktemplate({'longpollid':self.longpollid})
class GetBlockTemplateLPTest(BitcoinTestFramework): class GetBlockTemplateLPTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 4
self.setup_clean_chain = False
def run_test(self): def run_test(self):
self.log.info("Warning: this test will take about 70 seconds in the best case. Be patient.") self.log.info("Warning: this test will take about 70 seconds in the best case. Be patient.")
self.nodes[0].generate(10) self.nodes[0].generate(10)

6
test/functional/getchaintips.py

@ -14,13 +14,7 @@ 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):
tips = self.nodes[0].getchaintips () tips = self.nodes[0].getchaintips ()
assert_equal (len (tips), 1) assert_equal (len (tips), 1)
assert_equal (tips[0]['branchlen'], 0) assert_equal (tips[0]['branchlen'], 0)

4
test/functional/httpbasics.py

@ -11,10 +11,8 @@ import http.client
import urllib.parse import urllib.parse
class HTTPBasicsTest (BitcoinTestFramework): class HTTPBasicsTest (BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.num_nodes = 3 self.num_nodes = 3
self.setup_clean_chain = False
def setup_network(self): def setup_network(self):
self.setup_nodes() self.setup_nodes()

3
test/functional/import-rescan.py

@ -111,8 +111,7 @@ TIMESTAMP_WINDOW = 2 * 60 * 60
class ImportRescanTest(BitcoinTestFramework): class ImportRescanTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.num_nodes = 2 + len(IMPORT_NODES) self.num_nodes = 2 + len(IMPORT_NODES)
def setup_network(self): def setup_network(self):

3
test/functional/importmulti.py

@ -7,8 +7,7 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * from test_framework.util import *
class ImportMultiTest (BitcoinTestFramework): class ImportMultiTest (BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.num_nodes = 2 self.num_nodes = 2
self.setup_clean_chain = True self.setup_clean_chain = True

5
test/functional/importprunedfunds.py

@ -6,11 +6,8 @@
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * from test_framework.util import *
class ImportPrunedFundsTest(BitcoinTestFramework): class ImportPrunedFundsTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 2 self.num_nodes = 2

4
test/functional/invalidateblock.py

@ -8,9 +8,7 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * from test_framework.util import *
class InvalidateTest(BitcoinTestFramework): class InvalidateTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 3 self.num_nodes = 3

4
test/functional/invalidblockrequest.py

@ -23,9 +23,9 @@ 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 set_test_params(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
self.setup_clean_chain = True
def run_test(self): def run_test(self):
test = TestManager(self, self.options.tmpdir) test = TestManager(self, self.options.tmpdir)

4
test/functional/invalidtxrequest.py

@ -19,9 +19,9 @@ 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 set_test_params(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
self.setup_clean_chain = True
def run_test(self): def run_test(self):
test = TestManager(self, self.options.tmpdir) test = TestManager(self, self.options.tmpdir)

3
test/functional/keypool-topup.py

@ -20,8 +20,7 @@ from test_framework.util import (
) )
class KeypoolRestoreTest(BitcoinTestFramework): class KeypoolRestoreTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 2 self.num_nodes = 2
self.extra_args = [['-usehd=0'], ['-usehd=1', '-keypool=100', '-keypoolmin=20']] self.extra_args = [['-usehd=0'], ['-usehd=1', '-keypool=100', '-keypoolmin=20']]

7
test/functional/keypool.py

@ -8,6 +8,8 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * from test_framework.util import *
class KeyPoolTest(BitcoinTestFramework): class KeyPoolTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
def run_test(self): def run_test(self):
nodes = self.nodes nodes = self.nodes
@ -78,10 +80,5 @@ class KeyPoolTest(BitcoinTestFramework):
assert_equal(wi['keypoolsize_hd_internal'], 100) assert_equal(wi['keypoolsize_hd_internal'], 100)
assert_equal(wi['keypoolsize'], 100) assert_equal(wi['keypoolsize'], 100)
def __init__(self):
super().__init__()
self.setup_clean_chain = False
self.num_nodes = 1
if __name__ == '__main__': if __name__ == '__main__':
KeyPoolTest().main() KeyPoolTest().main()

5
test/functional/listsinceblock.py

@ -8,11 +8,8 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal from test_framework.util import assert_equal
class ListSinceBlockTest (BitcoinTestFramework): class ListSinceBlockTest (BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 4
def run_test(self): def run_test(self):
self.nodes[2].generate(101) self.nodes[2].generate(101)

5
test/functional/listtransactions.py

@ -16,10 +16,7 @@ def txFromHex(hexstring):
return tx return tx
class ListTransactionsTest(BitcoinTestFramework): class ListTransactionsTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.num_nodes = 4
self.setup_clean_chain = False
self.enable_mocktime() self.enable_mocktime()
def run_test(self): def run_test(self):

3
test/functional/maxuploadtarget.py

@ -31,8 +31,7 @@ class TestNode(NodeConnCB):
class MaxUploadTest(BitcoinTestFramework): class MaxUploadTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 1 self.num_nodes = 1
self.extra_args = [["-maxuploadtarget=800", "-blockmaxsize=999000"]] self.extra_args = [["-maxuploadtarget=800", "-blockmaxsize=999000"]]

4
test/functional/mempool_limit.py

@ -8,9 +8,7 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * from test_framework.util import *
class MempoolLimitTest(BitcoinTestFramework): class MempoolLimitTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 1 self.num_nodes = 1
self.extra_args = [["-maxmempool=5", "-spendzeroconfchange=0"]] self.extra_args = [["-maxmempool=5", "-spendzeroconfchange=0"]]

4
test/functional/mempool_packages.py

@ -12,10 +12,8 @@ MAX_ANCESTORS = 25
MAX_DESCENDANTS = 25 MAX_DESCENDANTS = 25
class MempoolPackagesTest(BitcoinTestFramework): class MempoolPackagesTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.num_nodes = 2 self.num_nodes = 2
self.setup_clean_chain = False
self.extra_args = [["-maxorphantx=1000"], ["-maxorphantx=1000", "-limitancestorcount=5"]] self.extra_args = [["-maxorphantx=1000"], ["-maxorphantx=1000", "-limitancestorcount=5"]]
# Build a transaction that spends parent_txid:vout # Build a transaction that spends parent_txid:vout

6
test/functional/mempool_persist.py

@ -36,12 +36,8 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * from test_framework.util import *
class MempoolPersistTest(BitcoinTestFramework): class MempoolPersistTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
# We need 3 nodes for this test. Node1 does not have a persistent mempool.
self.num_nodes = 3 self.num_nodes = 3
self.setup_clean_chain = False
self.extra_args = [[], ["-persistmempool=0"], []] self.extra_args = [[], ["-persistmempool=0"], []]
def run_test(self): def run_test(self):

4
test/functional/mempool_reorg.py

@ -13,10 +13,8 @@ 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): def set_test_params(self):
super().__init__()
self.num_nodes = 2 self.num_nodes = 2
self.setup_clean_chain = False
self.extra_args = [["-checkmempool"]] * 2 self.extra_args = [["-checkmempool"]] * 2
alert_filename = None # Set by setup_network alert_filename = None # Set by setup_network

6
test/functional/mempool_resurrect_test.py

@ -9,12 +9,8 @@ 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 set_test_params(self):
def __init__(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
self.setup_clean_chain = False
# Just need one node for this test
self.extra_args = [["-checkmempool"]] self.extra_args = [["-checkmempool"]]
def run_test(self): def run_test(self):

5
test/functional/mempool_spendcoinbase.py

@ -17,11 +17,8 @@ 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 set_test_params(self):
def __init__(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
self.setup_clean_chain = False
self.extra_args = [["-checkmempool"]] self.extra_args = [["-checkmempool"]]
def run_test(self): def run_test(self):

5
test/functional/merkle_blocks.py

@ -8,11 +8,8 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * from test_framework.util import *
class MerkleBlockTest(BitcoinTestFramework): class MerkleBlockTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 4
# Nodes 0/1 are "wallet" nodes, Nodes 2/3 are used for testing # Nodes 0/1 are "wallet" nodes, Nodes 2/3 are used for testing
self.extra_args = [[], [], [], ["-txindex"]] self.extra_args = [[], [], [], ["-txindex"]]

4
test/functional/mining.py

@ -25,9 +25,7 @@ def assert_template(node, block, expect, rehash=True):
assert_equal(rsp, expect) assert_equal(rsp, expect)
class MiningTest(BitcoinTestFramework): class MiningTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.num_nodes = 2 self.num_nodes = 2
self.setup_clean_chain = False self.setup_clean_chain = False

5
test/functional/multi_rpc.py

@ -12,10 +12,7 @@ import http.client
import urllib.parse import urllib.parse
class HTTPBasicsTest (BitcoinTestFramework): class HTTPBasicsTest (BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = False
self.num_nodes = 2 self.num_nodes = 2
def setup_chain(self): def setup_chain(self):

4
test/functional/multiwallet.py

@ -12,9 +12,7 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_jsonrpc from test_framework.util import assert_equal, assert_raises_jsonrpc
class MultiWalletTest(BitcoinTestFramework): class MultiWalletTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 1 self.num_nodes = 1
self.extra_args = [['-wallet=w1', '-wallet=w2', '-wallet=w3']] self.extra_args = [['-wallet=w1', '-wallet=w2', '-wallet=w3']]

4
test/functional/net.py

@ -17,10 +17,8 @@ from test_framework.util import (
p2p_port, p2p_port,
) )
class NetTest(BitcoinTestFramework): class NetTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 2 self.num_nodes = 2

3
test/functional/nulldummy.py

@ -37,8 +37,7 @@ def trueDummy(tx):
class NULLDUMMYTest(BitcoinTestFramework): class NULLDUMMYTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
self.setup_clean_chain = True self.setup_clean_chain = True
self.extra_args = [['-whitelist=127.0.0.1', '-walletprematurewitness']] self.extra_args = [['-whitelist=127.0.0.1', '-walletprematurewitness']]

3
test/functional/p2p-acceptblock.py

@ -60,8 +60,7 @@ class AcceptBlockTest(BitcoinTestFramework):
default=os.getenv("BITCOIND", "bitcoind"), default=os.getenv("BITCOIND", "bitcoind"),
help="bitcoind binary to test") help="bitcoind binary to test")
def __init__(self): def set_test_params(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 2 self.num_nodes = 2
self.extra_args = [[], ["-whitelist=127.0.0.1"]] self.extra_args = [[], ["-whitelist=127.0.0.1"]]

3
test/functional/p2p-compactblocks.py

@ -89,8 +89,7 @@ class TestNode(NodeConnCB):
wait_until(lambda: not self.connected, timeout=timeout, lock=mininode_lock) wait_until(lambda: not self.connected, timeout=timeout, lock=mininode_lock)
class CompactBlocksTest(BitcoinTestFramework): class CompactBlocksTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
# Node0 = pre-segwit, node1 = segwit-aware # Node0 = pre-segwit, node1 = segwit-aware
self.num_nodes = 2 self.num_nodes = 2

5
test/functional/p2p-feefilter.py

@ -37,11 +37,8 @@ class TestNode(NodeConnCB):
self.txinvs = [] self.txinvs = []
class FeeFilterTest(BitcoinTestFramework): class FeeFilterTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.num_nodes = 2 self.num_nodes = 2
self.setup_clean_chain = False
def run_test(self): def run_test(self):
node1 = self.nodes[1] node1 = self.nodes[1]

5
test/functional/p2p-fullblocktest.py

@ -49,12 +49,11 @@ class CBrokenBlock(CBlock):
return r return r
class FullBlockTest(ComparisonTestFramework): 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 set_test_params(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
self.setup_clean_chain = True
self.block_heights = {} self.block_heights = {}
self.coinbase_key = CECKey() self.coinbase_key = CECKey()
self.coinbase_key.set_secretbytes(b"horsebattery") self.coinbase_key.set_secretbytes(b"horsebattery")

3
test/functional/p2p-leaktests.py

@ -92,8 +92,7 @@ class CNodeNoVerackIdle(CLazyNode):
conn.send_message(msg_getaddr()) conn.send_message(msg_getaddr())
class P2PLeakTest(BitcoinTestFramework): class P2PLeakTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
self.extra_args = [['-banscore='+str(banscore)]] self.extra_args = [['-banscore='+str(banscore)]]

4
test/functional/p2p-mempool.py

@ -13,9 +13,7 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * from test_framework.util import *
class P2PMempoolTests(BitcoinTestFramework): class P2PMempoolTests(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 1 self.num_nodes = 1
self.extra_args = [["-peerbloomfilters=0"]] self.extra_args = [["-peerbloomfilters=0"]]

7
test/functional/p2p-segwit.py

@ -33,8 +33,7 @@ def get_virtual_size(witness_block):
return vsize return vsize
class TestNode(NodeConnCB): class TestNode(NodeConnCB):
def __init__(self): def set_test_params(self):
super().__init__()
self.getdataset = set() self.getdataset = set()
def on_getdata(self, conn, message): def on_getdata(self, conn, message):
@ -109,9 +108,7 @@ def sign_P2PK_witness_input(script, txTo, inIdx, hashtype, value, key):
class SegWitTest(BitcoinTestFramework): class SegWitTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 3 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"]] self.extra_args = [["-whitelist=127.0.0.1"], ["-whitelist=127.0.0.1", "-acceptnonstdtxn=0"], ["-whitelist=127.0.0.1", "-vbparams=segwit:0:0"]]

3
test/functional/p2p-timeouts.py

@ -33,8 +33,7 @@ class TestNode(NodeConnCB):
pass pass
class TimeoutsTest(BitcoinTestFramework): class TimeoutsTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 1 self.num_nodes = 1

3
test/functional/p2p-versionbits-warning.py

@ -28,8 +28,7 @@ class TestNode(NodeConnCB):
pass pass
class VersionBitsWarningTest(BitcoinTestFramework): class VersionBitsWarningTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 1 self.num_nodes = 1

3
test/functional/preciousblock.py

@ -35,8 +35,7 @@ def node_sync_via_rpc(nodes):
unidirectional_node_sync_via_rpc(node_src, node_dest) unidirectional_node_sync_via_rpc(node_src, node_dest)
class PreciousTest(BitcoinTestFramework): class PreciousTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 3 self.num_nodes = 3

4
test/functional/prioritise_transaction.py

@ -9,9 +9,7 @@ from test_framework.util import *
from test_framework.mininode import COIN, MAX_BLOCK_BASE_SIZE from test_framework.mininode import COIN, MAX_BLOCK_BASE_SIZE
class PrioritiseTransactionTest(BitcoinTestFramework): class PrioritiseTransactionTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 2 self.num_nodes = 2
self.extra_args = [["-printpriority=1"], ["-printpriority=1"]] self.extra_args = [["-printpriority=1"], ["-printpriority=1"]]

6
test/functional/proxy_test.py

@ -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 RANGE_BEGIN = PORT_MIN + 2 * PORT_RANGE # Start after p2p and rpc ports
class ProxyTest(BitcoinTestFramework): class ProxyTest(BitcoinTestFramework):
def __init__(self):
super().__init__()
self.num_nodes = 4
self.setup_clean_chain = False
def setup_nodes(self): def setup_nodes(self):
self.have_ipv6 = test_ipv6_local() self.have_ipv6 = test_ipv6_local()
# Create two proxies on different ports # Create two proxies on different ports

4
test/functional/pruning.py

@ -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.) return sum(os.path.getsize(blockdir+f) for f in os.listdir(blockdir) if os.path.isfile(blockdir+f)) / (1024. * 1024.)
class PruneTest(BitcoinTestFramework): class PruneTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 6 self.num_nodes = 6

4
test/functional/rawtransactions.py

@ -17,9 +17,7 @@ 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 set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 3 self.num_nodes = 3

6
test/functional/receivedby.py

@ -23,11 +23,7 @@ def get_sub_array_from_array(object_array, to_match):
return [] return []
class ReceivedByTest(BitcoinTestFramework): class ReceivedByTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.num_nodes = 4
self.setup_clean_chain = False
self.enable_mocktime() self.enable_mocktime()
def run_test(self): def run_test(self):

3
test/functional/reindex.py

@ -15,8 +15,7 @@ import time
class ReindexTest(BitcoinTestFramework): class ReindexTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 1 self.num_nodes = 1

4
test/functional/replace-by-fee.py

@ -61,10 +61,8 @@ def make_utxo(node, amount, confirmed=True, scriptPubKey=CScript([1])):
class ReplaceByFeeTest(BitcoinTestFramework): class ReplaceByFeeTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
self.setup_clean_chain = False
self.extra_args= [["-maxorphantx=1000", self.extra_args= [["-maxorphantx=1000",
"-whitelist=127.0.0.1", "-whitelist=127.0.0.1",
"-limitancestorcount=50", "-limitancestorcount=50",

6
test/functional/resendwallettransactions.py

@ -8,11 +8,9 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, assert_raises_jsonrpc from test_framework.util import assert_equal, assert_raises_jsonrpc
class ResendWalletTransactionsTest(BitcoinTestFramework): class ResendWalletTransactionsTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.extra_args = [['--walletbroadcast=false']]
self.num_nodes = 1 self.num_nodes = 1
self.extra_args = [['--walletbroadcast=false']]
def run_test(self): def run_test(self):
# Should raise RPC_WALLET_ERROR (-4) if walletbroadcast is disabled. # Should raise RPC_WALLET_ERROR (-4) if walletbroadcast is disabled.

3
test/functional/rest.py

@ -43,8 +43,7 @@ def http_post_call(host, port, path, requestdata = '', response_object = 0):
class RESTTest (BitcoinTestFramework): class RESTTest (BitcoinTestFramework):
FORMAT_SEPARATOR = "." FORMAT_SEPARATOR = "."
def __init__(self): def set_test_params(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 3 self.num_nodes = 3

5
test/functional/rpcbind_test.py

@ -11,11 +11,8 @@ from test_framework.test_framework import BitcoinTestFramework, SkipTest
from test_framework.util import * from test_framework.util import *
from test_framework.netutil import * from test_framework.netutil import *
class RPCBindTest(BitcoinTestFramework): class RPCBindTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 1 self.num_nodes = 1

9
test/functional/rpcnamedargs.py

@ -10,15 +10,8 @@ from test_framework.util import (
assert_raises_jsonrpc, assert_raises_jsonrpc,
) )
class NamedArgumentTest(BitcoinTestFramework): class NamedArgumentTest(BitcoinTestFramework):
""" def set_test_params(self):
Test named arguments on RPC calls.
"""
def __init__(self):
super().__init__()
self.setup_clean_chain = False
self.num_nodes = 1 self.num_nodes = 1
def run_test(self): def run_test(self):

4
test/functional/segwit.py

@ -75,9 +75,7 @@ def find_unspent(node, min_value):
return utxo return utxo
class SegWitTest(BitcoinTestFramework): class SegWitTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 3 self.num_nodes = 3
self.extra_args = [["-walletprematurewitness", "-rpcserialversion=0"], self.extra_args = [["-walletprematurewitness", "-rpcserialversion=0"],

3
test/functional/sendheaders.py

@ -174,8 +174,7 @@ class TestNode(NodeConnCB):
self.send_message(getblocks_message) self.send_message(getblocks_message)
class SendHeadersTest(BitcoinTestFramework): class SendHeadersTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 2 self.num_nodes = 2

4
test/functional/signmessages.py

@ -7,9 +7,7 @@
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
class SignMessagesTest(BitcoinTestFramework): class SignMessagesTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 1 self.num_nodes = 1

3
test/functional/signrawtransactions.py

@ -9,8 +9,7 @@ from test_framework.util import *
class SignRawTransactionsTest(BitcoinTestFramework): class SignRawTransactionsTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 1 self.num_nodes = 1

5
test/functional/smartfees.py

@ -141,11 +141,8 @@ def check_estimates(node, fees_seen, max_invalid, print_estimates = True):
class EstimateFeeTest(BitcoinTestFramework): class EstimateFeeTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.num_nodes = 3 self.num_nodes = 3
self.setup_clean_chain = False
def setup_network(self): def setup_network(self):
""" """

89
test/functional/test_framework/test_framework.py

@ -48,58 +48,30 @@ BITCOIND_PROC_WAIT_TIMEOUT = 60
class BitcoinTestFramework(object): class BitcoinTestFramework(object):
"""Base class for a bitcoin test script. """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() - add_options()
- setup_chain() - setup_chain()
- setup_network() - 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.""" This class also contains various public and private helper methods."""
# Methods to override in subclass test scripts.
def __init__(self): def __init__(self):
"""Sets test framework defaults. Do not override this method. Instead, override the set_test_params() method"""
self.num_nodes = 4 self.num_nodes = 4
self.setup_clean_chain = False self.setup_clean_chain = False
self.nodes = [] self.nodes = []
self.mocktime = 0 self.mocktime = 0
self.set_test_params()
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.
def main(self): def main(self):
"""Main function. This should not be overridden by the subclass test scripts."""
parser = optparse.OptionParser(usage="%prog [options]") parser = optparse.OptionParser(usage="%prog [options]")
parser.add_option("--nocleanup", dest="nocleanup", default=False, action="store_true", parser.add_option("--nocleanup", dest="nocleanup", default=False, action="store_true",
@ -203,6 +175,46 @@ class BitcoinTestFramework(object):
logging.shutdown() logging.shutdown()
sys.exit(TEST_EXIT_FAILED) 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. # 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): 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 - 2 binaries: 1 test binary, 1 ref binary
- n>2 binaries: 1 test binary, n-1 ref binaries""" - n>2 binaries: 1 test binary, n-1 ref binaries"""
def __init__(self): def set_test_params(self):
super().__init__()
self.num_nodes = 2 self.num_nodes = 2
self.setup_clean_chain = True self.setup_clean_chain = True

6
test/functional/txn_clone.py

@ -8,12 +8,6 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * 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")

5
test/functional/txn_doublespend.py

@ -9,11 +9,6 @@ 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")

4
test/functional/uptime.py

@ -13,9 +13,7 @@ from test_framework.test_framework import BitcoinTestFramework
class UptimeTest(BitcoinTestFramework): class UptimeTest(BitcoinTestFramework):
def __init__(self): def set_test_params(self):
super().__init__()
self.num_nodes = 1 self.num_nodes = 1
self.setup_clean_chain = True self.setup_clean_chain = True

4
test/functional/wallet-accounts.py

@ -17,9 +17,7 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal from test_framework.util import assert_equal
class WalletAccountsTest(BitcoinTestFramework): class WalletAccountsTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 1 self.num_nodes = 1
self.extra_args = [[]] self.extra_args = [[]]

5
test/functional/wallet-dump.py

@ -56,10 +56,7 @@ def read_dump(file_name, addrs, hd_master_addr_old):
class WalletDumpTest(BitcoinTestFramework): class WalletDumpTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = False
self.num_nodes = 1 self.num_nodes = 1
self.extra_args = [["-keypool=90"]] self.extra_args = [["-keypool=90"]]

4
test/functional/wallet-encryption.py

@ -13,9 +13,7 @@ from test_framework.util import (
) )
class WalletEncryptionTest(BitcoinTestFramework): class WalletEncryptionTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 1 self.num_nodes = 1

5
test/functional/wallet-hd.py

@ -11,11 +11,8 @@ from test_framework.util import (
) )
import shutil import shutil
class WalletHDTest(BitcoinTestFramework): class WalletHDTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 2 self.num_nodes = 2
self.extra_args = [['-usehd=0'], ['-usehd=1', '-keypool=0']] self.extra_args = [['-usehd=0'], ['-usehd=1', '-keypool=0']]

18
test/functional/wallet.py

@ -7,17 +7,8 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * from test_framework.util import *
class WalletTest(BitcoinTestFramework): class WalletTest(BitcoinTestFramework):
def set_test_params(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 __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 4
self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)] self.extra_args = [['-usehd={:d}'.format(i%2==0)] for i in range(4)]
def setup_network(self): def setup_network(self):
@ -30,8 +21,13 @@ class WalletTest(BitcoinTestFramework):
connect_nodes_bi(self.nodes,0,2) connect_nodes_bi(self.nodes,0,2)
self.sync_all([self.nodes[0:3]]) 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 # Check that there's no UTXO on none of the nodes
assert_equal(len(self.nodes[0].listunspent()), 0) assert_equal(len(self.nodes[0].listunspent()), 0)
assert_equal(len(self.nodes[1].listunspent()), 0) assert_equal(len(self.nodes[1].listunspent()), 0)

5
test/functional/walletbackup.py

@ -37,11 +37,8 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import * from test_framework.util import *
class WalletBackupTest(BitcoinTestFramework): class WalletBackupTest(BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 4
# 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
self.extra_args = [["-keypool=100"], ["-keypool=100"], ["-keypool=100"], []] self.extra_args = [["-keypool=100"], ["-keypool=100"], ["-keypool=100"], []]

4
test/functional/zapwallettxes.py

@ -20,9 +20,7 @@ from test_framework.util import (assert_equal,
) )
class ZapWalletTXesTest (BitcoinTestFramework): class ZapWalletTXesTest (BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.setup_clean_chain = True self.setup_clean_chain = True
self.num_nodes = 2 self.num_nodes = 2

4
test/functional/zmq_test.py

@ -13,9 +13,7 @@ from test_framework.util import (assert_equal,
) )
class ZMQTest (BitcoinTestFramework): class ZMQTest (BitcoinTestFramework):
def set_test_params(self):
def __init__(self):
super().__init__()
self.num_nodes = 2 self.num_nodes = 2
def setup_nodes(self): def setup_nodes(self):

Loading…
Cancel
Save