Skip to content

Commit

Permalink
Merge bitcoin#21042: doc, test: Improve setup_clean_chain documentation
Browse files Browse the repository at this point in the history
590bda7 scripted-diff: Remove setup_clean_chain if default is not changed (Fabian Jahr)
98892f3 doc: Improve setup_clean_chain documentation (Fabian Jahr)

Pull request description:

  The first commit improves documentation on setup_clean_chain which is misunderstood quite frequently. Most importantly it fixes the TestShell docs which are simply incorrect.

  The second commit removes the instances of `setup_clean_clain` in functional tests where it is not changing the default.

  This used to be part of bitcoin#19168 which also sought to rename`setup_clean_chain`.

ACKs for top commit:
  jonatack:
    ACK 590bda7

Tree-SHA512: a7881186e65d31160b8f84107fb185973b37c6e50f190a85c6e2906a13a7472bb4efa9440bd37fe0a9ac5cd2d1e8559870a7e4380632d9a249eca8980b945f3e
  • Loading branch information
MarcoFalke authored and vijaydasmp committed Aug 9, 2023
1 parent 1e74a6a commit 95ceb8f
Show file tree
Hide file tree
Showing 17 changed files with 11 additions and 19 deletions.
11 changes: 7 additions & 4 deletions test/functional/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ 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 `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 (25x500=12500 DASH) in its wallet.
- Set the `self.setup_clean_chain` variable in `set_test_params()` to `True` to
initialize an empty blockchain and start from the Genesis block, rather than
load a premined blockchain from cache with the default value of `False`. The
cached data directories contain a 200-block pre-mined blockchain with the
spendable mining rewards being split between four nodes. Each node has 25
mature block subsidies (25x500=12500 DASH) in its wallet. Using them is much more
efficient than mining blocks in your test.
- When calling RPCs with lots of arguments, consider using named keyword
arguments instead of positional arguments to make the intent of the call
clear to readers.
Expand Down
3 changes: 3 additions & 0 deletions test/functional/example_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def set_test_params(self):
"""Override test parameters for your individual test.
This method must be overridden and num_nodes must be explicitly set."""
# By default every test loads a pre-mined chain of 200 blocks from cache.
# Set setup_clean_chain to True to skip this and start from the Genesis
# block.
self.setup_clean_chain = True
self.num_nodes = 3
# Use self.extra_args to change command-line arguments for the nodes
Expand Down
1 change: 0 additions & 1 deletion test/functional/feature_asmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def expected_messages(filename):

class AsmapTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = False
self.num_nodes = 1

def test_without_asmap_arg(self):
Expand Down
1 change: 0 additions & 1 deletion test/functional/feature_dbcrash.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
class ChainstateWriteCrashTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 4
self.setup_clean_chain = False
self.rpc_timeout = 480
self.supports_cli = False

Expand Down
1 change: 0 additions & 1 deletion test/functional/feature_includeconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

class IncludeConfTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = False
self.num_nodes = 1

def setup_chain(self):
Expand Down
1 change: 0 additions & 1 deletion test/functional/p2p_addr_relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def on_addr(self, message):

class AddrTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = False
self.num_nodes = 1

def run_test(self):
Expand Down
1 change: 0 additions & 1 deletion test/functional/p2p_blocksonly.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

class P2PBlocksOnly(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = False
self.num_nodes = 1
self.extra_args = [["-blocksonly"]]

Expand Down
1 change: 0 additions & 1 deletion test/functional/p2p_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def on_tx(self, message):

class FilterTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = False
self.num_nodes = 1
self.extra_args = [[
'-peerbloomfilters',
Expand Down
1 change: 0 additions & 1 deletion test/functional/p2p_getaddr_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def addr_received(self):

class AddrTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = False
self.num_nodes = 1

def run_test(self):
Expand Down
1 change: 0 additions & 1 deletion test/functional/p2p_invalid_locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
class InvalidLocatorTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
self.setup_clean_chain = False

def run_test(self):
node = self.nodes[0] # convenience reference to the node
Expand Down
1 change: 0 additions & 1 deletion test/functional/p2p_tx_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def on_getdata(self, message):

class TxDownloadTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = False
self.num_nodes = 2

def test_tx_requests(self):
Expand Down
1 change: 0 additions & 1 deletion test/functional/rpc_estimatefee.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

class EstimateFeeTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = False
self.num_nodes = 1

def run_test(self):
Expand Down
1 change: 0 additions & 1 deletion test/functional/rpc_psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
class PSBTTest(BitcoinTestFramework):

def set_test_params(self):
self.setup_clean_chain = False
self.num_nodes = 3
# TODO: remove -txindex. Currently required for getrawtransaction call.
self.extra_args = [
Expand Down
2 changes: 1 addition & 1 deletion test/functional/test-shell.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ can be called after the TestShell is shut down.
| `num_nodes` | `1` | Sets the number of initialized bitcoind processes. |
| `perf` | False | Profiles running nodes with `perf` for the duration of the test if set to `True`. |
| `rpc_timeout` | `60` | Sets the RPC server timeout for the underlying bitcoind processes. |
| `setup_clean_chain` | `False` | Initializes an empty blockchain by default. A 199-block-long chain is initialized if set to `True`. |
| `setup_clean_chain` | `False` | A 200-block-long chain is initialized from cache by default. Instead, `setup_clean_chain` initializes an empty blockchain if set to `True`. |
| `randomseed` | Random Integer | `TestShell.options.randomseed` is a member of `TestShell` which can be accessed during a test to seed a random generator. User can override default with a constant value for reproducible test runs. |
| `supports_cli` | `False` | Whether the bitcoin-cli utility is compiled and available for the test. |
| `tmpdir` | `"/var/folders/.../"` | Sets directory for test logs. Will be deleted upon a successful test run unless `nocleanup` is set to `True` |
Expand Down
1 change: 0 additions & 1 deletion test/functional/wallet_avoidreuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def assert_balances(node, mine, margin=0.001):
class AvoidReuseTest(BitcoinTestFramework):

def set_test_params(self):
self.setup_clean_chain = False
self.num_nodes = 2
# This test isn't testing txn relay/timing, so set whitelist on the
# peers for instant txn relay. This speeds up the test run time 2-3x.
Expand Down
1 change: 0 additions & 1 deletion test/functional/wallet_createwallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

class CreateWalletTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = False
self.num_nodes = 1

def skip_test_if_missing_module(self):
Expand Down
1 change: 0 additions & 1 deletion test/functional/wallet_watchonly.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

class CreateWalletWatchonlyTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = False
self.num_nodes = 1
self.supports_cli = True

Expand Down

0 comments on commit 95ceb8f

Please sign in to comment.