Skip to content

Commit 5448a14

Browse files
committed
[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.
1 parent 6cf094a commit 5448a14

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+145
-322
lines changed

test/functional/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ don't have test cases for.
2424
- Use a module-level docstring to describe what the test is testing, and how it
2525
is testing it.
2626
- When subclassing the BitcoinTestFramwork, place overrides for the
27-
`__init__()`, and `setup_xxxx()` methods at the top of the subclass, then
28-
locally-defined helper methods, then the `run_test()` method.
27+
`set_test_params()`, `add_options()` and `setup_xxxx()` methods at the top of
28+
the subclass, then locally-defined helper methods, then the `run_test()` method.
2929

3030
#### General test-writing advice
3131

@@ -36,7 +36,7 @@ don't have test cases for.
3636
- Avoid stop-starting the nodes multiple times during the test if possible. A
3737
stop-start takes several seconds, so doing it several times blows up the
3838
runtime of the test.
39-
- Set the `self.setup_clean_chain` variable in `__init__()` to control whether
39+
- Set the `self.setup_clean_chain` variable in `set_test_params()` to control whether
4040
or not to use the cached data directories. The cached data directories
4141
contain a 200-block pre-mined blockchain and wallets for four nodes. Each node
4242
has 25 mature blocks (25x50=1250 BTC) in its wallet.

test/functional/abandonconflict.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
from test_framework.util import *
1515

1616
class AbandonConflictTest(BitcoinTestFramework):
17-
def __init__(self):
18-
super().__init__()
17+
def set_test_params(self):
1918
self.num_nodes = 2
20-
self.setup_clean_chain = False
2119
self.extra_args = [["-minrelaytxfee=0.00001"], []]
2220

2321
def run_test(self):

test/functional/assumevalid.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ def send_header_for_blocks(self, new_blocks):
5454
self.send_message(headers_message)
5555

5656
class AssumeValidTest(BitcoinTestFramework):
57-
def __init__(self):
58-
super().__init__()
57+
def set_test_params(self):
5958
self.setup_clean_chain = True
6059
self.num_nodes = 3
6160

test/functional/bip65-cltv-p2p.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ def create_transaction(node, coinbase, to_address, amount):
6060
return tx
6161

6262
class BIP65Test(BitcoinTestFramework):
63-
64-
def __init__(self):
65-
super().__init__()
63+
def set_test_params(self):
6664
self.num_nodes = 1
6765
self.extra_args = [['-promiscuousmempoolflags=1', '-whitelist=127.0.0.1']]
6866
self.setup_clean_chain = True

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ def all_rlt_txs(txarray):
9292
return txs
9393

9494
class BIP68_112_113Test(ComparisonTestFramework):
95-
def __init__(self):
96-
super().__init__()
95+
def set_test_params(self):
9796
self.num_nodes = 1
97+
self.setup_clean_chain = True
9898
self.extra_args = [['-whitelist=127.0.0.1', '-blockversion=4']]
9999

100100
def run_test(self):

test/functional/bip68-sequence.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
NOT_FINAL_ERROR = "64: non-BIP68-final"
1818

1919
class BIP68Test(BitcoinTestFramework):
20-
def __init__(self):
21-
super().__init__()
20+
def set_test_params(self):
2221
self.num_nodes = 2
23-
self.setup_clean_chain = False
2422
self.extra_args = [[], ["-acceptnonstdtxn=0"]]
2523

2624
def run_test(self):

test/functional/bip9-softforks.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@
2828
from test_framework.script import CScript, OP_1NEGATE, OP_CHECKSEQUENCEVERIFY, OP_DROP
2929

3030
class BIP9SoftForksTest(ComparisonTestFramework):
31-
32-
def __init__(self):
33-
super().__init__()
31+
def set_test_params(self):
3432
self.num_nodes = 1
3533
self.extra_args = [['-whitelist=127.0.0.1']]
34+
self.setup_clean_chain = True
3635

3736
def run_test(self):
3837
self.test = TestManager(self, self.options.tmpdir)

test/functional/bipdersig-p2p.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ def create_transaction(node, coinbase, to_address, amount):
4848
return tx
4949

5050
class BIP66Test(BitcoinTestFramework):
51-
52-
def __init__(self):
53-
super().__init__()
51+
def set_test_params(self):
5452
self.num_nodes = 1
5553
self.extra_args = [['-promiscuousmempoolflags=1', '-whitelist=127.0.0.1']]
5654
self.setup_clean_chain = True

test/functional/blockchain.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,8 @@
3030
assert_is_hash_string,
3131
)
3232

33-
3433
class BlockchainTest(BitcoinTestFramework):
35-
36-
def __init__(self):
37-
super().__init__()
38-
self.setup_clean_chain = False
34+
def set_test_params(self):
3935
self.num_nodes = 1
4036
self.extra_args = [['-stopatheight=207']]
4137

test/functional/bumpfee.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030

3131

3232
class BumpFeeTest(BitcoinTestFramework):
33-
def __init__(self):
34-
super().__init__()
33+
def set_test_params(self):
3534
self.num_nodes = 2
3635
self.setup_clean_chain = True
3736
self.extra_args = [["-prematurewitness", "-walletprematurewitness", "-walletrbf={}".format(i)]

0 commit comments

Comments
 (0)