Skip to content

Commit c7b7e0a

Browse files
committed
tests: Make only desc wallets for wallet_multwallet.py --descriptors
1 parent d4b67ad commit c7b7e0a

File tree

1 file changed

+44
-24
lines changed

1 file changed

+44
-24
lines changed

test/functional/wallet_multiwallet.py

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ def wallet_file(name):
8282
# directory paths) can be loaded
8383
# create another dummy wallet for use in testing backups later
8484
self.start_node(0)
85-
node.createwallet("empty", descriptors=False)
86-
node.createwallet("plain", descriptors=False)
85+
node.createwallet("empty")
86+
node.createwallet("plain")
8787
node.createwallet("created")
8888
self.stop_nodes()
8989
empty_wallet = os.path.join(self.options.tmpdir, 'empty.dat')
@@ -101,20 +101,29 @@ def wallet_file(name):
101101
# sub/w5 - to verify relative wallet path is created correctly
102102
# extern/w6 - to verify absolute wallet path is created correctly
103103
# w7_symlink - to verify symlinked wallet path is initialized correctly
104-
# w8 - to verify existing wallet file is loaded correctly
104+
# w8 - to verify existing wallet file is loaded correctly. Not tested for SQLite wallets as this is a deprecated BDB behavior.
105105
# '' - to verify default wallet file is created correctly
106-
wallet_names = ['w1', 'w2', 'w3', 'w', 'sub/w5', os.path.join(self.options.tmpdir, 'extern/w6'), 'w7_symlink', 'w8', self.default_wallet_name]
106+
to_create = ['w1', 'w2', 'w3', 'w', 'sub/w5', 'w7_symlink']
107+
in_wallet_dir = to_create.copy() # Wallets in the wallet dir
108+
in_wallet_dir.append('w7') # w7 is not loaded or created, but will be listed by listwalletdir because w7_symlink
109+
to_create.append(os.path.join(self.options.tmpdir, 'extern/w6')) # External, not in the wallet dir, so we need to avoid adding it to in_wallet_dir
110+
to_load = [self.default_wallet_name]
111+
if not self.options.descriptors:
112+
to_load.append('w8')
113+
wallet_names = to_create + to_load # Wallet names loaded in the wallet
114+
in_wallet_dir += to_load # The loaded wallets are also in the wallet dir
107115
self.start_node(0)
108-
for wallet_name in wallet_names[:-2]:
109-
self.nodes[0].createwallet(wallet_name, descriptors=False)
110-
for wallet_name in wallet_names[-2:]:
116+
for wallet_name in to_create:
117+
self.nodes[0].createwallet(wallet_name)
118+
for wallet_name in to_load:
111119
self.nodes[0].loadwallet(wallet_name)
112-
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), [self.default_wallet_name, os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8'])
120+
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), sorted(in_wallet_dir))
113121

114122
assert_equal(set(node.listwallets()), set(wallet_names))
115123

116124
# should raise rpc error if wallet path can't be created
117-
assert_raises_rpc_error(-1, "boost::filesystem::create_directory:", self.nodes[0].createwallet, "w8/bad", descriptors=False)
125+
err_code = -4 if self.options.descriptors else -1
126+
assert_raises_rpc_error(err_code, "boost::filesystem::create_directory:", self.nodes[0].createwallet, "w8/bad")
118127

119128
# check that all requested wallets were created
120129
self.stop_node(0)
@@ -128,10 +137,13 @@ def wallet_file(name):
128137
# should not initialize if there are duplicate wallets
129138
self.nodes[0].assert_start_raises_init_error(['-wallet=w1', '-wallet=w1'], 'Error: Error loading wallet w1. Duplicate -wallet filename specified.')
130139

131-
# should not initialize if one wallet is a copy of another
132-
shutil.copyfile(wallet_dir('w8'), wallet_dir('w8_copy'))
133-
exp_stderr = r"BerkeleyDatabase: Can't open database w8_copy \(duplicates fileid \w+ from w8\)"
134-
self.nodes[0].assert_start_raises_init_error(['-wallet=w8', '-wallet=w8_copy'], exp_stderr, match=ErrorMatch.PARTIAL_REGEX)
140+
if not self.options.descriptors:
141+
# Only BDB doesn't open duplicate wallet files. SQLite does not have this limitation. While this may be desired in the future, it is not necessary
142+
# should not initialize if one wallet is a copy of another
143+
shutil.copyfile(wallet_dir('w8'), wallet_dir('w8_copy'))
144+
in_wallet_dir.append('w8_copy')
145+
exp_stderr = r"BerkeleyDatabase: Can't open database w8_copy \(duplicates fileid \w+ from w8\)"
146+
self.nodes[0].assert_start_raises_init_error(['-wallet=w8', '-wallet=w8_copy'], exp_stderr, match=ErrorMatch.PARTIAL_REGEX)
135147

