Skip to content

Commit 171cd05

Browse files
author
MarcoFalke
committed
Merge #20034: test: Get rid of default wallet hacks
c1585bc test: Get rid of default wallet hacks (Russell Yanofsky) ed3acda test, refactor: add default_wallet_name and wallet_data_filename variables (Russell Yanofsky) Pull request description: Changes: - Get rid of setup_nodes (`-wallet`, `-nowallet`, `-disablewallet`) argument rewriting - Get rid of hardcoded wallet `""` names and `-wallet=""` args Motivation: - Simplify test framework behavior so it's easier to write new tests without having arguments mangled by the framework - Make tests more readable, replacing unexplained `""` string literals with `default_wallet_name` references - Make it trivial to update default wallet name and wallet data filename for sqlite #19077 testing - Stop relying on `-wallet` arguments to create wallets, so it is easy to change `-wallet` option in the future to only load existing wallets not create new ones (to avoid accidental wallet creation, and encourage use of wallet encryption and descriptor features) ACKs for top commit: MarcoFalke: ACK c1585bc, only effective change is adding documentation 🎵 Tree-SHA512: f62dec7cbdacb5f330aa0e1eec89ab4d065540d91495bbedcb375eda1c080b45ce9edb310ce253c44c4839f1b4cc2c7df9816c58402d5d43f94a437e301ea8bc
2 parents d993522 + c1585bc commit 171cd05

27 files changed

+94
-92
lines changed

test/functional/feature_backwards_compatibility.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ def set_test_params(self):
3636
self.num_nodes = 6
3737
# Add new version after each release:
3838
self.extra_args = [
39-
["-addresstype=bech32", "-wallet="], # Pre-release: use to mine blocks
39+
["-addresstype=bech32"], # Pre-release: use to mine blocks
4040
["-nowallet", "-walletrbf=1", "-addresstype=bech32"], # Pre-release: use to receive coins, swap wallets, etc
4141
["-nowallet", "-walletrbf=1", "-addresstype=bech32"], # v0.19.1
4242
["-nowallet", "-walletrbf=1", "-addresstype=bech32"], # v0.18.1
4343
["-nowallet", "-walletrbf=1", "-addresstype=bech32"], # v0.17.2
4444
["-nowallet", "-walletrbf=1", "-addresstype=bech32", "-wallet=wallet.dat"], # v0.16.3
4545
]
46+
self.wallet_names = [self.default_wallet_name]
4647

4748
def skip_test_if_missing_module(self):
4849
self.skip_if_no_wallet()
@@ -59,6 +60,7 @@ def setup_nodes(self):
5960
])
6061

6162
self.start_nodes()
63+
self.import_deterministic_coinbase_privkeys()
6264

6365
def run_test(self):
6466
self.nodes[0].generatetoaddress(101, self.nodes[0].getnewaddress())

test/functional/feature_config_args.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def set_test_params(self):
1414
self.setup_clean_chain = True
1515
self.num_nodes = 1
1616
self.supports_cli = False
17+
self.wallet_names = []
1718

1819
def test_config_file_parser(self):
1920
# Assume node is stopped

test/functional/feature_dbcrash.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def set_test_params(self):
5656
# Set -maxmempool=0 to turn off mempool memory sharing with dbcache
5757
# Set -rpcservertimeout=900 to reduce socket disconnects in this
5858
# long-running test
59-
self.base_args = ["-limitdescendantsize=0", "-maxmempool=0", "-rpcservertimeout=900", "-dbbatchsize=200000", "-wallet="]
59+
self.base_args = ["-limitdescendantsize=0", "-maxmempool=0", "-rpcservertimeout=900", "-dbbatchsize=200000"]
6060

6161
# Set different crash ratios and cache sizes. Note that not all of
6262
# -dbcache goes to the in-memory coins cache.
@@ -66,7 +66,7 @@ def set_test_params(self):
6666

6767
# Node3 is a normal node with default args, except will mine full blocks
6868
# and non-standard txs (e.g. txs with "dust" outputs)
69-
self.node3_args = ["-blockmaxweight=4000000", "-acceptnonstdtxn", "-wallet="]
69+
self.node3_args = ["-blockmaxweight=4000000", "-acceptnonstdtxn"]
7070
self.extra_args = [self.node0_args, self.node1_args, self.node2_args, self.node3_args]
7171

7272
def skip_test_if_missing_module(self):

