Skip to content

Commit 1a2dbc8

Browse files
kwvgUdjinM6
andcommitted
merge bitcoin#20034: Get rid of default wallet hacks
Co-authored-by: UdjinM6 <[email protected]>
1 parent cda49c3 commit 1a2dbc8

18 files changed

+84
-67
lines changed

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_fee_estimation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ def set_test_params(self):
126126
self.num_nodes = 3
127127
# mine non-standard txs (e.g. txs with "dust" outputs)
128128
self.extra_args = [
129-
["-acceptnonstdtxn=1", "-maxorphantxsize=1000", "-whitelist=127.0.0.1", "-wallet="],
130-
["-acceptnonstdtxn=1", "-blockmaxsize=17000", "-maxorphantxsize=1000", "-whitelist=127.0.0.1", "-wallet="],
131-
["-acceptnonstdtxn=1", "-blockmaxsize=8000", "-maxorphantxsize=1000", "-whitelist=127.0.0.1", "-wallet="]
129+
["-acceptnonstdtxn=1", "-maxorphantxsize=1000", "-whitelist=127.0.0.1"],
130+
["-acceptnonstdtxn=1", "-blockmaxsize=17000", "-maxorphantxsize=1000", "-whitelist=127.0.0.1"],
131+
["-acceptnonstdtxn=1", "-blockmaxsize=8000", "-maxorphantxsize=1000", "-whitelist=127.0.0.1"]
132132
]
133133

134134
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 dashd 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
@@ -44,8 +44,8 @@ def setup_network(self):
4444
"-blocknotify=echo > {}".format(os.path.join(self.blocknotify_dir, '%s'))],
4545
["-blockversion=211",
4646
"-rescan",
47-
"-wallet={}".format(self.wallet),
4847
"-walletnotify=echo > {}".format(os.path.join(self.walletnotify_dir, notify_outputname('%w', '%s')))]]
48+
self.wallet_names = [self.default_wallet_name, self.wallet]
4949
super().setup_network()
5050

5151
def run_test(self):

test/functional/feature_pruning.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ def setup_network(self):
106106
def setup_nodes(self):
107107
self.add_nodes(self.num_nodes, self.extra_args)
108108
self.start_nodes()
109-
for n in self.nodes:
110-
n.importprivkey(privkey=n.get_deterministic_priv_key().key, label='coinbase', rescan=False)
109+
self.import_deterministic_coinbase_privkeys()
111110

112111
def create_big_chain(self):
113112
# 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/rpc_platform_filter.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def set_test_params(self):
1818
self.num_nodes = 1
1919
self.supports_cli = False
2020

21+
def setup_nodes(self):
22+
self.add_nodes(self.num_nodes)
23+
self.start_nodes()
24+
2125
def setup_chain(self):
2226
super().setup_chain()
2327
# Append rpcauth to dash.conf before initialization
@@ -36,7 +40,6 @@ def setup_chain(self):
3640
f.write(rpcauthoperator+"\n")
3741

3842
def run_test(self):
39-
4043
url = urllib.parse.urlparse(self.nodes[0].url)
4144

4245
def test_command(method, params, auth, expexted_status, should_not_match=False):

test/functional/test_framework/test_framework.py

+17-10
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,17 @@ def __init__(self):
118118
self.rpc_timeout = 60 # Wait for up to 60 seconds for the RPC server to respond
119119
self.supports_cli = True
120120
self.bind_to_localhost_only = True
121+
self.parse_args()
122+
self.default_wallet_name = ""
123+
self.wallet_data_filename = "wallet.dat"
121124
self.extra_args_from_options = []
125+
# Optional list of wallet names that can be set in set_test_params to
126+
# create and import keys to. If unset, default is len(nodes) *
127+
# [default_wallet_name]. If wallet names are None, wallet creation is
128+
# skipped. If list is truncated, wallet creation is skipped and keys
129+
# are not imported.
130+
self.wallet_names = None
122131
self.set_test_params()
123-
self.parse_args()
124132
if self.options.timeout_factor == 0 :
125133
self.options.timeout_factor = 99999
126134
self.rpc_timeout = int(self.rpc_timeout * self.options.timeout_factor) # optionally, increase timeout by a factor
@@ -385,7 +393,8 @@ def setup_nodes(self):
385393
extra_args = self.extra_args
386394
self.add_nodes(self.num_nodes, extra_args)
387395
self.start_nodes()
388-
self.import_deterministic_coinbase_privkeys()
396+
if self.is_wallet_compiled():
397+
self.import_deterministic_coinbase_privkeys()
389398
if not self.setup_clean_chain:
390399
for n in self.nodes:
391400
assert_equal(n.getblockchaininfo()["blocks"], 199)
@@ -402,13 +411,11 @@ def setup_nodes(self):
402411
assert_equal(chain_info["initialblockdownload"], False)
403412

