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

Code before:
        with self.node.assert_debug_log(['Using /16 prefix for IP bucketing']):
            self.start_node(0, ["-noasmap"])

    def test_asmap_with_absolute_path(self):
        self.log.info('Test bitcoind -asmap=<absolute path>')
        self.stop_node(0)
        filename = os.path.join(self.datadir, 'my-map-file.map')
        shutil.copyfile(self.asmap_raw, filename)
        with self.node.assert_debug_log(expected_messages(filename)):
            self.start_node(0, [f'-asmap={filename}'])
        os.remove(filename)

    def test_asmap_with_relative_path(self):
        self.log.info('Test bitcoind -asmap=<relative path>')
        self.stop_node(0)
        name = 'ASN_map'
        filename = os.path.join(self.datadir, name)
        shutil.copyfile(self.asmap_raw, filename)
        with self.node.assert_debug_log(expected_messages(filename)):
            self.start_node(0, [f'-asmap={name}'])
        os.remove(filename)

    def test_default_asmap(self):
        msg = f"Error: Could not find asmap file \"{self.datadir}{os.sep}\""
        for arg in ['-asmap', '-asmap=']:
            self.log.info(f'Test bitcoind {arg} (using default map file)')
            self.stop_node(0)
            self.node.assert_start_raises_init_error(extra_args=[arg], expected_msg=msg)

    def test_asmap_interaction_with_addrman_containing_entries(self):
        self.log.info("Test bitcoind -asmap restart with addrman containing new and tried entries")
        self.stop_node(0)
        self.start_node(0, [f"-asmap={self.asmap_raw}", "-checkaddrman=1", "-test=addrman"])
        self.fill_addrman(node_id=0)
        self.restart_node(0, [f"-asmap={self.asmap_raw}", "-checkaddrman=1", "-test=addrman"])
        with self.node.assert_debug_log(
            expected_msgs=[
                "CheckAddrman: new 2, tried 2, total 4 started",
                "CheckAddrman: completed",
            ]
        ):
            self.node.getnodeaddresses()  # getnodeaddresses re-runs the addrman checks

    def test_default_asmap_with_missing_file(self):
        self.log.info('Test bitcoind -asmap with missing default map file')
        self.stop_node(0)
        msg = f"Error: Could not find asmap file \"{self.datadir}{os.sep}missing\""
        self.node.assert_start_raises_init_error(extra_args=['-asmap=missing'], expected_msg=msg)

    def test_empty_asmap(self):
        self.log.info('Test bitcoind -asmap with empty map file')

Review comment (suggestion):
nit:
```suggestion
            self.log.info(f'Test bitcoind {arg} (using a map file)')
```

Code after:
    def test_asmap_with_relative_path(self):
        self.log.info('Test bitcoind -asmap=<relative path>')
        self.stop_node(0)
        name = 'ASN_map'
        filename = os.path.join(self.datadir, name)
        shutil.copyfile(self.asmap_raw, filename)
        with self.node.assert_debug_log(expected_messages(filename)):
            self.start_node(0, [f'-asmap={name}'])
        os.remove(filename)

    def test_unspecified_asmap(self):
        msg = "Error: -asmap requires a file path. Use -asmap=<file>."
        for arg in ['-asmap', '-asmap=']:
            self.log.info(f'Test bitcoind {arg} (and no filename specified)')
            self.stop_node(0)
            self.node.assert_start_raises_init_error(extra_args=[arg], expected_msg=msg)

    def test_asmap_interaction_with_addrman_containing_entries(self):
        self.log.info("Test bitcoind -asmap restart with addrman containing new and tried entries")
        self.stop_node(0)
        self.start_node(0, [f"-asmap={self.asmap_raw}", "-checkaddrman=1", "-test=addrman"])
        self.fill_addrman(node_id=0)
        self.restart_node(0, [f"-asmap={self.asmap_raw}", "-checkaddrman=1", "-test=addrman"])
        with self.node.assert_debug_log(
            expected_msgs=[
                "CheckAddrman: new 2, tried 2, total 4 started",
                "CheckAddrman: completed",
            ]
        ):
            self.node.getnodeaddresses()  # getnodeaddresses re-runs the addrman checks

    def test_asmap_with_missing_file(self):
        self.log.info('Test bitcoind -asmap with missing map file')
        self.stop_node(0)
        msg = f"Error: Could not find asmap file \"{self.datadir}{os.sep}missing\""
        self.node.assert_start_raises_init_error(extra_args=['-asmap=missing'], expected_msg=msg)

    def test_empty_asmap(self):
        self.log.info('Test bitcoind -asmap with empty map file')
        self.stop_node(0)
        empty_asmap = os.path.join(self.datadir, "ip_asn.map")
        with open(empty_asmap, "w", encoding="utf-8") as f:
            f.write("")
        msg = f"Error: Could not parse asmap file \"{empty_asmap}\""
        self.node.assert_start_raises_init_error(extra_args=[f'-asmap={empty_asmap}'], expected_msg=msg)
        os.remove(empty_asmap)

    def test_asmap_health_check(self):
        self.log.info('Test bitcoind -asmap logs ASMap Health Check with basic stats')
        msg = "ASMap Health Check: 4 clearnet peers are mapped to 3 ASNs with 0 peers being unmapped"
        with self.node.assert_debug_log(expected_msgs=[msg]):