test/functional/feature_fee_estimation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,9 @@ def set_test_params(self):
145145
# mine non-standard txs (e.g. txs with "dust" outputs)
146146
# Force fSendTrickle to true (via whitelist.noban)
147147
self.extra_args = [
148-
["-acceptnonstdtxn", "[email protected]", "-wallet="],
149-
["-acceptnonstdtxn", "[email protected]", "-blockmaxweight=68000", "-wallet="],
150-
["-acceptnonstdtxn", "[email protected]", "-blockmaxweight=32000", "-wallet="],
148+
["-acceptnonstdtxn", "[email protected]"],
149+
["-acceptnonstdtxn", "[email protected]", "-blockmaxweight=68000"],
150+
["-acceptnonstdtxn", "[email protected]", "-blockmaxweight=32000"],
151151
]
152152

153153
def skip_test_if_missing_module(self):

test/functional/feature_filelock.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def set_test_params(self):
1515

1616
def setup_network(self):
1717
self.add_nodes(self.num_nodes, extra_args=None)
18-
self.nodes[0].start(['-wallet='])
18+
self.nodes[0].start()
1919
self.nodes[0].wait_for_rpc_connection()
2020

2121
def run_test(self):
@@ -27,10 +27,11 @@ def run_test(self):
2727
self.nodes[1].assert_start_raises_init_error(extra_args=['-datadir={}'.format(self.nodes[0].datadir), '-noserver'], expected_msg=expected_msg)
2828

2929
if self.is_wallet_compiled():
30+
self.nodes[0].createwallet(self.default_wallet_name)
3031
wallet_dir = os.path.join(datadir, 'wallets')
3132
self.log.info("Check that we can't start a second bitcoind instance using the same wallet")
3233
expected_msg = "Error: Error initializing wallet database environment"
33-
self.nodes[1].assert_start_raises_init_error(extra_args=['-walletdir={}'.format(wallet_dir), '-wallet=', '-noserver'], expected_msg=expected_msg, match=ErrorMatch.PARTIAL_REGEX)
34+
self.nodes[1].assert_start_raises_init_error(extra_args=['-walletdir={}'.format(wallet_dir), '-wallet=' + self.default_wallet_name, '-noserver'], expected_msg=expected_msg, match=ErrorMatch.PARTIAL_REGEX)
3435

3536
if __name__ == '__main__':
3637
FilelockTest().main()

test/functional/feature_notifications.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ def setup_network(self):
4545
"-blocknotify=echo > {}".format(os.path.join(self.blocknotify_dir, '%s'))],
4646
["-blockversion=211",
4747
"-rescan",
48-
"-wallet={}".format(self.wallet),
4948
"-walletnotify=echo > {}".format(os.path.join(self.walletnotify_dir, notify_outputname('%w', '%s')))]]
49+
self.wallet_names = [self.default_wallet_name, self.wallet]
5050
super().setup_network()
5151

5252
def run_test(self):

test/functional/feature_pruning.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ def set_test_params(self):
8181

8282
# Create nodes 0 and 1 to mine.
8383
# Create node 2 to test pruning.
84-
self.full_node_default_args = ["-maxreceivebuffer=20000", "-checkblocks=5", "-wallet="]
84+
self.full_node_default_args = ["-maxreceivebuffer=20000", "-checkblocks=5"]
8585
# Create nodes 3 and 4 to test manual pruning (they will be re-started with manual pruning later)
8686
# Create nodes 5 to test wallet in prune mode, but do not connect
8787
self.extra_args = [
8888
self.full_node_default_args,
8989
self.full_node_default_args,
90-
["-wallet=", "-maxreceivebuffer=20000", "-prune=550"],
91-
["-wallet=", "-maxreceivebuffer=20000"],
92-
["-wallet=", "-maxreceivebuffer=20000"],
93-
["-wallet=", "-prune=550"],
90+
["-maxreceivebuffer=20000", "-prune=550"],
91+
["-maxreceivebuffer=20000"],
92+
["-maxreceivebuffer=20000"],
93+
["-prune=550"],
9494
]
9595
self.rpc_timeout = 120
9696

@@ -112,8 +112,7 @@ def setup_network(self):
112112
def setup_nodes(self):
113113
self.add_nodes(self.num_nodes, self.extra_args)
114114
self.start_nodes()
115-
for n in self.nodes:
116-
n.importprivkey(privkey=n.get_deterministic_priv_key().key, label='coinbase', rescan=False)
115+
self.import_deterministic_coinbase_privkeys()
117116