404413
def import_deterministic_coinbase_privkeys(self):
405-
for n in self.nodes:
406-
try:
407-
n.getwalletinfo()
408-
except JSONRPCException as e:
409-
assert str(e).startswith('Method not found')
410-
continue
411-
414+
wallet_names = [self.default_wallet_name] * len(self.nodes) if self.wallet_names is None else self.wallet_names
415+
assert len(wallet_names) <= len(self.nodes)
416+
for wallet_name, n in zip(wallet_names, self.nodes):
417+
if wallet_name is not None:
418+
n.createwallet(wallet_name=wallet_name, load_on_startup=True)
412419
n.importprivkey(privkey=n.get_deterministic_priv_key().key, label='coinbase')
413420

414421
def run_test(self):
@@ -874,6 +881,7 @@ def create_simple_node(self):
874881
idx = len(self.nodes)
875882
self.add_nodes(1, extra_args=[self.extra_args[idx]])
876883
self.start_node(idx)
884+
self.nodes[idx].createwallet(self.default_wallet_name)
877885
for i in range(0, idx):
878886
connect_nodes(self.nodes[i], idx)
879887

@@ -1033,7 +1041,6 @@ def setup_network(self):
10331041
self.prepare_masternodes()
10341042
self.prepare_datadirs()
10351043
self.start_masternodes()
1036-
self.import_deterministic_coinbase_privkeys()
10371044

10381045
# non-masternodes where disconnected from the control node during prepare_datadirs,
10391046
# let's reconnect them back to make sure they receive updates

test/functional/tool_wallet.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def test_invalid_tool_commands_and_args(self):
7272
locked_dir = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets")
7373
self.assert_raises_tool_error(
7474
'Error initializing wallet database environment "{}"!'.format(locked_dir),
75-
'-wallet=wallet.dat',
75+
'-wallet=' + self.default_wallet_name,
7676
'info',
7777
)
7878
path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "nonexistent.dat")
@@ -118,7 +118,7 @@ def test_tool_wallet_info(self):
118118
Transactions: 0
119119
Address Book: 1
120120
''')
121-
self.assert_tool_output(out, '-wallet=wallet.dat', 'info')
121+
self.assert_tool_output(out, '-wallet=' + self.default_wallet_name, 'info')
122122
timestamp_after = self.wallet_timestamp()
123123
self.log.debug('Wallet file timestamp after calling info: {}'.format(timestamp_after))
124124
self.log_wallet_timestamp_comparison(timestamp_before, timestamp_after)
@@ -157,7 +157,7 @@ def test_tool_wallet_info_after_transaction(self):
157157
Transactions: 1
158158
Address Book: 1
159159
''')
160-
self.assert_tool_output(out, '-wallet=wallet.dat', 'info')
160+
self.assert_tool_output(out, '-wallet=' + self.default_wallet_name, 'info')
161161
shasum_after = self.wallet_shasum()
162162
timestamp_after = self.wallet_timestamp()
163163
self.log.debug('Wallet file timestamp after calling info: {}'.format(timestamp_after))
@@ -195,7 +195,7 @@ def test_tool_wallet_create_on_existing_wallet(self):
195195

