From 987a614c0d80b6d073844a93f900c5b391f7d9c9 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Tue, 26 Nov 2024 15:14:41 +0100 Subject: [PATCH] test: avoid generating non-loopback traffic from p2p_dns_seeds.py `p2p_dns_seeds.py` would try to connect to the DNS server configured on the machine and resolve `dummySeed.invalid`. To block that configure an unavailable proxy which will be used also to connect to the name server. The test needs 2 successful connections to other peers (two Python `P2PInterface`s) and they work in spite of the unavailable proxy because they are on `127.0.0.1` (`NET_UNROUTABLE`) and the proxy is not used for that. --- test/functional/p2p_dns_seeds.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/test/functional/p2p_dns_seeds.py b/test/functional/p2p_dns_seeds.py index a2d4ea110f720..831b5165678ff 100755 --- a/test/functional/p2p_dns_seeds.py +++ b/test/functional/p2p_dns_seeds.py @@ -10,11 +10,16 @@ from test_framework.test_framework import BitcoinTestFramework +# Easily unreachable address. Attempts to connect to it will stay within the machine. +# Used to avoid non-loopback traffic or DNS queries. +DUMMY_PROXY_ARG = '-proxy=127.0.0.1:1' + + class P2PDNSSeeds(BitcoinTestFramework): def set_test_params(self): self.setup_clean_chain = True self.num_nodes = 1 - self.extra_args = [["-dnsseed=1"]] + self.extra_args = [["-dnsseed=1", DUMMY_PROXY_ARG]] def run_test(self): self.init_arg_tests() @@ -29,11 +34,11 @@ def init_arg_tests(self): self.log.info("Check that setting -connect disables -dnsseed by default") self.nodes[0].stop_node() with self.nodes[0].assert_debug_log(expected_msgs=["DNS seeding disabled"]): - self.start_node(0, [f"-connect={fakeaddr}"]) + self.start_node(0, extra_args=[f"-connect={fakeaddr}", DUMMY_PROXY_ARG]) self.log.info("Check that running -connect and -dnsseed means DNS logic runs.") with self.nodes[0].assert_debug_log(expected_msgs=["Loading addresses from DNS seed"], timeout=12): - self.restart_node(0, [f"-connect={fakeaddr}", "-dnsseed=1"]) + self.restart_node(0, extra_args=[f"-connect={fakeaddr}", "-dnsseed=1", DUMMY_PROXY_ARG]) self.log.info("Check that running -forcednsseed and -dnsseed=0 throws an error.") self.nodes[0].stop_node() @@ -88,7 +93,7 @@ def force_dns_test(self): with self.nodes[0].assert_debug_log(expected_msgs=["Loading addresses from DNS seed"], timeout=12): # -dnsseed defaults to 1 in bitcoind, but 0 in the test framework, # so pass it explicitly here - self.restart_node(0, ["-forcednsseed", "-dnsseed=1"]) + self.restart_node(0, ["-forcednsseed", "-dnsseed=1", DUMMY_PROXY_ARG]) # Restore default for subsequent tests self.restart_node(0)