Skip to content

Commit 7cd862a

Browse files
committed
Merge bitcoin#31646: test: avoid internet traffic
2ed161c test: avoid generating non-loopback traffic from p2p_dns_seeds.py (Vasil Dimov) a5746dc test: avoid generating non-loopback traffic from feature_config_args.py (Vasil Dimov) 6b3f6ea test: avoid generating non-loopback traffic from p2p_seednode.py (Vasil Dimov) Pull request description: Avoid generating outbound traffic on a non-loopback interface during tests. Fix all tests, including ones that generate DNS traffic. --- This is a subset of bitcoin#31349 containing only the changes to the tests, without the CI changes to detect future regressions. ACKs for top commit: kevkevinpal: light code review ACK [2ed161c](bitcoin@2ed161c) brunoerg: code review ACK 2ed161c BrandonOdiwuor: Code Review ACK 2ed161c jonatack: ACK 2ed161c Tree-SHA512: 34dcd4a4d0c4edaa68cc7263540af01afd6ef6e90fd6a43dcd1e989dbd7d32cb2c24ad9e68fde75866a935e6dbfe10d45c10f0bc674f40f9ac72ef964e5a380a
2 parents 35bf426 + 2ed161c commit 7cd862a

File tree

4 files changed

+27
-17
lines changed

4 files changed

+27
-17
lines changed

test/functional/feature_config_args.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import tempfile
1212
import time
1313

14+
from test_framework.netutil import UNREACHABLE_PROXY_ARG
1415
from test_framework.test_framework import BitcoinTestFramework
1516
from test_framework.test_node import ErrorMatch
1617
from test_framework import util
@@ -227,8 +228,8 @@ def test_invalid_command_line_options(self):
227228
)
228229

229230
def test_log_buffer(self):
230-
with self.nodes[0].assert_debug_log(expected_msgs=['Warning: parsed potentially confusing double-negative -connect=0\n']):
231-
self.start_node(0, extra_args=['-noconnect=0'])
231+
with self.nodes[0].assert_debug_log(expected_msgs=['Warning: parsed potentially confusing double-negative -listen=0\n']):
232+
self.start_node(0, extra_args=['-nolisten=0'])
232233
self.stop_node(0)
233234

234235
def test_args_log(self):
@@ -259,6 +260,7 @@ def test_args_log(self):
259260
'-rpcpassword=',
260261
'-rpcuser=secret-rpcuser',
261262
'-torpassword=secret-torpassword',
263+
UNREACHABLE_PROXY_ARG,
262264
])
263265
self.stop_node(0)
264266

@@ -307,7 +309,7 @@ def test_seed_peers(self):
307309
],
308310
timeout=10,
309311
):
310-
self.start_node(0, extra_args=['-dnsseed=1', '-fixedseeds=1', f'-mocktime={start}'])
312+
self.start_node(0, extra_args=['-dnsseed=1', '-fixedseeds=1', f'-mocktime={start}', UNREACHABLE_PROXY_ARG])
311313

312314
# Only regtest has no fixed seeds. To avoid connections to random
313315
# nodes, regtest is the only network where it is safe to enable
@@ -355,7 +357,7 @@ def test_seed_peers(self):
355357
],
356358
timeout=10,
357359
):
358-
self.start_node(0, extra_args=['-dnsseed=0', '-fixedseeds=1', '-addnode=fakenodeaddr', f'-mocktime={start}'])
360+
self.start_node(0, extra_args=['-dnsseed=0', '-fixedseeds=1', '-addnode=fakenodeaddr', f'-mocktime={start}', UNREACHABLE_PROXY_ARG])
359361
with self.nodes[0].assert_debug_log(expected_msgs=[
360362
"Adding fixed seeds as 60 seconds have passed and addrman is empty",
361363
]):
@@ -371,18 +373,18 @@ def test_connect_with_seednode(self):
371373
# When -connect is supplied, expanding addrman via getaddr calls to ADDR_FETCH(-seednode)
372374
# nodes is irrelevant and -seednode is ignored.
373375
with self.nodes[0].assert_debug_log(expected_msgs=seednode_ignored):
374-
self.start_node(0, extra_args=['-connect=fakeaddress1', '-seednode=fakeaddress2'])
376+
self.start_node(0, extra_args=['-connect=fakeaddress1', '-seednode=fakeaddress2', UNREACHABLE_PROXY_ARG])
375377