196196
def test_getwalletinfo_on_different_wallet(self):
197197
self.log.info('Starting node with arg -wallet=foo')
198-
self.start_node(0, ['-wallet=foo'])
198+
self.start_node(0, ['-nowallet', '-wallet=foo'])
199199

200200
self.log.info('Calling getwalletinfo on a different wallet ("foo"), testing output')
201201
shasum_before = self.wallet_shasum()
@@ -225,7 +225,7 @@ def test_salvage(self):
225225
self.assert_tool_output('', '-wallet=salvage', 'salvage')
226226

227227
def run_test(self):
228-
self.wallet_path = os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat')
228+
self.wallet_path = os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename)
229229
self.test_invalid_tool_commands_and_args()
230230
# Warning: The following tests are order-dependent.
231231
self.test_tool_wallet_info()

test/functional/wallet_backup.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ def set_test_params(self):
4545
# nodes 1, 2,3 are spenders, let's give them a keypool=100
4646
# whitelist all peers to speed up tx relay / mempool sync
4747
self.extra_args = [
48-
["-keypool=100", "-whitelist=127.0.0.1", "-wallet="],
49-
["-keypool=100", "-whitelist=127.0.0.1", "-wallet="],
50-
["-keypool=100", "-whitelist=127.0.0.1", "-wallet="],
51-
["-whitelist=127.0.0.1", "-wallet="]
48+
["-keypool=100", "-whitelist=127.0.0.1"],
49+
["-keypool=100", "-whitelist=127.0.0.1"],
50+
["-keypool=100", "-whitelist=127.0.0.1"],
51+
["-whitelist=127.0.0.1"]
5252
]
5353
self.rpc_timeout = 120
5454

@@ -102,9 +102,9 @@ def stop_three(self):
102102
self.stop_node(2)
103103

104104
def erase_three(self):
105-
os.remove(os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat'))
106-
os.remove(os.path.join(self.nodes[1].datadir, self.chain, 'wallets', 'wallet.dat'))
107-
os.remove(os.path.join(self.nodes[2].datadir, self.chain, 'wallets', 'wallet.dat'))
105+
os.remove(os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
106+
os.remove(os.path.join(self.nodes[1].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
107+
os.remove(os.path.join(self.nodes[2].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename))
108108

109109
def run_test(self):
110110
self.log.info("Generating initial blockchain")
@@ -168,9 +168,9 @@ def run_test(self):
168168
shutil.rmtree(os.path.join(self.nodes[2].datadir, self.chain, 'llmq'))
169169

170170
# Restore wallets from backup
171-
shutil.copyfile(os.path.join(self.nodes[0].datadir, 'wallet.bak'), os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat'))
172-
shutil.copyfile(os.path.join(self.nodes[1].datadir, 'wallet.bak'), os.path.join(self.nodes[1].datadir, self.chain, 'wallets', 'wallet.dat'))
173-
shutil.copyfile(os.path.join(self.nodes[2].datadir, 'wallet.bak'), os.path.join(self.nodes[2].datadir, self.chain, 'wallets', 'wallet.dat'))
171+
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))
172+
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))
173+
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))
174174

175175
self.log.info("Re-starting nodes")
176176
self.start_three()
@@ -208,9 +208,9 @@ def run_test(self):
208208

209209
# Backup to source wallet file must fail
210210
sourcePaths = [
211-
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', 'wallet.dat'),
212-
os.path.join(self.nodes[0].datadir, self.chain, '.', 'wallets', 'wallet.dat'),
213-
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', ''),
211+
os.path.join(self.nodes[0].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename),
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),
214214
os.path.join(self.nodes[0].datadir, self.chain, 'wallets')]
215215

216216
for sourcePath in sourcePaths:

test/functional/wallet_balance.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ def test_balances(*, fee_node_1=0):
153153
# dynamically loading the wallet.
154154
before = self.nodes[1].getunconfirmedbalance()
155155
dst = self.nodes[1].getnewaddress()
156-
self.nodes[1].unloadwallet('')
156+
self.nodes[1].unloadwallet(self.default_wallet_name)
157157
self.nodes[0].sendtoaddress(dst, 0.1)
158158
self.sync_all()
159-
self.nodes[1].loadwallet('')
159+
self.nodes[1].loadwallet(self.default_wallet_name)
160160
after = self.nodes[1].getunconfirmedbalance()
161161
assert_equal(before + Decimal('0.1'), after)
162162

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

