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.

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

+ 3
- 3
test/functional/README.md View File

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

+ 1
- 3
test/functional/abandonconflict.py View File

@@ -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):

+ 1
- 2
test/functional/assumevalid.py View File

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


+ 1
- 3
test/functional/bip65-cltv-p2p.py View File

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

+ 2
- 2
test/functional/bip68-112-113-p2p.py View File

@@ -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):

+ 1
- 3
test/functional/bip68-sequence.py View File

@@ -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):

+ 2
- 3
test/functional/bip9-softforks.py View File

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

+ 1
- 3
test/functional/bipdersig-p2p.py View File

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

+ 1
- 5
test/functional/blockchain.py View File

@@ -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']]


+ 1
- 2
test/functional/bumpfee.py View File

@@ -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)]

+ 2
- 4
test/functional/create_cache.py View File

@@ -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):

+ 1
- 2
test/functional/dbcrash.py View File

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


+ 1
- 3
test/functional/decodescript.py View File

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


+ 1
- 4
test/functional/disablewallet.py View File

@@ -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"]]

+ 1
- 4
test/functional/disconnect_ban.py View File

@@ -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")

+ 3
- 7
test/functional/example_test.py View File

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

+ 1
- 4
test/functional/forknotify.py View File

@@ -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")

+ 1
- 5
test/functional/fundrawtransaction.py View File

@@ -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()

+ 0
- 5
test/functional/getblocktemplate_longpoll.py View File

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

+ 0
- 6
test/functional/getchaintips.py View File

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

+ 1
- 3
test/functional/httpbasics.py View File

@@ -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()

+ 1
- 2
test/functional/import-rescan.py View File

@@ -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):

+ 1
- 2
test/functional/importmulti.py View File

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


+ 1
- 4
test/functional/importprunedfunds.py View File

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


+ 1
- 3
test/functional/invalidateblock.py View File

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


+ 2
- 2
test/functional/invalidblockrequest.py View File

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

+ 2
- 2
test/functional/invalidtxrequest.py View File

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

+ 1
- 2
test/functional/keypool-topup.py View File

@@ -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']]

+ 2
- 5
test/functional/keypool.py View File

@@ -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()

+ 1
- 4
test/functional/listsinceblock.py View File

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

+ 1
- 4
test/functional/listtransactions.py View File

@@ -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):

+ 1
- 2
test/functional/maxuploadtarget.py View File

@@ -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"]]

+ 1
- 3
test/functional/mempool_limit.py View File

@@ -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"]]

+ 1
- 3
test/functional/mempool_packages.py View File

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

+ 1
- 5
test/functional/mempool_persist.py View File

@@ -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):

+ 1
- 3
test/functional/mempool_reorg.py View File

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

+ 1
- 5
test/functional/mempool_resurrect_test.py View File

@@ -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):

+ 1
- 4
test/functional/mempool_spendcoinbase.py View File

@@ -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):

+ 1
- 4
test/functional/merkle_blocks.py View File

@@ -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"]]


+ 1
- 3
test/functional/mining.py View File

@@ -27,9 +27,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


+ 1
- 4
test/functional/multi_rpc.py View File

@@ -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):

+ 1
- 3
test/functional/multiwallet.py View File

@@ -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']]

+ 1
- 3
test/functional/net.py View File

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


+ 1
- 2
test/functional/nulldummy.py View File

@@ -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']]

+ 1
- 2
test/functional/p2p-acceptblock.py View File

@@ -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"]]

+ 1
- 2
test/functional/p2p-compactblocks.py View File

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

+ 1
- 4
test/functional/p2p-feefilter.py View File

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

+ 2
- 3
test/functional/p2p-fullblocktest.py View File

@@ -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")

+ 1
- 2
test/functional/p2p-leaktests.py View File

@@ -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)]]


+ 1
- 3
test/functional/p2p-mempool.py View File

@@ -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"]]

+ 2
- 5
test/functional/p2p-segwit.py View File

@@ -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"]]

+ 1
- 2
test/functional/p2p-timeouts.py View File

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


+ 1
- 2
test/functional/p2p-versionbits-warning.py View File

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


+ 1
- 2
test/functional/preciousblock.py View File

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


+ 1
- 3
test/functional/prioritise_transaction.py View File

@@ -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"]]

+ 0
- 6
test/functional/proxy_test.py View File

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

+ 1
- 3
test/functional/pruning.py View File

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


+ 1
- 3
test/functional/rawtransactions.py View File

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


+ 1
- 5
test/functional/receivedby.py View File

@@ -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):

+ 1
- 2
test/functional/reindex.py View File

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


+ 1
- 3
test/functional/replace-by-fee.py View File

@@ -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",

+ 2
- 4
test/functional/resendwallettransactions.py View File

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

+ 1
- 2
test/functional/rest.py View File

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


+ 1
- 4
test/functional/rpcbind_test.py View File

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


+ 1
- 8
test/functional/rpcnamedargs.py View File

@@ -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):

+ 1
- 3
test/functional/segwit.py View File

@@ -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"],

+ 1
- 2
test/functional/sendheaders.py View File

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


+ 1
- 3
test/functional/signmessages.py View File

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


+ 1
- 2
test/functional/signrawtransactions.py View File

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


+ 1
- 4
test/functional/smartfees.py View File

@@ -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):
"""

+ 50
- 39
test/functional/test_framework/test_framework.py View File

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


+ 0
- 6
test/functional/txn_clone.py View File

@@ -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")

+ 0
- 5
test/functional/txn_doublespend.py View File

@@ -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")

+ 1
- 3
test/functional/uptime.py View File

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


+ 1
- 3
test/functional/wallet-accounts.py View File

@@ -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 = [[]]

+ 1
- 4
test/functional/wallet-dump.py View File

@@ -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"]]


+ 1
- 3
test/functional/wallet-encryption.py View File

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


+ 1
- 4
test/functional/wallet-hd.py View File

@@ -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
- 11
test/functional/wallet.py View File

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

+ 1
- 4
test/functional/walletbackup.py View File

@@ -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"], []]


+ 1
- 3
test/functional/zapwallettxes.py View File

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


+ 1
- 3
test/functional/zmq_test.py View File

@@ -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…
Cancel
Save