136148
# should not initialize if wallet file is a symlink
137149
os.symlink('w8', wallet_dir('w8_symlink'))
@@ -167,15 +179,18 @@ def wallet_file(name):
167179
competing_wallet_dir = os.path.join(self.options.tmpdir, 'competing_walletdir')
168180
os.mkdir(competing_wallet_dir)
169181
self.restart_node(0, ['-nowallet', '-walletdir=' + competing_wallet_dir])
170-
self.nodes[0].createwallet(self.default_wallet_name, descriptors=False)
171-
exp_stderr = r"Error: Error initializing wallet database environment \"\S+competing_walletdir\S*\"!"
182+
self.nodes[0].createwallet(self.default_wallet_name)
183+
if self.options.descriptors:
184+
exp_stderr = r"Error: SQLiteDatabase: Unable to obtain an exclusive lock on the database, is it being used by another bitcoind?"
185+
else:
186+
exp_stderr = r"Error: Error initializing wallet database environment \"\S+competing_walletdir\S*\"!"
172187
self.nodes[1].assert_start_raises_init_error(['-walletdir=' + competing_wallet_dir], exp_stderr, match=ErrorMatch.PARTIAL_REGEX)
173188

174189
self.restart_node(0)
175190
for wallet_name in wallet_names:
176191
self.nodes[0].loadwallet(wallet_name)
177192

178-
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), [self.default_wallet_name, os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8', 'w8_copy'])
193+
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), sorted(in_wallet_dir))
179194

180195
wallets = [wallet(w) for w in wallet_names]
181196
wallet_bad = wallet("bad")
@@ -266,18 +281,22 @@ def wallet_file(name):
266281

267282
# Fail to load duplicate wallets
268283
path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "w1", "wallet.dat")
269-
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])
284+
if self.options.descriptors:
285+
assert_raises_rpc_error(-4, "Wallet file verification failed. SQLiteDatabase: Unable to obtain an exclusive lock on the database, is it being used by another bitcoind?", self.nodes[0].loadwallet, wallet_names[0])
286+
else:
287+
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])
270288

271-
# Fail to load duplicate wallets by different ways (directory and filepath)
272-
if not self.options.descriptors:
289+
# This tests the default wallet that BDB makes, so SQLite wallet doesn't need to test this
290+
# Fail to load duplicate wallets by different ways (directory and filepath)
273291
path = os.path.join(self.options.tmpdir, "node0", "regtest", "wallets", "wallet.dat")
274292
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')
275293

276-
# Fail to load if one wallet is a copy of another
277-
assert_raises_rpc_error(-4, "BerkeleyDatabase: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
294+
# Only BDB doesn't open duplicate wallet files. SQLite does not have this limitation. While this may be desired in the future, it is not necessary
295+
# Fail to load if one wallet is a copy of another
296+
assert_raises_rpc_error(-4, "BerkeleyDatabase: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
278297

279-
# Fail to load if one wallet is a copy of another, test this twice to make sure that we don't re-introduce #14304
280-
assert_raises_rpc_error(-4, "BerkeleyDatabase: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
298+
# Fail to load if one wallet is a copy of another, test this twice to make sure that we don't re-introduce #14304
299+
assert_raises_rpc_error(-4, "BerkeleyDatabase: Can't open database w8_copy (duplicates fileid", self.nodes[0].loadwallet, 'w8_copy')
281300

282301

283302
# Fail to load if wallet file is a symlink
@@ -296,6 +315,7 @@ def wallet_file(name):
296315

297316
# Successfully create a wallet with a new name
298317
loadwallet_name = self.nodes[0].createwallet('w9')
318+
in_wallet_dir.append('w9')
299319
assert_equal(loadwallet_name['name'], 'w9')
300320
w9 = node.get_wallet_rpc('w9')
301321
assert_equal(w9.getwalletinfo()['walletname'], 'w9')
@@ -343,7 +363,7 @@ def wallet_file(name):
343363
assert_equal(self.nodes[0].listwallets(), ['w1'])
344364
assert_equal(w1.getwalletinfo()['walletname'], 'w1')
345365

346-
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), [self.default_wallet_name, os.path.join('sub', 'w5'), 'w', 'w1', 'w2', 'w3', 'w7', 'w7_symlink', 'w8', 'w8_copy', 'w9'])
366+
assert_equal(sorted(map(lambda w: w['name'], self.nodes[0].listwalletdir()['wallets'])), sorted(in_wallet_dir))
347367

348368
# Test backing up and restoring wallets
349369
self.log.info("Test wallet backup")

0 commit comments

Comments
 (0)