Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_bind_extra.py
Show All 19 Lines | def set_test_params(self): | ||||
# Avoid any -bind= on the command line. Force the framework to avoid | # Avoid any -bind= on the command line. Force the framework to avoid | ||||
# adding -bind=127.0.0.1. | # adding -bind=127.0.0.1. | ||||
self.bind_to_localhost_only = False | self.bind_to_localhost_only = False | ||||
self.num_nodes = 2 | self.num_nodes = 2 | ||||
def setup_network(self): | def setup_network(self): | ||||
# Due to OS-specific network stats queries, we only run on Linux. | # Due to OS-specific network stats queries, we only run on Linux. | ||||
self.log.info("Checking for Linux") | self.log.info("Checking for Linux") | ||||
if not sys.platform.startswith('linux'): | if not sys.platform.startswith("linux"): | ||||
raise SkipTest("This test can only be run on Linux.") | raise SkipTest("This test can only be run on Linux.") | ||||
loopback_ipv4 = addr_to_hex("127.0.0.1") | loopback_ipv4 = addr_to_hex("127.0.0.1") | ||||
# Start custom ports by reusing unused p2p ports | # Start custom ports by reusing unused p2p ports | ||||
port = p2p_port(self.num_nodes) | port = p2p_port(self.num_nodes) | ||||
# Array of tuples [command line arguments, expected bind addresses]. | # Array of tuples [command line arguments, expected bind addresses]. | ||||
self.expected = [] | self.expected = [] | ||||
# Node0, no normal -bind=... with -bind=...=onion, thus only the tor | # Node0, no normal -bind=... with -bind=...=onion, thus only the tor | ||||
# target. | # target. | ||||
self.expected.append( | self.expected.append( | ||||
[ | [[f"-bind=127.0.0.1:{port}=onion"], [(loopback_ipv4, port)]], | ||||
[f"-bind=127.0.0.1:{port}=onion"], | |||||
[(loopback_ipv4, port)] | |||||
], | |||||
) | ) | ||||
port += 1 | port += 1 | ||||
# Node1, both -bind=... and -bind=...=onion. | # Node1, both -bind=... and -bind=...=onion. | ||||
self.expected.append( | self.expected.append( | ||||
[ | [ | ||||
[f"-bind=127.0.0.1:{port}", | [f"-bind=127.0.0.1:{port}", f"-bind=127.0.0.1:{port + 1}=onion"], | ||||
f"-bind=127.0.0.1:{port + 1}=onion"], | [(loopback_ipv4, port), (loopback_ipv4, port + 1)], | ||||
[(loopback_ipv4, port), (loopback_ipv4, port + 1)] | |||||
], | ], | ||||
) | ) | ||||
port += 2 | port += 2 | ||||
self.extra_args = [e[0] for e in self.expected] | self.extra_args = [e[0] for e in self.expected] | ||||
self.add_nodes(self.num_nodes, self.extra_args) | self.add_nodes(self.num_nodes, self.extra_args) | ||||
# Don't start the nodes, as some of them would collide trying to bind | # Don't start the nodes, as some of them would collide trying to bind | ||||
# on the same port. | # on the same port. | ||||
def run_test(self): | def run_test(self): | ||||
for i in range(len(self.expected)): | for i in range(len(self.expected)): | ||||
self.log.info(f"Starting node {i} with {self.expected[i][0]}") | self.log.info(f"Starting node {i} with {self.expected[i][0]}") | ||||
self.start_node(i) | self.start_node(i) | ||||
pid = self.nodes[i].process.pid | pid = self.nodes[i].process.pid | ||||
binds = set(get_bind_addrs(pid)) | binds = set(get_bind_addrs(pid)) | ||||
# Remove IPv6 addresses because on some CI environments "::1" is not configured | # Remove IPv6 addresses because on some CI environments "::1" is not configured | ||||
# on the system (so our test_ipv6_local() would return False), but it is | # on the system (so our test_ipv6_local() would return False), but it is | ||||
# possible to bind on "::". This makes it unpredictable whether to expect | # possible to bind on "::". This makes it unpredictable whether to expect | ||||
# that bitcoind has bound on "::1" (for RPC) and "::" (for P2P). | # that bitcoind has bound on "::1" (for RPC) and "::" (for P2P). | ||||
ipv6_addr_len_bytes = 32 | ipv6_addr_len_bytes = 32 | ||||
binds = set( | binds = set(filter(lambda e: len(e[0]) != ipv6_addr_len_bytes, binds)) | ||||
filter( | |||||
lambda e: len( | |||||
e[0]) != ipv6_addr_len_bytes, | |||||
binds)) | |||||
# Remove RPC ports. They are not relevant for this test. | # Remove RPC ports. They are not relevant for this test. | ||||
binds = set(filter(lambda e: e[1] != rpc_port(i), binds)) | binds = set(filter(lambda e: e[1] != rpc_port(i), binds)) | ||||
assert_equal(binds, set(self.expected[i][1])) | assert_equal(binds, set(self.expected[i][1])) | ||||
self.stop_node(i) | self.stop_node(i) | ||||
self.log.info(f"Stopped node {i}") | self.log.info(f"Stopped node {i}") | ||||
if __name__ == '__main__': | if __name__ == "__main__": | ||||
BindExtraTest().main() | BindExtraTest().main() |