@@ -82,8 +82,8 @@ def wallet_file(name):
82
82
# directory paths) can be loaded
83
83
# create another dummy wallet for use in testing backups later
84
84
self .start_node (0 )
85
- node .createwallet ("empty" , descriptors = False )
86
- node .createwallet ("plain" , descriptors = False )
85
+ node .createwallet ("empty" )
86
+ node .createwallet ("plain" )
87
87
node .createwallet ("created" )
88
88
self .stop_nodes ()
89
89
empty_wallet = os .path .join (self .options .tmpdir , 'empty.dat' )
@@ -101,20 +101,29 @@ def wallet_file(name):
101
101
# sub/w5 - to verify relative wallet path is created correctly
102
102
# extern/w6 - to verify absolute wallet path is created correctly
103
103
# 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.
105
105
# '' - 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
107
115
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 :
111
119
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 ) )
113
121
114
122
assert_equal (set (node .listwallets ()), set (wallet_names ))
115
123
116
124
# 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" )
118
127
119
128
# check that all requested wallets were created
120
129
self .stop_node (0 )
@@ -128,10 +137,13 @@ def wallet_file(name):
128
137
# should not initialize if there are duplicate wallets
129
138
self .nodes [0 ].assert_start_raises_init_error (['-wallet=w1' , '-wallet=w1' ], 'Error: Error loading wallet w1. Duplicate -wallet filename specified.' )
130
139
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 )
135
147
136
148
# should not initialize if wallet file is a symlink
137
149
os .symlink ('w8' , wallet_dir ('w8_symlink' ))
@@ -167,15 +179,18 @@ def wallet_file(name):
167
179
competing_wallet_dir = os .path .join (self .options .tmpdir , 'competing_walletdir' )
168
180
os .mkdir (competing_wallet_dir )
169
181
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*\"!"
172
187
self .nodes [1 ].assert_start_raises_init_error (['-walletdir=' + competing_wallet_dir ], exp_stderr , match = ErrorMatch .PARTIAL_REGEX )
173
188
174
189
self .restart_node (0 )
175
190
for wallet_name in wallet_names :
176
191
self .nodes [0 ].loadwallet (wallet_name )
177
192
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 ) )
179
194
180
195
wallets = [wallet (w ) for w in wallet_names ]
181
196
wallet_bad = wallet ("bad" )
@@ -266,18 +281,22 @@ def wallet_file(name):
266
281
267
282
# Fail to load duplicate wallets
268
283
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 ])
270
288
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)
273
291
path = os .path .join (self .options .tmpdir , "node0" , "regtest" , "wallets" , "wallet.dat" )
274
292
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' )
275
293
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' )
278
297
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' )
281
300
282
301
283
302
# Fail to load if wallet file is a symlink
@@ -296,6 +315,7 @@ def wallet_file(name):
296
315
297
316
# Successfully create a wallet with a new name
298
317
loadwallet_name = self .nodes [0 ].createwallet ('w9' )
318
+ in_wallet_dir .append ('w9' )
299
319
assert_equal (loadwallet_name ['name' ], 'w9' )
300
320
w9 = node .get_wallet_rpc ('w9' )
301
321
assert_equal (w9 .getwalletinfo ()['walletname' ], 'w9' )
@@ -343,7 +363,7 @@ def wallet_file(name):
343
363
assert_equal (self .nodes [0 ].listwallets (), ['w1' ])
344
364
assert_equal (w1 .getwalletinfo ()['walletname' ], 'w1' )
345
365
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 ) )
347
367
348
368
# Test backing up and restoring wallets
349
369
self .log .info ("Test wallet backup" )
0 commit comments