118117
def create_big_chain(self):
119118
# Start by creating some coinbases we can spend later

test/functional/feature_settings.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class SettingsTest(BitcoinTestFramework):
1717
def set_test_params(self):
1818
self.setup_clean_chain = True
1919
self.num_nodes = 1
20+
self.wallet_names = []
2021

2122
def run_test(self):
2223
node, = self.nodes

test/functional/interface_bitcoin_cli.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def run_test(self):
9595
assert_equal(self.nodes[0].cli.getwalletinfo(), wallet_info)
9696

9797
# Setup to test -getinfo, -generate, and -rpcwallet= with multiple wallets.
98-
wallets = ['', 'Encrypted', 'secret']
98+
wallets = [self.default_wallet_name, 'Encrypted', 'secret']
9999
amounts = [BALANCE + Decimal('9.999928'), Decimal(9), Decimal(31)]
100100
self.nodes[0].createwallet(wallet_name=wallets[1])
101101
self.nodes[0].createwallet(wallet_name=wallets[2])

test/functional/mempool_compatibility.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
class MempoolCompatibilityTest(BitcoinTestFramework):
2222
def set_test_params(self):
2323
self.num_nodes = 2
24+
self.wallet_names = [None, self.default_wallet_name]
2425

2526
def skip_test_if_missing_module(self):
2627
self.skip_if_no_wallet()
@@ -31,7 +32,7 @@ def setup_network(self):
3132
150200, # oldest version supported by the test framework
3233
None,
3334
])
34-
self.start_nodes([[], ["-wallet="]])
35+
self.start_nodes()
3536
self.import_deterministic_coinbase_privkeys()
3637

3738
def run_test(self):

test/functional/rpc_deprecated.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def run_test(self):
2929
self.nodes[0].generate(101)
3030
self.nodes[0].createwallet(wallet_name='nopriv', disable_private_keys=True)
3131
noprivs0 = self.nodes[0].get_wallet_rpc('nopriv')
32-
w0 = self.nodes[0].get_wallet_rpc('')
32+
w0 = self.nodes[0].get_wallet_rpc(self.default_wallet_name)
3333
self.nodes[1].createwallet(wallet_name='nopriv', disable_private_keys=True)
3434
noprivs1 = self.nodes[1].get_wallet_rpc('nopriv')
3535

test/functional/rpc_getdescriptorinfo.py

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class DescriptorTest(BitcoinTestFramework):
1717
def set_test_params(self):
1818
self.num_nodes = 1
1919
self.extra_args = [["-disablewallet"]]
20+
self.wallet_names = []
2021

2122
def test_desc(self, desc, isrange, issolvable, hasprivatekeys):
2223
info = self.nodes[0].getdescriptorinfo(desc)

test/functional/test_framework/test_framework.py

+16-21
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,16 @@ def __init__(self):
102102
self.rpc_timeout = 60 # Wait for up to 60 seconds for the RPC server to respond
103103
self.supports_cli = True
104104
self.bind_to_localhost_only = True
105-
self.set_test_params()
106105
self.parse_args()
106+
self.default_wallet_name = ""
107+
self.wallet_data_filename = "wallet.dat"
108+
# Optional list of wallet names that can be set in set_test_params to
109+
# create and import keys to. If unset, default is len(nodes) *
110+
# [default_wallet_name]. If wallet names are None, wallet creation is
111+
# skipped. If list is truncated, wallet creation is skipped and keys
112+
# are not imported.
113+
self.wallet_names = None
114+
self.set_test_params()
107115
if self.options.timeout_factor == 0 :
108116
self.options.timeout_factor = 99999
109117
self.rpc_timeout = int(self.rpc_timeout * self.options.timeout_factor) # optionally, increase timeout by a factor
@@ -362,23 +370,12 @@ def setup_network(self):
362370
def setup_nodes(self):
363371
"""Override this method to customize test node setup"""
364372
extra_args = [[]] * self.num_nodes
365-
wallets = [[]] * self.num_nodes
366373
if hasattr(self, "extra_args"):
367374
extra_args = self.extra_args
368-
wallets = [[x for x in eargs if x.startswith('-wallet=')] for eargs in extra_args]
369-
extra_args = [x + ['-nowallet'] for x in extra_args]
370375
self.add_nodes(self.num_nodes, extra_args)
371376
self.start_nodes()
372-
for i, n in enumerate(self.nodes):
373-
n.extra_args.pop()
374-
if '-wallet=0' in n.extra_args or '-nowallet' in n.extra_args or '-disablewallet' in n.extra_args or not self.is_wallet_compiled():
375-
continue
376-
if '-wallet=' not in wallets[i] and not any([x.startswith('-wallet=') for x in wallets[i]]):
377-
wallets[i].append('-wallet=')
378-
for w in wallets[i]:
379-
wallet_name = w.split('=', 1)[1]
380-
n.createwallet(wallet_name=wallet_name, descriptors=self.options.descriptors)
381-
self.import_deterministic_coinbase_privkeys()
377+
if self.is_wallet_compiled():
378+
self.import_deterministic_coinbase_privkeys()
382379
if not self.setup_clean_chain:
383380
for n in self.nodes:
384381
assert_equal(n.getblockchaininfo()["blocks"], 199)
@@ -394,13 +391,11 @@ def setup_nodes(self):
394391
assert_equal(chain_info["initialblockdownload"], False)
395392

