Skip to content

Commit c4a29d0

Browse files
ryanofskyachow101
authored andcommitted
Update wallet_multiwallet.py for descriptor and sqlite wallets
1 parent 310b0fd commit c4a29d0

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

test/functional/test_framework/test_framework.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def __init__(self):
103103
self.supports_cli = True
104104
self.bind_to_localhost_only = True
105105
self.parse_args()
106-
self.default_wallet_name = ""
106+
self.default_wallet_name = "default_wallet" if self.options.descriptors else ""
107107
self.wallet_data_filename = "wallet.dat"
108108
# Optional list of wallet names that can be set in set_test_params to
109109
# create and import keys to. If unset, default is len(nodes) *

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@
141141
'mempool_reorg.py',
142142
'mempool_persist.py',
143143
'wallet_multiwallet.py',
144+
'wallet_multiwallet.py --descriptors',
144145
'wallet_multiwallet.py --usecli',
145146
'wallet_createwallet.py',
146147
'wallet_createwallet.py --usecli',

test/functional/wallet_multiwallet.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ def run_test(self):
6060
wallet = lambda name: node.get_wallet_rpc(name)
6161

6262
def wallet_file(name):
63+
if name == self.default_wallet_name:
64+
return wallet_dir(self.default_wallet_name, self.wallet_data_filename)
6365
if os.path.isdir(wallet_dir(name)):
64-
return wallet_dir(name, self.wallet_data_filename)
66+
return wallet_dir(name, "wallet.dat")
6567
return wallet_dir(name)
6668

6769
assert_equal(self.nodes[0].listwalletdir(), { 'wallets': [{ 'name': self.default_wallet_name }] })
@@ -77,13 +79,18 @@ def wallet_file(name):
7779

7880
# rename wallet.dat to make sure plain wallet file paths (as opposed to
7981
# directory paths) can be loaded
80-
os.rename(wallet_dir(self.default_wallet_name, self.wallet_data_filename), wallet_dir("w8"))
81-
8282
# create another dummy wallet for use in testing backups later
83-
self.start_node(0, ["-nowallet", "-wallet=" + self.default_wallet_name])
83+
self.start_node(0, ["-nowallet", "-wallet=empty", "-wallet=plain"])
84+
node.createwallet("created")
8485
self.stop_nodes()
8586
empty_wallet = os.path.join(self.options.tmpdir, 'empty.dat')
86-
os.rename(wallet_dir(self.default_wallet_name, self.wallet_data_filename), empty_wallet)
87+
os.rename(wallet_file("empty"), empty_wallet)
88+
shutil.rmtree(wallet_dir("empty"))
89+
empty_created_wallet = os.path.join(self.options.tmpdir, 'empty.created.dat')
90+
os.rename(wallet_dir("created", self.wallet_data_filename), empty_created_wallet)
91+
shutil.rmtree(wallet_dir("created"))
92+
os.rename(wallet_file("plain"), wallet_dir("w8"))
93+
shutil.rmtree(wallet_dir("plain"))
8794

8895
# restart node with a mix of wallet names:
8996
# w1, w2, w3 - to verify new wallets created when non-existing paths specified
@@ -151,7 +158,7 @@ def wallet_file(name):
151158
competing_wallet_dir = os.path.join(self.options.tmpdir, 'competing_walletdir')
152159
os.mkdir(competing_wallet_dir)
153160
self.restart_node(0, ['-walletdir=' + competing_wallet_dir])
154-
exp_stderr = r"Error: Error initializing wallet database environment \"\S+competing_walletdir\"!"
161+
exp_stderr = r"Error: Error initializing wallet database environment \"\S+competing_walletdir\S*\"!"
155162
self.nodes[1].assert_start_raises_init_error(['-walletdir=' + competing_wallet_dir], exp_stderr, match=ErrorMatch.PARTIAL_REGEX)
156163

157164
self.restart_node(0, extra_args)
@@ -246,12 +253,13 @@ def wallet_file(name):
246253
assert_raises_rpc_error(-18, "Wallet file verification failed. Failed to load database path '{}'. Path does not exist.".format(path), self.nodes[0].loadwallet, 'wallets')
247254

248255
# Fail to load duplicate wallets
249-
path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "w1", self.wallet_data_filename)
256+
path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "w1", "wallet.dat")
250257
assert_raises_rpc_error(-4, "Wallet file verification failed. Refusing to load database. Data file '{}' is already loaded.".format(path), self.nodes[0].loadwallet, wallet_names[0])
251258

252259
# Fail to load duplicate wallets by different ways (directory and filepath)
253-
path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", self.wallet_data_filename)
254-
assert_raises_rpc_error(-4, "Wallet file verification failed. Refusing to load database. Data file '{}' is already loaded.".format(path), self.nodes[0].loadwallet, self.wallet_data_filename)
260+
if not self.options.descriptors:
261+
path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "wallet.dat")
262+
assert_raises_rpc_error(-4, "Wallet file verification failed. Refusing to load database. Data file '{}' is already loaded.".format(path), self.nodes[0].loadwallet, 'wallet.dat')
255263

256264
# Fail to load if one wallet is a copy of another
257265
assert_raises_rpc_error(-4, "BerkeleyDatabase: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
@@ -334,9 +342,11 @@ def wallet_file(name):
334342
rpc = self.nodes[0].get_wallet_rpc(wallet_name)
335343
addr = rpc.getnewaddress()
336344
backup = os.path.join(self.options.tmpdir, 'backup.dat')
345+
if os.path.exists(backup):
346+
os.unlink(backup)
337347
rpc.backupwallet(backup)
338348
self.nodes[0].unloadwallet(wallet_name)
339-
shutil.copyfile(empty_wallet, wallet_file(wallet_name))
349+
shutil.copyfile(empty_created_wallet if wallet_name == self.default_wallet_name else empty_wallet, wallet_file(wallet_name))
340350
self.nodes[0].loadwallet(wallet_name)
341351
assert_equal(rpc.getaddressinfo(addr)['ismine'], False)
342352
self.nodes[0].unloadwallet(wallet_name)
@@ -348,7 +358,10 @@ def wallet_file(name):
348358
self.start_node(1)
349359
wallet = os.path.join(self.options.tmpdir, 'my_wallet')
350360
self.nodes[0].createwallet(wallet)
351-
assert_raises_rpc_error(-4, "Error initializing wallet database environment", self.nodes[1].loadwallet, wallet)
361+
if self.options.descriptors:
362+
assert_raises_rpc_error(-4, "Unable to obtain an exclusive lock", self.nodes[1].loadwallet, wallet)
363+
else:
364+
assert_raises_rpc_error(-4, "Error initializing wallet database environment", self.nodes[1].loadwallet, wallet)
352365
self.nodes[0].unloadwallet(wallet)
353366
self.nodes[1].loadwallet(wallet)
354367

0 commit comments

Comments
 (0)