@@ -60,6 +60,18 @@ def create_legacy_wallet(self, wallet_name, **kwargs):
60
60
assert_equal (info ["format" ], "bdb" )
61
61
return wallet
62
62
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
+
63
75
def assert_addr_info_equal (self , addr_info , addr_info_old ):
64
76
assert_equal (addr_info ["address" ], addr_info_old ["address" ])
65
77
assert_equal (addr_info ["scriptPubKey" ], addr_info_old ["scriptPubKey" ])
@@ -104,7 +116,7 @@ def test_basic(self):
104
116
assert_equal (old_change_addr_info ["hdkeypath" ], "m/0'/1'/0'" )
105
117
106
118
# Note: migration could take a while.
107
- basic0 . migratewallet ( )
119
+ self . migrate_wallet ( basic0 )
108
120
109
121
# Verify created descriptors
110
122
assert_equal (basic0 .getwalletinfo ()["descriptors" ], True )
@@ -145,7 +157,7 @@ def test_basic(self):
145
157
txs = basic1 .listtransactions ()
146
158
addr_gps = basic1 .listaddressgroupings ()
147
159
148
- basic1_migrate = basic1 . migratewallet ( )
160
+ basic1_migrate = self . migrate_wallet ( basic1 )
149
161
assert_equal (basic1 .getwalletinfo ()["descriptors" ], True )
150
162
self .assert_is_sqlite ("basic1" )
151
163
assert_equal (basic1 .getbalance (), bal )
@@ -186,7 +198,7 @@ def test_basic(self):
186
198
basic2_txs = basic2 .listtransactions ()
187
199
188
200
# Now migrate and test that we still see have the same balance/transactions
189
- basic2 . migratewallet ( )
201
+ self . migrate_wallet ( basic2 )
190
202
assert_equal (basic2 .getwalletinfo ()["descriptors" ], True )
191
203
self .assert_is_sqlite ("basic2" )
192
204
assert_equal (basic2 .getbalance (), basic2_balance )
@@ -208,7 +220,7 @@ def test_multisig(self):
208
220
209
221
ms_info = multisig0 .addmultisigaddress (2 , [addr1 , addr2 , addr3 ])
210
222
211
- multisig0 . migratewallet ( )
223
+ self . migrate_wallet ( multisig0 )
212
224
assert_equal (multisig0 .getwalletinfo ()["descriptors" ], True )
213
225
self .assert_is_sqlite ("multisig0" )
214
226
ms_addr_info = multisig0 .getaddressinfo (ms_info ["address" ])
@@ -243,7 +255,7 @@ def test_multisig(self):
243
255
# Migrating multisig1 should see the multisig is no longer part of multisig1
244
256
# A new wallet multisig1_watchonly is created which has the multisig address
245
257
# Transaction to multisig is in multisig1_watchonly and not multisig1
246
- multisig1 . migratewallet ( )
258
+ self . migrate_wallet ( multisig1 )
247
259
assert_equal (multisig1 .getwalletinfo ()["descriptors" ], True )
248
260
self .assert_is_sqlite ("multisig1" )
249
261
assert_equal (multisig1 .getaddressinfo (addr1 )["ismine" ], False )
@@ -326,7 +338,7 @@ def test_other_watchonly(self):
326
338
self .nodes [0 ].setmocktime (int (time .time ()) + 100 )
327
339
328
340
# Migrate
329
- imports0 . migratewallet ( )
341
+ self . migrate_wallet ( imports0 )
330
342
assert_equal (imports0 .getwalletinfo ()["descriptors" ], True )
331
343
self .assert_is_sqlite ("imports0" )
332
344
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):
379
391
default .sendtoaddress (addr , 10 )
380
392
self .generate (self .nodes [0 ], 1 )
381
393
382
- watchonly0 . migratewallet ( )
394
+ self . migrate_wallet ( watchonly0 )
383
395
assert_equal ("watchonly0_watchonly" in self .nodes [0 ].listwallets (), False )
384
396
info = watchonly0 .getwalletinfo ()
385
397
assert_equal (info ["descriptors" ], True )
@@ -411,7 +423,7 @@ def test_no_privkeys(self):
411
423
# Before migrating, we can fetch addr1 from the keypool
412
424
assert_equal (watchonly1 .getnewaddress (address_type = "bech32" ), addr1 )
413
425
414
- watchonly1 . migratewallet ( )
426
+ self . migrate_wallet ( watchonly1 )
415
427
info = watchonly1 .getwalletinfo ()
416
428
assert_equal (info ["descriptors" ], True )
417
429
assert_equal (info ["private_keys_enabled" ], False )
@@ -431,7 +443,7 @@ def test_pk_coinbases(self):
431
443
432
444
bals = wallet .getbalances ()
433
445
434
- wallet . migratewallet ( )
446
+ self . migrate_wallet ( wallet )
435
447
436
448
assert_equal (bals , wallet .getbalances ())
437
449
@@ -450,7 +462,7 @@ def test_encrypted(self):
450
462
assert_raises_rpc_error (- 4 , "Error: Wallet decryption failed, the wallet passphrase was not provided or was incorrect" , wallet .migratewallet , None , "badpass" )
451
463
assert_raises_rpc_error (- 4 , "The passphrase contains a null character" , wallet .migratewallet , None , "pass\0 with\0 null" )
452
464
453
- wallet . migratewallet ( passphrase = "pass" )
465
+ self . migrate_wallet ( wallet , passphrase = "pass" )
454
466
455
467
info = wallet .getwalletinfo ()
456
468
assert_equal (info ["descriptors" ], True )
@@ -512,7 +524,7 @@ def test_default_wallet(self):
512
524
self .log .info ("Test migration of the wallet named as the empty string" )
513
525
wallet = self .create_legacy_wallet ("" )
514
526
515
- wallet . migratewallet ( )
527
+ self . migrate_wallet ( wallet )
516
528
info = wallet .getwalletinfo ()
517
529
assert_equal (info ["descriptors" ], True )
518
530
assert_equal (info ["format" ], "sqlite" )
@@ -534,7 +546,7 @@ def test_direct_file(self):
534
546
assert_equal (info ["descriptors" ], False )
535
547
assert_equal (info ["format" ], "bdb" )
536
548
537
- wallet . migratewallet ( )
549
+ self . migrate_wallet ( wallet )
538
550
info = wallet .getwalletinfo ()
539
551
assert_equal (info ["descriptors" ], True )
540
552
assert_equal (info ["format" ], "sqlite" )
@@ -622,7 +634,7 @@ def check(info, node):
622
634
check (addr_info , wallet )
623
635
624
636
# Migrate wallet
625
- info_migration = wallet . migratewallet ( )
637
+ info_migration = self . migrate_wallet ( wallet )
626
638
wallet_wo = self .nodes [0 ].get_wallet_rpc (info_migration ["watchonly_name" ])
627
639
wallet_solvables = self .nodes [0 ].get_wallet_rpc (info_migration ["solvables_name" ])
628
640
@@ -717,7 +729,7 @@ def send_to_script(script, amount):
717
729
wallet .rpc .importaddress (address = script_sh_pkh .hex (), label = label_sh_pkh , rescan = False , p2sh = True )
718
730
719
731
# Migrate wallet and re-check balance
720
- info_migration = wallet . migratewallet ( )
732
+ info_migration = self . migrate_wallet ( wallet )
721
733
wallet_wo = self .nodes [0 ].get_wallet_rpc (info_migration ["watchonly_name" ])
722
734
723
735
# Watch-only balance is under "mine".
@@ -780,7 +792,7 @@ def test_conflict_txs(self):
780
792
assert_equal (wallet .gettransaction (txid = child_txid )["confirmations" ], - 1 )
781
793
assert_equal (wallet .gettransaction (txid = conflict_txid )["confirmations" ], 1 )
782
794
783
- wallet . migratewallet ( )
795
+ self . migrate_wallet ( wallet )
784
796
assert_equal (wallet .gettransaction (txid = parent_txid )["confirmations" ], - 1 )
785
797
assert_equal (wallet .gettransaction (txid = child_txid )["confirmations" ], - 1 )
786
798
assert_equal (wallet .gettransaction (txid = conflict_txid )["confirmations" ], 1 )
@@ -813,7 +825,7 @@ def test_hybrid_pubkey(self):
813
825
p2wpkh_addr = key_to_p2wpkh (hybrid_pubkey )
814
826
wallet .importaddress (p2wpkh_addr )
815
827
816
- migrate_info = wallet . migratewallet ( )
828
+ migrate_info = self . migrate_wallet ( wallet )
817
829
818
830
# Both addresses should only appear in the watchonly wallet
819
831
p2pkh_addr_info = wallet .getaddressinfo (p2pkh_addr )
0 commit comments