From 1c500b17098e2c65129a1dda7345b9961f4a951f Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Thu, 4 Sep 2025 14:47:41 +0200 Subject: [PATCH] test: avoid non-loopback network traffic from node_init_tests/init_test The test calls: `AppInitMain()` -> `StartMapPort()` -> `StartThreadMapPort()` -> `ThreadMapPort()` -> `ProcessPCP()` -> `PCPRequestPortMap()` -> `CreateSock()` and on the returned value from `CreateSock()` it calls the `Connect()` method. Thus, change `BasicTestingSetup::BasicTestingSetup()` to set `-natpmp` to 0. This way `node_init_tests/init_test` or other tests will not do network activity due to `ThreadMapPort()`. Also add a comment about `natpmp=0` in `test/functional/test_framework/util.py`. Also set `-dnsseed=0` in `BasicTestingSetup::BasicTestingSetup()` to avoid DNS queries. --- src/test/util/setup_common.cpp | 4 ++++ test/functional/test_framework/util.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index 39c691c3364..349d7cbdb81 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -199,6 +199,10 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts) m_args.ForceSetArg("-datadir", fs::PathToString(m_path_root)); gArgs.ForceSetArg("-datadir", fs::PathToString(m_path_root)); + // Avoid non-loopback network traffic during tests. + gArgs.ForceSetArg("-dnsseed", "0"); // DNS queries are usually forwarded to upstream DNS servers. + gArgs.ForceSetArg("-natpmp", "0"); // NATPMP sends packets to the router. + SelectParams(chainType); InitLogging(*m_node.args); AppInitParameterInteraction(*m_node.args); diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index 3e7e6dd97a9..4918a7f4d5e 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -576,7 +576,7 @@ def write_config(config_path, *, n, chain, extra_config="", disable_autoconnect= # in tests. f.write("peertimeout=999999999\n") f.write("printtoconsole=0\n") - f.write("natpmp=0\n") + f.write("natpmp=0\n") # Avoid non-loopback network traffic during tests. f.write("shrinkdebugfile=0\n") # To improve SQLite wallet performance so that the tests don't timeout, use -unsafesqlitesync f.write("unsafesqlitesync=1\n")