Skip to content

Commit

Permalink
test: avoid generating non-loopback traffic from p2p_dns_seeds.py
Browse files Browse the repository at this point in the history
`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.
  • Loading branch information
vasild committed Dec 17, 2024
1 parent d37ebe0 commit 987a614
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions test/functional/p2p_dns_seeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 987a614

Please sign in to comment.