396393
def import_deterministic_coinbase_privkeys(self):
397-
for n in self.nodes:
398-
try:
399-
n.getwalletinfo()
400-
except JSONRPCException as e:
401-
assert str(e).startswith('Method not found')
402-
continue
403-
394+
wallet_names = [self.default_wallet_name] * len(self.nodes) if self.wallet_names is None else self.wallet_names
395+
assert len(wallet_names) <= len(self.nodes)
396+
for wallet_name, n in zip(wallet_names, self.nodes):
397+
if wallet_name is not None:
398+
n.createwallet(wallet_name=wallet_name, descriptors=self.options.descriptors, load_on_startup=True)
404399
n.importprivkey(privkey=n.get_deterministic_priv_key().key, label='coinbase')
405400

406401
def run_test(self):

test/functional/tool_wallet.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def test_invalid_tool_commands_and_args(self):
7373
locked_dir = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets")
7474
self.assert_raises_tool_error(
7575
'Error initializing wallet database environment "{}"!'.format(locked_dir),
76-
'-wallet=wallet.dat',
76+
'-wallet=' + self.default_wallet_name,
7777
'info',
7878
)
7979
path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "nonexistent.dat")
@@ -104,7 +104,7 @@ def test_tool_wallet_info(self):
104104
Transactions: 0
105105
Address Book: 3
106106
''')
107-
self.assert_tool_output(out, '-wallet=wallet.dat', 'info')
107+
self.assert_tool_output(out, '-wallet=' + self.default_wallet_name, 'info')
108108
timestamp_after = self.wallet_timestamp()
109109
self.log.debug('Wallet file timestamp after calling info: {}'.format(timestamp_after))
110110
self.log_wallet_timestamp_comparison(timestamp_before, timestamp_after)
@@ -143,7 +143,7 @@ def test_tool_wallet_info_after_transaction(self):
143143
Transactions: 1
144144
Address Book: 3
145145
''')
146-
self.assert_tool_output(out, '-wallet=wallet.dat', 'info')
146+
self.assert_tool_output(out, '-wallet=' + self.default_wallet_name, 'info')
147147
shasum_after = self.wallet_shasum()
148148
timestamp_after = self.wallet_timestamp()
149149
self.log.debug('Wallet file timestamp after calling info: {}'.format(timestamp_after))
@@ -181,7 +181,7 @@ def test_tool_wallet_create_on_existing_wallet(self):
181181

182182
def test_getwalletinfo_on_different_wallet(self):
183183
self.log.info('Starting node with arg -wallet=foo')
184-
self.start_node(0, ['-wallet=foo'])
184+
self.start_node(0, ['-nowallet', '-wallet=foo'])
185185

186186
self.log.info('Calling getwalletinfo on a different wallet ("foo"), testing output')
187187
shasum_before = self.wallet_shasum()
@@ -213,7 +213,7 @@ def test_salvage(self):
213213
self.assert_tool_output('', '-wallet=salvage', 'salvage')
214214

215215
def run_test(self):
216-
self.wallet_path = os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat')
216+
self.wallet_path = os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename)
217217
self.test_invalid_tool_commands_and_args()
218218
# Warning: The following tests are order-dependent.
219219
self.test_tool_wallet_info()