376378
# With -proxy, an ADDR_FETCH connection is made to a peer that the dns seed resolves to.
377379
# ADDR_FETCH connections are not used when -connect is used.
378380
with self.nodes[0].assert_debug_log(expected_msgs=dnsseed_ignored):
379-
self.restart_node(0, extra_args=['-connect=fakeaddress1', '-dnsseed=1', '-proxy=1.2.3.4'])
381+
self.restart_node(0, extra_args=['-connect=fakeaddress1', '-dnsseed=1', UNREACHABLE_PROXY_ARG])
380382

381383
# If the user did not disable -dnsseed, but it was soft-disabled because they provided -connect,
382384
# they shouldn't see a warning about -dnsseed being ignored.
383385
with self.nodes[0].assert_debug_log(expected_msgs=addcon_thread_started,
384386
unexpected_msgs=dnsseed_ignored):
385-
self.restart_node(0, extra_args=['-connect=fakeaddress1', '-proxy=1.2.3.4'])
387+
self.restart_node(0, extra_args=['-connect=fakeaddress1', UNREACHABLE_PROXY_ARG])
386388

387389
# We have to supply expected_msgs as it's a required argument
388390
# The expected_msg must be something we are confident will be logged after the unexpected_msg

test/functional/p2p_dns_seeds.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import itertools
88

9+
from test_framework.netutil import UNREACHABLE_PROXY_ARG
910
from test_framework.p2p import P2PInterface
1011
from test_framework.test_framework import BitcoinTestFramework
1112

@@ -14,7 +15,7 @@ class P2PDNSSeeds(BitcoinTestFramework):
1415
def set_test_params(self):
1516
self.setup_clean_chain = True
1617
self.num_nodes = 1
17-
self.extra_args = [["-dnsseed=1"]]
18+
self.extra_args = [["-dnsseed=1", UNREACHABLE_PROXY_ARG]]
1819

1920
def run_test(self):
2021
self.init_arg_tests()
@@ -29,11 +30,11 @@ def init_arg_tests(self):
2930
self.log.info("Check that setting -connect disables -dnsseed by default")
3031
self.nodes[0].stop_node()
3132
with self.nodes[0].assert_debug_log(expected_msgs=["DNS seeding disabled"]):
32-
self.start_node(0, [f"-connect={fakeaddr}"])
33+
self.start_node(0, extra_args=[f"-connect={fakeaddr}", UNREACHABLE_PROXY_ARG])
3334

3435
self.log.info("Check that running -connect and -dnsseed means DNS logic runs.")
3536
with self.nodes[0].assert_debug_log(expected_msgs=["Loading addresses from DNS seed"], timeout=12):
36-
self.restart_node(0, [f"-connect={fakeaddr}", "-dnsseed=1"])
37+
self.restart_node(0, extra_args=[f"-connect={fakeaddr}", "-dnsseed=1", UNREACHABLE_PROXY_ARG])
3738

3839
self.log.info("Check that running -forcednsseed and -dnsseed=0 throws an error.")
3940
self.nodes[0].stop_node()
@@ -88,7 +89,7 @@ def force_dns_test(self):
8889
with self.nodes[0].assert_debug_log(expected_msgs=["Loading addresses from DNS seed"], timeout=12):
8990
# -dnsseed defaults to 1 in bitcoind, but 0 in the test framework,
9091
# so pass it explicitly here
91-
self.restart_node(0, ["-forcednsseed", "-dnsseed=1"])
92+
self.restart_node(0, ["-forcednsseed", "-dnsseed=1", UNREACHABLE_PROXY_ARG])
9293

