@@ -60,8 +60,10 @@ def run_test(self):
60
60
wallet = lambda name : node .get_wallet_rpc (name )
61
61
62
62
def wallet_file (name ):
63
+ if name == self .default_wallet_name :
64
+ return wallet_dir (self .default_wallet_name , self .wallet_data_filename )
63
65
if os .path .isdir (wallet_dir (name )):
64
- return wallet_dir (name , self . wallet_data_filename )
66
+ return wallet_dir (name , "wallet.dat" )
65
67
return wallet_dir (name )
66
68
67
69
assert_equal (self .nodes [0 ].listwalletdir (), { 'wallets' : [{ 'name' : self .default_wallet_name }] })
@@ -77,13 +79,18 @@ def wallet_file(name):
77
79
78
80
# rename wallet.dat to make sure plain wallet file paths (as opposed to
79
81
# directory paths) can be loaded
80
- os .rename (wallet_dir (self .default_wallet_name , self .wallet_data_filename ), wallet_dir ("w8" ))
81
-
82
82
# 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" )
84
85
self .stop_nodes ()
85
86
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" ))
87
94
88
95
# restart node with a mix of wallet names:
89
96
# w1, w2, w3 - to verify new wallets created when non-existing paths specified
@@ -151,7 +158,7 @@ def wallet_file(name):
151
158
competing_wallet_dir = os .path .join (self .options .tmpdir , 'competing_walletdir' )
152
159
os .mkdir (competing_wallet_dir )
153
160
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*\ "!"
155
162
self .nodes [1 ].assert_start_raises_init_error (['-walletdir=' + competing_wallet_dir ], exp_stderr , match = ErrorMatch .PARTIAL_REGEX )
156
163
157
164
self .restart_node (0 , extra_args )
@@ -246,12 +253,13 @@ def wallet_file(name):
246
253
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' )
247
254
248
255
# 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" )
250
257
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 ])
251
258
252
259
# 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' )
255
263
256
264
# Fail to load if one wallet is a copy of another
257
265
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):
334
342
rpc = self .nodes [0 ].get_wallet_rpc (wallet_name )
335
343
addr = rpc .getnewaddress ()
336
344
backup = os .path .join (self .options .tmpdir , 'backup.dat' )
345
+ if os .path .exists (backup ):
346
+ os .unlink (backup )
337
347
rpc .backupwallet (backup )
338
348
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 ))
340
350
self .nodes [0 ].loadwallet (wallet_name )
341
351
assert_equal (rpc .getaddressinfo (addr )['ismine' ], False )
342
352
self .nodes [0 ].unloadwallet (wallet_name )
@@ -348,7 +358,10 @@ def wallet_file(name):
348
358
self .start_node (1 )
349
359
wallet = os .path .join (self .options .tmpdir , 'my_wallet' )
350
360
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 )
352
365
self .nodes [0 ].unloadwallet (wallet )
353
366
self .nodes [1 ].loadwallet (wallet )
354
367
0 commit comments