test/functional/wallet_backup.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ def set_test_params(self):
5050
# nodes 1, 2,3 are spenders, let's give them a keypool=100
5151
# whitelist all peers to speed up tx relay / mempool sync
5252
self.extra_args = [
53-
["[email protected]", "-keypool=100", "-wallet="],
54-
["[email protected]", "-keypool=100", "-wallet="],
55-
["[email protected]", "-keypool=100", "-wallet="],
56-
["[email protected]", "-wallet="],
53+
["[email protected]", "-keypool=100"],
54+
["[email protected]", "-keypool=100"],
55+
["[email protected]", "-keypool=100"],
56+
5757
]
5858
self.rpc_timeout = 120
5959

@@ -107,9 +107,9 @@ def stop_three(self):
107107
self.stop_node(2)
108108

109109
def erase_three(self):
110-
os.remove(os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat'))
111-
os.remove(os.path.join(self.nodes[1].datadir, self.chain, 'wallets', 'wallet.dat'))
112-
os.remove(os.path.join(self.nodes[2].datadir, self.chain, 'wallets', 'wallet.dat'))
110+
os.remove(os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
111+
os.remove(os.path.join(self.nodes[1].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
112+
os.remove(os.path.join(self.nodes[2].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
113113

114114
def run_test(self):
115115
self.log.info("Generating initial blockchain")
@@ -171,9 +171,9 @@ def run_test(self):
171171
shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'chainstate'))
172172

173173
# Restore wallets from backup
174-
shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat'))
175-
shutil.copyfile(os.path.join(self.nodes[1].datadir, 'wallet.bak'), os.path.join(self.nodes[1].datadir, self.chain, 'wallets', 'wallet.dat'))
176-
shutil.copyfile(os.path.join(self.nodes[2].datadir, 'wallet.bak'), os.path.join(self.nodes[2].datadir, self.chain, 'wallets', 'wallet.dat'))
174+
shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
175+
shutil.copyfile(os.path.join(self.nodes[1].datadir, 'wallet.bak'), os.path.join(self.nodes[1].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
176+
shutil.copyfile(os.path.join(self.nodes[2].datadir, 'wallet.bak'), os.path.join(self.nodes[2].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
177177

178178
self.log.info("Re-starting nodes")
179179
self.start_three()
@@ -209,9 +209,9 @@ def run_test(self):
209209

210210
# Backup to source wallet file must fail
211211
sourcePaths = [
212-
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat'),
213-
os.path.join(self.nodes[0].datadir, self.chain, '.', 'wallets', 'wallet.dat'),
214-
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', ''),
212+
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename),
213+
os.path.join(self.nodes[0].datadir, self.chain, '.', 'wallets', self.default_wallet_name, self.wallet_data_filename),
214+
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name),
215215
os.path.join(self.nodes[0].datadir, self.chain, 'wallets')]
216216

217217
for sourcePath in sourcePaths:

test/functional/wallet_balance.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,10 @@ def test_balances(*, fee_node_1=0):
215215
# dynamically loading the wallet.
216216
before = self.nodes[1].getbalances()['mine']['untrusted_pending']
217217
dst = self.nodes[1].getnewaddress()
218-
self.nodes[1].unloadwallet('')
218+
self.nodes[1].unloadwallet(self.default_wallet_name)
219219
self.nodes[0].sendtoaddress(dst, 0.1)
220220
self.sync_all()
221-
self.nodes[1].loadwallet('')
221+
self.nodes[1].loadwallet(self.default_wallet_name)
222222
after = self.nodes[1].getbalances()['mine']['untrusted_pending']
223223
assert_equal(before + Decimal('0.1'), after)
224224

test/functional/wallet_descriptor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def run_test(self):
2424
# Make a descriptor wallet
2525
self.log.info("Making a descriptor wallet")
2626
self.nodes[0].createwallet(wallet_name="desc1", descriptors=True)
27-
self.nodes[0].unloadwallet("")
27+
self.nodes[0].unloadwallet(self.default_wallet_name)
2828

2929
# A descriptor wallet should have 100 addresses * 3 types = 300 keys
3030
self.log.info("Checking wallet info")

test/functional/wallet_disable.py

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def set_test_params(self):
1616
self.setup_clean_chain = True
1717
self.num_nodes = 1
1818
self.extra_args = [["-disablewallet"]]
19+
self.wallet_names = []
1920

2021
def run_test (self):
2122
# Make sure wallet is really disabled

0 commit comments

Comments
 (0)