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

Code before:
        # Test vectors
        addr_external = {
            "addr": df_wallet.getnewaddress(),
            "is_mine": False,
            "is_change": False,
            "label": ""
        }
        addr_external_with_label = {
            "addr": df_wallet.getnewaddress(),
            "is_mine": False,
            "is_change": False,
            "label": "external"
        }
        addr_internal = {
            "addr": wallet.getnewaddress(),
            "is_mine": True,
            "is_change": False,
            "label": ""
        }
        addr_internal_with_label = {
            "addr": wallet.getnewaddress(),
            "is_mine": True,
            "is_change": False,
            "label": "internal"
        }
        change_address = {
            "addr": wallet.getrawchangeaddress(),
            "is_mine": True,
            "is_change": True,
            "label": None
        }
        watch_only_addr = {
            "addr": watch_addr,
            "is_mine": False,
            "is_change": False,
            "label": "imported"
        }
        ms_addr = {
            "addr": ms_addr_info['address'],
            "is_mine": False,
            "is_change": False,
            "label": "multisig"
        }

        # To store the change address in the addressbook need to send coins to it
        wallet.send(outputs=[{wallet.getnewaddress(): 2}], options={"change_address": change_address['addr']})
        self.generate(self.master_node, 1)

        # Util wrapper func for 'addr_info'
        def check(info, node):
            self.check_address(node, info['addr'], info['is_mine'], info['is_change'], info["label"])

Review comment (bug):
In commit "test: Migration of a wallet ending in `../`" (76fe0e59ec4a5b0c5b18f46bfcbbf99628d74d77)

There's a minor typo in the commit message. `../` should just be `..` since the path doesn't end in a slash.

Also this commit seems very similar to previous commit. Could be nice to combine these into a single function like:

```py
self.test_wallet_with_path("path/to/mywallet/")
self.test_wallet_with_path("path/that/ends/in/..")
```

With a `fail_migration: bool` option, this could be extended to dedup `test_wallet_with_relative_path` and `test_failed_migration_cleanup_relative_path` cases as well.

Seem ok to have duplicate test code for now though.



Code after:
        assert_equal(info["descriptors"], False)
        assert_equal(info["format"], "bdb")

    def test_wallet_with_path_ending_in_slash(self):
        self.log.info("Test migrating a wallet with a name/path ending in '/'")

        # The last directory in the wallet's path
        final_dir = "mywallet"
        wallet_name = f"path/to/{final_dir}/"
        wallet = self.create_legacy_wallet(wallet_name)
        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_name)

        assert wallet.gettransaction(txid)

        assert_equal(bals, wallet.getbalances())

    def test_wallet_with_path_ending_in_relative_specifier(self):
        self.log.info("Test migrating a wallet with a name/path ending in a relative specifier, '..'")
        wallet_ending_in_relative = "path/that/ends/in/.."
        # the wallet data is actually inside of path/that/ends/
        wallet = self.create_legacy_wallet(wallet_ending_in_relative)
        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_ending_in_relative)

        assert wallet.gettransaction(txid)

        assert_equal(bals, wallet.getbalances())

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

        # Set time to verify backup existence later
        curr_time = int(time.time())
        self.master_node.setmocktime(curr_time)

        res, wallet = self.migrate_and_get_rpc("")
        self.master_node.setmocktime(0)