Skip to content

Commit bfc9d95

Browse files
committed
Merge bitcoin/bitcoin#33104: test: Perform backup filename checks in migrate_and_get_rpc in wallet_migration.py
4b80147 test: Perform backup filename checks in migrate_and_get_rpc (Ava Chow) Pull request description: Some test cases were unnecessarily checking the backup filename, which involved setting the mocktime before `migrate_and_get_rpc`. However, this could cause a failure if the test was slow since `migrate_and_get_rpc` also sets the mocktime. Since it also already checks that the backup file is named correctly, there's no need for those tests to also do their own mocktime and filename check. The CI failure can be reproduced locally by adding a sleep to `migrate_and_get_rpc`: ```diff diff --git a/test/functional/wallet_migration.py b/test/functional/wallet_migration.py index 7042044..e87a6100623 100755 --- a/test/functional/wallet_migration.py +++ b/test/functional/wallet_migration.py @@ -129,6 +129,7 @@ class WalletMigrationTest(BitcoinTestFramework): assert_equal(w["warnings"], ["This wallet is a legacy wallet and will need to be migrated with migratewallet before it can be loaded"]) # Mock time so that we can check the backup filename. + time.sleep(1) mocked_time = int(time.time()) self.master_node.setmocktime(mocked_time) # Migrate, checking that rescan does not occur ``` Fixes #33096 ACKs for top commit: fjahr: reACK 4b80147 Sammie05: tACK 4b80147 pablomartin4btc: utACK 4b80147 rkrux: ACK 4b80147 Tree-SHA512: 045d4acf2ad0b56a7083ff2ee5ef09f0d74ad097c01a290660daca096c71fc07109848024256d84f74abbc87dd52691d160f9968b3654726626d3dbd21a84ab6
2 parents 8712e07 + 4b80147 commit bfc9d95

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

test/functional/wallet_migration.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)