66
77import os
88import random
9+ import shutil
910from test_framework .descriptors import descsum_create
1011from test_framework .test_framework import BitcoinTestFramework
1112from test_framework .util import (
@@ -470,6 +471,40 @@ def test_unloaded_by_path(self):
470471
471472 assert_equal (bals , wallet .getbalances ())
472473
474+ def test_default_wallet (self ):
475+ self .log .info ("Test migration of the wallet named as the empty string" )
476+ wallet = self .create_legacy_wallet ("" )
477+
478+ wallet .migratewallet ()
479+ info = wallet .getwalletinfo ()
480+ assert_equal (info ["descriptors" ], True )
481+ assert_equal (info ["format" ], "sqlite" )
482+
483+ def test_direct_file (self ):
484+ self .log .info ("Test migration of a wallet that is not in a wallet directory" )
485+ wallet = self .create_legacy_wallet ("plainfile" )
486+ wallet .unloadwallet ()
487+
488+ wallets_dir = os .path .join (self .nodes [0 ].datadir , "regtest" , "wallets" )
489+ wallet_path = os .path .join (wallets_dir , "plainfile" )
490+ wallet_dat_path = os .path .join (wallet_path , "wallet.dat" )
491+ shutil .copyfile (wallet_dat_path , os .path .join (wallets_dir , "plainfile.bak" ))
492+ shutil .rmtree (wallet_path )
493+ shutil .move (os .path .join (wallets_dir , "plainfile.bak" ), wallet_path )
494+
495+ self .nodes [0 ].loadwallet ("plainfile" )
496+ info = wallet .getwalletinfo ()
497+ assert_equal (info ["descriptors" ], False )
498+ assert_equal (info ["format" ], "bdb" )
499+
500+ wallet .migratewallet ()
501+ info = wallet .getwalletinfo ()
502+ assert_equal (info ["descriptors" ], True )
503+ assert_equal (info ["format" ], "sqlite" )
504+
505+ assert os .path .isdir (wallet_path )
506+ assert os .path .isfile (wallet_dat_path )
507+
473508 def run_test (self ):
474509 self .generate (self .nodes [0 ], 101 )
475510
@@ -482,6 +517,8 @@ def run_test(self):
482517 self .test_encrypted ()
483518 self .test_unloaded ()
484519 self .test_unloaded_by_path ()
520+ self .test_default_wallet ()
521+ self .test_direct_file ()
485522
486523if __name__ == '__main__' :
487524 WalletMigrationTest ().main ()
0 commit comments