Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions test/functional/example_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class ExampleTest(BitcoinTestFramework):
# Override the set_test_params(), skip_test_if_missing_module(), add_options(), setup_chain(), setup_network()
# and setup_nodes() methods to customize the test setup as required.

def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
"""Override test parameters for your individual test.

Expand Down
3 changes: 3 additions & 0 deletions test/functional/feature_backwards_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@


class BackwardsCompatibilityTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 8
Expand Down
3 changes: 3 additions & 0 deletions test/functional/feature_bip68_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
NOT_FINAL_ERROR = "non-BIP68-final"

class BIP68Test(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.num_nodes = 2
self.extra_args = [
Expand Down
3 changes: 3 additions & 0 deletions test/functional/feature_config_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@


class ConfArgsTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 1
Expand Down
3 changes: 3 additions & 0 deletions test/functional/feature_filelock.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from test_framework.test_node import ErrorMatch

class FilelockTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 2
Expand Down
3 changes: 3 additions & 0 deletions test/functional/feature_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class InitStressTest(BitcoinTestFramework):
subsequent starts.
"""

def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.setup_clean_chain = False
self.num_nodes = 1
Expand Down
2 changes: 2 additions & 0 deletions test/functional/feature_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def notify_outputname(walletname, txid):


class NotificationsTest(DashTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)
def set_test_params(self):
self.set_dash_test_params(6, 4)

Expand Down
3 changes: 3 additions & 0 deletions test/functional/feature_pruning.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ def calc_usage(blockdir):
return sum(os.path.getsize(blockdir + f) for f in os.listdir(blockdir) if os.path.isfile(os.path.join(blockdir, f))) / (1024. * 1024.)

class PruneTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 6
Expand Down
6 changes: 4 additions & 2 deletions test/functional/interface_bitcoin_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ def cli_get_info_string_to_dict(cli_get_info_string):


class TestBitcoinCli(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 1
if self.is_specified_wallet_compiled():
self.requires_wallet = True

def skip_test_if_missing_module(self):
self.skip_if_no_cli()
Expand Down Expand Up @@ -123,6 +124,7 @@ def run_test(self):

self.log.info("Test -getinfo returns expected network and blockchain info")
if self.is_specified_wallet_compiled():
self.import_deterministic_coinbase_privkeys()
self.nodes[0].encryptwallet(password)
cli_get_info_string = self.nodes[0].cli('-getinfo').send_cli()
cli_get_info = cli_get_info_string_to_dict(cli_get_info_string)
Expand Down
3 changes: 3 additions & 0 deletions test/functional/interface_usdt_coinselection.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@


class CoinSelectionTracepointTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.num_nodes = 1
self.setup_clean_chain = True
Expand Down
3 changes: 3 additions & 0 deletions test/functional/mempool_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@


class MempoolCompatibilityTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.num_nodes = 2

Expand Down
3 changes: 3 additions & 0 deletions test/functional/mempool_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@


class MempoolPackagesTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.num_nodes = 2
self.extra_args = [
Expand Down
3 changes: 3 additions & 0 deletions test/functional/mempool_persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@


class MempoolPersistTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser, legacy=False)

def set_test_params(self):
self.num_nodes = 3
self.extra_args = [[], ["-persistmempool=0"], []]
Expand Down
6 changes: 4 additions & 2 deletions test/functional/mempool_unbroadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
MAX_INITIAL_BROADCAST_DELAY = 15 * 60 # 15 minutes in seconds

class MempoolUnbroadcastTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.num_nodes = 2
if self.is_wallet_compiled():
self.requires_wallet = True

def run_test(self):
self.wallet = MiniWallet(self.nodes[0])
Expand All @@ -35,6 +36,7 @@ def test_broadcast(self):
self.log.info("Generate transactions that only node 0 knows about")

if self.is_wallet_compiled():
self.import_deterministic_coinbase_privkeys()
# generate a wallet txn
addr = node.getnewaddress()
wallet_tx_hsh = node.sendtoaddress(addr, 0.0001)
Expand Down
6 changes: 4 additions & 2 deletions test/functional/rpc_createmultisig.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
)

class RpcCreateMultiSigTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 3
self.supports_cli = False
if self.is_bdb_compiled():
self.requires_wallet = True

def get_keys(self):
self.pub = []
Expand All @@ -49,6 +50,7 @@ def run_test(self):
self.wallet = MiniWallet(test_node=node0)

if self.is_bdb_compiled():
self.import_deterministic_coinbase_privkeys()
self.check_addmultisigaddress_errors()

self.log.info('Generating blocks ...')
Expand Down
3 changes: 3 additions & 0 deletions test/functional/rpc_fundrawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def get_unspent(listunspent, amount):
raise AssertionError('Could not find unspent with amount={}'.format(amount))

class RawTransactionsTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.num_nodes = 4
self.setup_clean_chain = True
Expand Down
3 changes: 3 additions & 0 deletions test/functional/rpc_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def process_mapping(fname):


class HelpRpcTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.num_nodes = 1
self.supports_cli = False
Expand Down
3 changes: 3 additions & 0 deletions test/functional/rpc_invalid_address_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
INVALID_ADDRESS = 'asfah14i8fajz0123f'

class InvalidAddressErrorMessageTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 1
Expand Down
4 changes: 3 additions & 1 deletion test/functional/rpc_psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
import json
import os

# Create one-input, one-output, no-fee transaction:

class PSBTTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.num_nodes = 3
Expand Down
8 changes: 5 additions & 3 deletions test/functional/rpc_rawtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def items(self):


class RawTransactionsTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser, descriptors=False)

def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 3
Expand All @@ -64,8 +67,6 @@ def set_test_params(self):
# whitelist all peers to speed up tx relay / mempool sync
for args in self.extra_args:
args.append("-whitelist=noban@127.0.0.1")
self.requires_wallet = self.is_specified_wallet_compiled()

self.supports_cli = False

def setup_network(self):
Expand All @@ -83,7 +84,8 @@ def run_test(self):
self.sendrawtransaction_tests()
self.sendrawtransaction_testmempoolaccept_tests()
self.transaction_version_number_tests()
if self.requires_wallet and not self.options.descriptors:
if self.is_specified_wallet_compiled() and not self.options.descriptors:
self.import_deterministic_coinbase_privkeys()
self.raw_multisig_transaction_legacy_tests()

def getrawtransaction_tests(self):
Expand Down
34 changes: 24 additions & 10 deletions test/functional/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def __init__(self):
self.wallet_names = None
# By default the wallet is not required. Set to true by skip_if_no_wallet().
# When False, we ignore wallet_names regardless of what it is.
self.requires_wallet = False
self._requires_wallet = False
# Disable ThreadOpenConnections by default, so that adding entries to
# addrman will not result in automatic connections to them.
self.disable_autoconnect = True
Expand Down Expand Up @@ -230,12 +230,6 @@ def parse_args(self):
parser.add_argument("--v1transport", dest="v1transport", default=False, action="store_true",
help="Explicitly use v1 transport (can be used to overwrite global --v2transport option)")

group = parser.add_mutually_exclusive_group()
group.add_argument("--descriptors", action='store_const', const=True,
help="Run test using a descriptor wallet", dest='descriptors')
group.add_argument("--legacy-wallet", action='store_const', const=False,
help="Run test using legacy wallets", dest='descriptors')

self.add_options(parser)
self.options = parser.parse_args()
if self.options.timeout_factor == 0:
Expand All @@ -254,7 +248,13 @@ def parse_args(self):
# source: https://stackoverflow.com/questions/48796169/how-to-fix-ipykernel-launcher-py-error-unrecognized-arguments-in-jupyter/56349168#56349168
parser.add_argument("-f", "--fff", help="a dummy argument to fool ipython", default="1")

