Skip to content

Commit 71cb28e

Browse files
committed
test: Make sure that migration test does not rescan on reloading
We want to make sure that all of the transactions are being copied to the watchonly and solvable wallets as expected. The automatic rescanning behavior can cause us to pass a test by finding the transaction on loading rather than having it be copied as expected.
1 parent 78ba0e6 commit 71cb28e

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

test/functional/wallet_migration.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ def create_legacy_wallet(self, wallet_name, **kwargs):
6060
assert_equal(info["format"], "bdb")
6161
return wallet
6262

63+
def migrate_wallet(self, wallet_rpc, *args, **kwargs):
64+
# Helper to ensure that only migration happens
65+
# Since we may rescan on loading of a wallet, make sure that the best block
66+
# is written before beginning migration
67+
# Reload to force write that record
68+
wallet_name = wallet_rpc.getwalletinfo()["walletname"]
69+
wallet_rpc.unloadwallet()
70+
self.nodes[0].loadwallet(wallet_name)
71+
# Migrate, checking that rescan does not occur
72+
with self.nodes[0].assert_debug_log(expected_msgs=[], unexpected_msgs=["Rescanning"]):
73+
return wallet_rpc.migratewallet(*args, **kwargs)
74+
6375
def assert_addr_info_equal(self, addr_info, addr_info_old):
6476
assert_equal(addr_info["address"], addr_info_old["address"])
6577
assert_equal(addr_info["scriptPubKey"], addr_info_old["scriptPubKey"])
@@ -104,7 +116,7 @@ def test_basic(self):
104116
assert_equal(old_change_addr_info["hdkeypath"], "m/0'/1'/0'")
105117

106118
# Note: migration could take a while.
107-
basic0.migratewallet()
119+
self.migrate_wallet(basic0)
108120

109121
# Verify created descriptors
110122
assert_equal(basic0.getwalletinfo()["descriptors"], True)
@@ -145,7 +157,7 @@ def test_basic(self):
145157
txs = basic1.listtransactions()
146158
addr_gps = basic1.listaddressgroupings()
147159

148-
basic1_migrate = basic1.migratewallet()
160+
basic1_migrate = self.migrate_wallet(basic1)
149161
assert_equal(basic1.getwalletinfo()["descriptors"], True)
150162
self.assert_is_sqlite("basic1")
151163
assert_equal(basic1.getbalance(), bal)
@@ -186,7 +198,7 @@ def test_basic(self):
186198
basic2_txs = basic2.listtransactions()
187199

188200
# Now migrate and test that we still see have the same balance/transactions
189-
basic2.migratewallet()
201+
self.migrate_wallet(basic2)
190202
assert_equal(basic2.getwalletinfo()["descriptors"], True)
191203
self.assert_is_sqlite("basic2")
192204
assert_equal(basic2.getbalance(), basic2_balance)
@@ -208,7 +220,7 @@ def test_multisig(self):
208220

209221
ms_info = multisig0.addmultisigaddress(2, [addr1, addr2, addr3])
210222

211-
multisig0.migratewallet()
223+
self.migrate_wallet(multisig0)
212224
assert_equal(multisig0.getwalletinfo()["descriptors"], True)
213225
self.assert_is_sqlite("multisig0")
214226
ms_addr_info = multisig0.getaddressinfo(ms_info["address"])
@@ -243,7 +255,7 @@ def test_multisig(self):
243255
# Migrating multisig1 should see the multisig is no longer part of multisig1
244256
# A new wallet multisig1_watchonly is created which has the multisig address
245257
# Transaction to multisig is in multisig1_watchonly and not multisig1
246-
multisig1.migratewallet()
258+
self.migrate_wallet(multisig1)
247259
assert_equal(multisig1.getwalletinfo()["descriptors"], True)
248260
self.assert_is_sqlite("multisig1")
249261
assert_equal(multisig1.getaddressinfo(addr1)["ismine"], False)
@@ -326,7 +338,7 @@ def test_other_watchonly(self):
326338
self.nodes[0].setmocktime(int(time.time()) + 100)
327339

328340
# Migrate
329-
imports0.migratewallet()
341+
self.migrate_wallet(imports0)
330342
assert_equal(imports0.getwalletinfo()["descriptors"], True)
331343
self.assert_is_sqlite("imports0")
332344
assert_raises_rpc_error(-5, "Invalid or non-wallet transaction id", imports0.gettransaction, received_watchonly_txid)
@@ -379,7 +391,7 @@ def test_no_privkeys(self):
379391
default.sendtoaddress(addr, 10)
380392
self.generate(self.nodes[0], 1)
381393