test/functional/wallet_hd.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ def run_test(self):
8282
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "chainstate"))
8383
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "evodb"))
8484
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "llmq"))
85-
shutil.copyfile(os.path.join(self.nodes[1].datadir, "hd.bak"), os.path.join(self.nodes[1].datadir, self.chain, "wallets", "wallet.dat"))
85+
shutil.copyfile(
86+
os.path.join(self.nodes[1].datadir, "hd.bak"),
87+
os.path.join(self.nodes[1].datadir, self.chain, 'wallets', self.default_wallet_name, self.wallet_data_filename),
88+
)
8689
self.start_node(1)
8790

8891
# Assert that derivation is deterministic
@@ -107,7 +110,10 @@ def run_test(self):
107110
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "chainstate"))
108111
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "evodb"))
109112
shutil.rmtree(os.path.join(self.nodes[1].datadir, self.chain, "llmq"))
110-
shutil.copyfile(os.path.join(self.nodes[1].datadir, "hd.bak"), os.path.join(self.nodes[1].datadir, self.chain, "wallets", "wallet.dat"))
113+
shutil.copyfile(
114+
os.path.join(self.nodes[1].datadir, "hd.bak"),
115+
os.path.join(self.nodes[1].datadir, self.chain, "wallets", self.default_wallet_name, self.wallet_data_filename),
116+
)
111117
self.start_node(1, extra_args=self.extra_args[1])
112118
connect_nodes(self.nodes[0], 1)
113119
self.sync_all()

test/functional/wallet_import_rescan.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def skip_test_if_missing_module(self):
126126
self.skip_if_no_wallet()
127127

128128
def setup_network(self):
129-
extra_args = [["-wallet="] for _ in range(self.num_nodes)]
129+
extra_args = [[] for _ in range(self.num_nodes)]
130130
for i, import_node in enumerate(IMPORT_NODES, 2):
131131
if import_node.prune:
132132
# txindex is enabled by default in Dash and needs to be disabled for import-rescan.py
@@ -135,9 +135,8 @@ def setup_network(self):
135135
self.add_nodes(self.num_nodes, extra_args=extra_args)
136136

137137
# Import keys with pruning disabled
138-
self.start_nodes(extra_args=[["-wallet="]] * self.num_nodes)
139-
for n in self.nodes:
140-
n.importprivkey(privkey=n.get_deterministic_priv_key().key, label='coinbase')
138+
self.start_nodes(extra_args=[[]] * self.num_nodes)
139+
self.import_deterministic_coinbase_privkeys()
141140
self.stop_nodes()
142141

143142
self.start_nodes()

test/functional/wallet_importmulti.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ def run_test(self):
673673

674674
# Cannot import those pubkeys to keypool of wallet with privkeys
675675
self.log.info("Pubkeys cannot be added to the keypool of a wallet with private keys")
676-
wrpc = self.nodes[1].get_wallet_rpc("")
676+
wrpc = self.nodes[1].get_wallet_rpc(self.default_wallet_name)
677677
assert wrpc.getwalletinfo()['private_keys_enabled']
678678
result = wrpc.importmulti(
679679
[{

test/functional/wallet_keypool_topup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def skip_test_if_missing_module(self):
3030
self.skip_if_no_wallet()
3131

3232
def run_test(self):
33-
wallet_path = os.path.join(self.nodes[1].datadir, self.chain, "wallets", "wallet.dat")
33+
wallet_path = os.path.join(self.nodes[1].datadir, self.chain, "wallets", self.default_wallet_name, self.wallet_data_filename)
3434
wallet_backup_path = os.path.join(self.nodes[1].datadir, "wallet.bak")
3535
self.nodes[0].generate(101)
3636

0 commit comments

Comments
 (0)