if self.options.descriptors is None:
if "descriptors" not in self.options:
# Wallet is not required by the test at all and the value of self.options.descriptors won't matter.
# It still needs to exist and be None in order for tests to work however.
# So set it to None to force -disablewallet, because the wallet is not needed.
self.options.descriptors = None
elif self.options.descriptors is None:
# Some wallet is either required or optionally used by the test.
# Prefer BDB unless it isn't available
if self.is_bdb_compiled():
self.options.descriptors = False
Expand All @@ -263,6 +263,7 @@ def parse_args(self):
else:
# If neither are compiled, tests requiring a wallet will be skipped and the value of self.options.descriptors won't matter
# It still needs to exist and be None in order for tests to work however.
# So set it to None, which will also set -disablewallet.
self.options.descriptors = None

PortSeed.n = self.options.port_seed
Expand Down Expand Up @@ -461,7 +462,7 @@ def setup_nodes(self):
""" NOTE! If this method is updated - backport changes to DashTestFramework.setup_nodes"""
self.add_nodes(self.num_nodes, self.extra_args)
self.start_nodes()
if self.requires_wallet:
if self._requires_wallet:
self.import_deterministic_coinbase_privkeys()
if not self.setup_clean_chain:
for n in self.nodes:
Expand Down Expand Up @@ -497,6 +498,19 @@ def run_test(self):

# Public helper methods. These can be accessed by the subclass test scripts.

def add_wallet_options(self, parser, *, descriptors=True, legacy=True):
group = parser.add_mutually_exclusive_group()
kwargs = {}
if descriptors + legacy == 1:
# If only one type can be chosen, set it as default
kwargs["default"] = descriptors
if descriptors:
group.add_argument("--descriptors", action='store_const', const=True, **kwargs,
help="Run test using a descriptor wallet", dest='descriptors')
if legacy:
group.add_argument("--legacy-wallet", action='store_const', const=False, **kwargs,
help="Run test using legacy wallets", dest='descriptors')

def add_nodes(self, num_nodes: int, extra_args=None, *, rpchost=None, binary=None, binary_cli=None, versions=None):
"""Instantiate TestNode objects.

Expand Down Expand Up @@ -1048,7 +1062,7 @@ def skip_if_no_bitcoind_zmq(self):

def skip_if_no_wallet(self):
"""Skip the running test if wallet has not been compiled."""
self.requires_wallet = True
self._requires_wallet = True
if not self.is_wallet_compiled():
raise SkipTest("wallet has not been compiled.")
if self.options.descriptors:
Expand Down
3 changes: 3 additions & 0 deletions test/functional/test_framework/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ def __init__(self, i, datadir, extra_args_from_options, *, chain, rpchost, timew
if self.mocktime != 0:
self.args.append(f"-mocktime={mocktime}")

if self.descriptors is None:
self.args.append("-disablewallet")

# Use valgrind, expect for previous release binaries
if use_valgrind and version is None:
default_suppressions_file = os.path.join(
Expand Down
3 changes: 3 additions & 0 deletions test/functional/tool_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
BUFFER_SIZE = 16 * 1024

class ToolWalletTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.num_nodes = 1
self.setup_clean_chain = True
Expand Down
3 changes: 3 additions & 0 deletions test/functional/wallet_abandonconflict.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@


class AbandonConflictTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.num_nodes = 2
self.extra_args = [["-minrelaytxfee=0.00001"], []]
Expand Down
2 changes: 2 additions & 0 deletions test/functional/wallet_avoidreuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ def assert_balances(node, mine, margin=0.001):
assert_approx(got[k], v, margin)

class AvoidReuseTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.num_nodes = 2
Expand Down
3 changes: 3 additions & 0 deletions test/functional/wallet_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
from test_framework.util import assert_equal, assert_raises_rpc_error

class WalletBackupTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)

def set_test_params(self):
self.num_nodes = 4
self.setup_clean_chain = True
Expand Down
Loading
Loading