Repository: bitcoin/bitcoin
File: test/functional/wallet_migration.py (Python)

Code before:
        info = wallet.getwalletinfo()
        assert_equal(info["descriptors"], False)
        assert_equal(info["format"], "bdb")

    def test_wallet_with_path(self, wallet_path):
        self.log.info("Test migrating a wallet with the following path/name: %s", wallet_path)
        # the wallet data is actually inside of path/that/ends/
        wallet = self.create_legacy_wallet(wallet_path)
        default = self.master_node.get_wallet_rpc(self.default_wallet_name)

        addr = wallet.getnewaddress()
        txid = default.sendtoaddress(addr, 1)
        self.generate(self.master_node, 1)
        bals = wallet.getbalances()

        _, wallet = self.migrate_and_get_rpc(wallet_path)

        assert wallet.gettransaction(txid)

        assert_equal(bals, wallet.getbalances())

    def clear_default_wallet(self, backup_file):
        # Test cleanup: Clear unnamed default wallet for subsequent tests
        (self.old_node.wallets_path / "wallet.dat").unlink()
        (self.master_node.wallets_path / "wallet.dat").unlink(missing_ok=True)
        shutil.rmtree(self.master_node.wallets_path / "default_wallet_watchonly", ignore_errors=True)
        backup_file.unlink()

    def test_default_wallet(self):
        self.log.info("Test migration of the wallet named as the empty string")
        wallet = self.create_legacy_wallet("")

        res, wallet = self.migrate_and_get_rpc("")
        info = wallet.getwalletinfo()
        assert_equal(info["descriptors"], True)
        assert_equal(info["format"], "sqlite")

        walletdir_list = wallet.listwalletdir()
        assert {"name": info["walletname"]} in [{"name": w["name"]} for w in walletdir_list["wallets"]]

        # Make sure the backup uses a non-empty filename
        # migrate_and_get_rpc already checks for backup file existence
        assert os.path.basename(res["backup_path"]).startswith("default_wallet")

        wallet.unloadwallet()
        self.clear_default_wallet(backup_file=Path(res["backup_path"]))

    def test_default_wallet_watch_only(self):
        self.log.info("Test unnamed (default) watch-only wallet migration")
        master_wallet = self.master_node.get_wallet_rpc(self.default_wallet_name)
        wallet = self.create_legacy_wallet("", blank=True)

Review comment (suggestion):
In 1ee2186d6e1f2a38cae3eae16a0565924fe8c309 "wallet: migration, fix watch-only and solvables wallets names"

For completeness, also do `default_wallet_solvables`.

Code after:
        info = wallet.getwalletinfo()
        assert_equal(info["descriptors"], False)
        assert_equal(info["format"], "bdb")

    def test_wallet_with_path(self, wallet_path):
        self.log.info("Test migrating a wallet with the following path/name: %s", wallet_path)
        # the wallet data is actually inside of path/that/ends/
        wallet = self.create_legacy_wallet(wallet_path)
        default = self.master_node.get_wallet_rpc(self.default_wallet_name)

        addr = wallet.getnewaddress()
        txid = default.sendtoaddress(addr, 1)
        self.generate(self.master_node, 1)
        bals = wallet.getbalances()

        _, wallet = self.migrate_and_get_rpc(wallet_path)

        assert wallet.gettransaction(txid)

        assert_equal(bals, wallet.getbalances())

    def clear_default_wallet(self, backup_file):
        # Test cleanup: Clear unnamed default wallet for subsequent tests
        (self.old_node.wallets_path / "wallet.dat").unlink()
        (self.master_node.wallets_path / "wallet.dat").unlink(missing_ok=True)
        shutil.rmtree(self.master_node.wallets_path / "default_wallet_watchonly", ignore_errors=True)
        shutil.rmtree(self.master_node.wallets_path / "default_wallet_solvables", ignore_errors=True)
        backup_file.unlink()

    def test_default_wallet(self):
        self.log.info("Test migration of the wallet named as the empty string")
        wallet = self.create_legacy_wallet("")

        res, wallet = self.migrate_and_get_rpc("")
        info = wallet.getwalletinfo()
        assert_equal(info["descriptors"], True)
        assert_equal(info["format"], "sqlite")

        walletdir_list = wallet.listwalletdir()
        assert {"name": info["walletname"]} in [{"name": w["name"]} for w in walletdir_list["wallets"]]

        # Make sure the backup uses a non-empty filename
        # migrate_and_get_rpc already checks for backup file existence
        assert os.path.basename(res["backup_path"]).startswith("default_wallet")

        wallet.unloadwallet()
        self.clear_default_wallet(backup_file=Path(res["backup_path"]))

    def test_default_wallet_watch_only(self):
        self.log.info("Test unnamed (default) watch-only wallet migration")
        master_wallet = self.master_node.get_wallet_rpc(self.default_wallet_name)