9394
# Restore default for subsequent tests
9495
self.restart_node(0)

test/functional/p2p_seednode.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import random
1010
import time
1111

12+
from test_framework.netutil import UNREACHABLE_PROXY_ARG
1213
from test_framework.test_framework import BitcoinTestFramework
1314

1415
ADD_NEXT_SEEDNODE = 10
@@ -17,32 +18,34 @@
1718
class P2PSeedNodes(BitcoinTestFramework):
1819
def set_test_params(self):
1920
self.num_nodes = 1
21+
# Specify a non-working proxy to make sure no actual connections to random IPs are attempted.
22+
self.extra_args = [[UNREACHABLE_PROXY_ARG]]
2023
self.disable_autoconnect = False
2124

2225
def test_no_seednode(self):
2326
self.log.info("Check that if no seednode is provided, the node proceeds as usual (without waiting)")
2427
with self.nodes[0].assert_debug_log(expected_msgs=[], unexpected_msgs=["Empty addrman, adding seednode", f"Couldn't connect to peers from addrman after {ADD_NEXT_SEEDNODE} seconds. Adding seednode"], timeout=ADD_NEXT_SEEDNODE):
25-
self.restart_node(0)
28+
self.restart_node(0, extra_args=self.nodes[0].extra_args)
2629

2730
def test_seednode_empty_addrman(self):
28-
seed_node = "0.0.0.1"
31+
seed_node = "25.0.0.1"
2932
self.log.info("Check that the seednode is immediately added on bootstrap on an empty addrman")
3033
with self.nodes[0].assert_debug_log(expected_msgs=[f"Empty addrman, adding seednode ({seed_node}) to addrfetch"], timeout=ADD_NEXT_SEEDNODE):
31-
self.restart_node(0, extra_args=[f'-seednode={seed_node}'])
34+
self.restart_node(0, extra_args=self.nodes[0].extra_args + [f'-seednode={seed_node}'])
3235

3336
def test_seednode_non_empty_addrman(self):
3437
self.log.info("Check that if addrman is non-empty, seednodes are queried with a delay")
35-
seed_node = "0.0.0.2"
38+
seed_node = "25.0.0.2"
3639
node = self.nodes[0]
3740
# Fill the addrman with unreachable nodes
3841
for i in range(10):
3942
ip = f"{random.randrange(128,169)}.{random.randrange(1,255)}.{random.randrange(1,255)}.{random.randrange(1,255)}"
4043
port = 8333 + i
4144
node.addpeeraddress(ip, port)
4245

43-
# Restart the node so seednode is processed again. Specify a non-working proxy to make sure no actual connections to random IPs are attempted.
46+
# Restart the node so seednode is processed again.
4447
with node.assert_debug_log(expected_msgs=["trying v1 connection"], timeout=ADD_NEXT_SEEDNODE):
45-
self.restart_node(0, extra_args=[f'-seednode={seed_node}', '-proxy=127.0.0.1:1'])
48+
self.restart_node(0, extra_args=self.nodes[0].extra_args + [f'-seednode={seed_node}'])
4649

4750
with node.assert_debug_log(expected_msgs=[f"Couldn't connect to peers from addrman after {ADD_NEXT_SEEDNODE} seconds. Adding seednode ({seed_node}) to addrfetch"], unexpected_msgs=["Empty addrman, adding seednode"], timeout=ADD_NEXT_SEEDNODE * 1.5):
4851
node.setmocktime(int(time.time()) + ADD_NEXT_SEEDNODE + 1)

test/functional/test_framework/netutil.py

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
import array
1414
import os
1515

16+
# Easily unreachable address. Attempts to connect to it will stay within the machine.
17+
# Used to avoid non-loopback traffic or DNS queries.
18+
UNREACHABLE_PROXY_ARG = '-proxy=127.0.0.1:1'
19+
1620
# STATE_ESTABLISHED = '01'
1721
# STATE_SYN_SENT = '02'
1822
# STATE_SYN_RECV = '03'

0 commit comments

Comments
 (0)