diff --git a/test/functional/feature_bind_extra.py b/test/functional/feature_bind_extra.py --- a/test/functional/feature_bind_extra.py +++ b/test/functional/feature_bind_extra.py @@ -11,7 +11,7 @@ from test_framework.netutil import addr_to_hex, get_bind_addrs from test_framework.test_framework import BitcoinTestFramework, SkipTest -from test_framework.util import PORT_MIN, PORT_RANGE, assert_equal, rpc_port +from test_framework.util import assert_equal, p2p_port, rpc_port class BindExtraTest(BitcoinTestFramework): @@ -23,11 +23,6 @@ self.num_nodes = 2 def setup_network(self): - # Override setup_network() because we want to put the result of - # p2p_port() in self.extra_args[], before the nodes are started. - # p2p_port() is not usable in set_test_params() because PortSeed.n is - # not set at that time. - # Due to OS-specific network stats queries, we only run on Linux. self.log.info("Checking for Linux") if not sys.platform.startswith('linux'): @@ -35,8 +30,8 @@ loopback_ipv4 = addr_to_hex("127.0.0.1") - # Start custom ports after p2p and rpc ports. - port = PORT_MIN + 2 * PORT_RANGE + # Start custom ports by reusing unused p2p ports + port = p2p_port(self.num_nodes) # Array of tuples [command line arguments, expected bind addresses]. self.expected = [] diff --git a/test/functional/feature_proxy.py b/test/functional/feature_proxy.py --- a/test/functional/feature_proxy.py +++ b/test/functional/feature_proxy.py @@ -30,7 +30,6 @@ - Test getnetworkinfo for each node """ -import os import socket from test_framework.netutil import test_ipv6_local @@ -41,9 +40,7 @@ Socks5Server, ) from test_framework.test_framework import BitcoinTestFramework -from test_framework.util import PORT_MIN, PORT_RANGE, assert_equal - -RANGE_BEGIN = PORT_MIN + 2 * PORT_RANGE # Start after p2p and rpc ports +from test_framework.util import assert_equal, p2p_port # Networks returned by RPC getpeerinfo. NET_UNROUTABLE = "not_publicly_routable" @@ -67,21 +64,19 @@ # Create two proxies on different ports # ... one unauthenticated self.conf1 = Socks5Configuration() - self.conf1.addr = ('127.0.0.1', RANGE_BEGIN + (os.getpid() % 1000)) + self.conf1.addr = ('127.0.0.1', p2p_port(self.num_nodes)) self.conf1.unauth = True self.conf1.auth = False # ... one supporting authenticated and unauthenticated (Tor) self.conf2 = Socks5Configuration() - self.conf2.addr = ( - '127.0.0.1', RANGE_BEGIN + 1000 + (os.getpid() % 1000)) + self.conf2.addr = ('127.0.0.1', p2p_port(self.num_nodes + 1)) self.conf2.unauth = True self.conf2.auth = True if self.have_ipv6: # ... one on IPv6 with similar configuration self.conf3 = Socks5Configuration() self.conf3.af = socket.AF_INET6 - self.conf3.addr = ( - '::1', RANGE_BEGIN + 2000 + (os.getpid() % 1000)) + self.conf3.addr = ('::1', p2p_port(self.num_nodes + 2)) self.conf3.unauth = True self.conf3.auth = True else: diff --git a/test/functional/p2p_getaddr_caching.py b/test/functional/p2p_getaddr_caching.py --- a/test/functional/p2p_getaddr_caching.py +++ b/test/functional/p2p_getaddr_caching.py @@ -38,6 +38,9 @@ class AddrTest(BitcoinTestFramework): def set_test_params(self): self.num_nodes = 1 + # TODO When Backporting core#25096, please also includes changes from: + # - core#25312 + # - core#25333 def run_test(self): self.log.info('Fill peer AddrMan with a lot of records') diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -205,10 +205,10 @@ self.add_options(parser) self.options = parser.parse_args() - def setup(self): - """Call this method to start up the test framework object with options set.""" PortSeed.n = self.options.port_seed + def setup(self): + """Call this method to start up the test framework object with options set.""" check_json_precision() self.options.cachedir = os.path.abspath(self.options.cachedir)