382-
watchonly0.migratewallet()
394+
self.migrate_wallet(watchonly0)
383395
assert_equal("watchonly0_watchonly" in self.nodes[0].listwallets(), False)
384396
info = watchonly0.getwalletinfo()
385397
assert_equal(info["descriptors"], True)
@@ -411,7 +423,7 @@ def test_no_privkeys(self):
411423
# Before migrating, we can fetch addr1 from the keypool
412424
assert_equal(watchonly1.getnewaddress(address_type="bech32"), addr1)
413425

414-
watchonly1.migratewallet()
426+
self.migrate_wallet(watchonly1)
415427
info = watchonly1.getwalletinfo()
416428
assert_equal(info["descriptors"], True)
417429
assert_equal(info["private_keys_enabled"], False)
@@ -431,7 +443,7 @@ def test_pk_coinbases(self):
431443

432444
bals = wallet.getbalances()
433445

434-
wallet.migratewallet()
446+
self.migrate_wallet(wallet)
435447

436448
assert_equal(bals, wallet.getbalances())
437449

@@ -450,7 +462,7 @@ def test_encrypted(self):
450462
assert_raises_rpc_error(-4, "Error: Wallet decryption failed, the wallet passphrase was not provided or was incorrect", wallet.migratewallet, None, "badpass")
451463
assert_raises_rpc_error(-4, "The passphrase contains a null character", wallet.migratewallet, None, "pass\0with\0null")
452464

453-
wallet.migratewallet(passphrase="pass")
465+
self.migrate_wallet(wallet, passphrase="pass")
454466

455467
info = wallet.getwalletinfo()
456468
assert_equal(info["descriptors"], True)
@@ -512,7 +524,7 @@ def test_default_wallet(self):
512524
self.log.info("Test migration of the wallet named as the empty string")
513525
wallet = self.create_legacy_wallet("")
514526

515-
wallet.migratewallet()
527+
self.migrate_wallet(wallet)
516528
info = wallet.getwalletinfo()
517529
assert_equal(info["descriptors"], True)
518530
assert_equal(info["format"], "sqlite")
@@ -534,7 +546,7 @@ def test_direct_file(self):
534546
assert_equal(info["descriptors"], False)
535547
assert_equal(info["format"], "bdb")
536548

537-
wallet.migratewallet()
549+
self.migrate_wallet(wallet)
538550
info = wallet.getwalletinfo()
539551
assert_equal(info["descriptors"], True)
540552
assert_equal(info["format"], "sqlite")
@@ -622,7 +634,7 @@ def check(info, node):
622634
check(addr_info, wallet)
623635

624636
# Migrate wallet
625-
info_migration = wallet.migratewallet()
637+
info_migration = self.migrate_wallet(wallet)
626638
wallet_wo = self.nodes[0].get_wallet_rpc(info_migration["watchonly_name"])
627639
wallet_solvables = self.nodes[0].get_wallet_rpc(info_migration["solvables_name"])
628640

@@ -717,7 +729,7 @@ def send_to_script(script, amount):
717729
wallet.rpc.importaddress(address=script_sh_pkh.hex(), label=label_sh_pkh, rescan=False, p2sh=True)
718730

719731
# Migrate wallet and re-check balance
720-
info_migration = wallet.migratewallet()
732+
info_migration = self.migrate_wallet(wallet)
721733
wallet_wo = self.nodes[0].get_wallet_rpc(info_migration["watchonly_name"])
722734

723735
# Watch-only balance is under "mine".
@@ -780,7 +792,7 @@ def test_conflict_txs(self):
780792
assert_equal(wallet.gettransaction(txid=child_txid)["confirmations"], -1)
781793
assert_equal(wallet.gettransaction(txid=conflict_txid)["confirmations"], 1)
782794

783-
wallet.migratewallet()
795+
self.migrate_wallet(wallet)
784796
assert_equal(wallet.gettransaction(txid=parent_txid)["confirmations"], -1)
785797
assert_equal(wallet.gettransaction(txid=child_txid)["confirmations"], -1)
786798
assert_equal(wallet.gettransaction(txid=conflict_txid)["confirmations"], 1)
@@ -813,7 +825,7 @@ def test_hybrid_pubkey(self):
813825
p2wpkh_addr = key_to_p2wpkh(hybrid_pubkey)
814826
wallet.importaddress(p2wpkh_addr)
815827

816-
migrate_info = wallet.migratewallet()
828+
migrate_info = self.migrate_wallet(wallet)
817829

818830
# Both addresses should only appear in the watchonly wallet
819831
p2pkh_addr_info = wallet.getaddressinfo(p2pkh_addr)

0 commit comments

Comments
 (0)