Merge bitcoin/bitcoin#32149: wallet, migration: Fix empty wallet crash

0f602c5693 wallet, migration: Fix crash on empty wallet (pablomartin4btc)
42c13141b5 wallet, refactor: Decouple into HasLegacyRecords() (pablomartin4btc)

Pull request description:

  Same as with a blank wallet (#28976), wallets with no legacy records (i.e. empty, non-blank, watch-only wallet) do not require to be migrated.

  Steps to reproduce the issue:

  1.- `createwallet "empty_wo_noblank_legacy_wallet" true false "" false false`
  2.- `migratewallet`

  ```
  wallet/wallet.cpp:4071 GetDescriptorsForLegacy: Assertion `legacy_spkm' failed.
  Aborted (core dumped)
  ```

ACKs for top commit:
  davidgumberg:
    untested reACK 0f602c5693
  fjahr:
    re-ACK 0f602c5693
  achow101:
    ACK 0f602c5693
  furszy:
    ACK 0f602c5693
  BrandonOdiwuor:
    Code Review ACK 0f602c5693

Tree-SHA512: 796c3f0b1946281097f7ffc3563bc79f879e80a98237012535cc530a4a2239fd2d71a17b4f54e30258886dc9f0b83206d7a5d50312e4fc6d0abe4f559fbe07ec
This commit is contained in:
Ava Chow
2025-04-09 17:50:48 -07:00
5 changed files with 51 additions and 20 deletions

View File

@@ -445,6 +445,15 @@ class WalletMigrationTest(BitcoinTestFramework):
# After migrating, the "keypool" is empty
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", watchonly1.getnewaddress)
self.log.info("Test migration of a watch-only empty wallet")
for idx, is_blank in enumerate([True, False], start=1):
wallet_name = f"watchonly_empty{idx}"
self.create_legacy_wallet(wallet_name, disable_private_keys=True, blank=is_blank)
_, watchonly_empty = self.migrate_and_get_rpc(wallet_name)
info = watchonly_empty.getwalletinfo()
assert_equal(info["private_keys_enabled"], False)
assert_equal(info["blank"], is_blank)
def test_pk_coinbases(self):
self.log.info("Test migration of a wallet using old pk() coinbases")
wallet = self.create_legacy_wallet("pkcb")