@@ -128,7 +128,8 @@ def migrate_and_get_rpc(self, wallet_name, **kwargs):
128128 if w ["name" ] == wallet_name :
129129 assert_equal (w ["warnings" ], ["This wallet is a legacy wallet and will need to be migrated with migratewallet before it can be loaded" ])
130130
131- # Mock time so that we can check the backup filename.
131+ # migratewallet uses current time in naming the backup file, set a mock time
132+ # to check that this works correctly.
132133 mocked_time = int (time .time ())
133134 self .master_node .setmocktime (mocked_time )
134135 # Migrate, checking that rescan does not occur
@@ -148,8 +149,10 @@ def migrate_and_get_rpc(self, wallet_name, **kwargs):
148149 else :
149150 backup_prefix = os .path .basename (os .path .realpath (self .old_node .wallets_path / wallet_name ))
150151
151- expected_backup_path = self .master_node .wallets_path / f"{ backup_prefix } _{ mocked_time } .legacy.bak"
152+ backup_filename = f"{ backup_prefix } _{ mocked_time } .legacy.bak"
153+ expected_backup_path = self .master_node .wallets_path / backup_filename
152154 assert_equal (str (expected_backup_path ), migrate_info ['backup_path' ])
155+ assert {"name" : backup_filename } not in self .master_node .listwalletdir ()["wallets" ]
153156
154157 return migrate_info , wallet
155158
@@ -593,12 +596,7 @@ def test_wallet_with_relative_path(self):
593596 self .generate (self .master_node , 1 )
594597 bals = wallet .getbalances ()
595598
596- # migratewallet uses current time in naming the backup file, set a mock time
597- # to check that this works correctly.
598- curr_time = int (time .time ())
599- self .master_node .setmocktime (curr_time )
600599 migrate_res , wallet = self .migrate_and_get_rpc (relative_name )
601- self .master_node .setmocktime (0 )
602600
603601 # Check that the wallet was migrated, knows the right txid, and has the right balance.
604602 assert wallet .gettransaction (txid )
@@ -665,27 +663,17 @@ def test_default_wallet(self):
665663 self .log .info ("Test migration of the wallet named as the empty string" )
666664 wallet = self .create_legacy_wallet ("" )
667665
668- # Set time to verify backup existence later
669- curr_time = int (time .time ())
670- self .master_node .setmocktime (curr_time )
671-
672666 res , wallet = self .migrate_and_get_rpc ("" )
673- self .master_node .setmocktime (0 )
674667 info = wallet .getwalletinfo ()
675668 assert_equal (info ["descriptors" ], True )
676669 assert_equal (info ["format" ], "sqlite" )
677670
678671 walletdir_list = wallet .listwalletdir ()
679672 assert {"name" : info ["walletname" ]} in [{"name" : w ["name" ]} for w in walletdir_list ["wallets" ]]
680673
681- # Check backup existence and its non-empty wallet filename
682- backup_filename = f"default_wallet_{ curr_time } .legacy.bak"
683- backup_path = self .master_node .wallets_path / backup_filename
684- assert backup_path .exists ()
685- assert_equal (str (backup_path ), res ['backup_path' ])
686- assert {"name" : backup_filename } not in walletdir_list ["wallets" ]
687-
688- self .master_node .setmocktime (0 )
674+ # Make sure the backup uses a non-empty filename
675+ # migrate_and_get_rpc already checks for backup file existence
676+ assert os .path .basename (res ["backup_path" ]).startswith ("default_wallet" )
689677
690678 def test_direct_file (self ):
691679 self .log .info ("Test migration of a wallet that is not in a wallet directory" )
0 commit comments