test: Prevent connection attempts to random IPs in p2p_seednodes.py

These addrs aren't unreachable as the test claims.
Specify a (non-working) proxy to make sure the connections fails
even if the addr was reachable.

Co-authored-by: Vasil Dimov <vd@FreeBSD.org>
pull/31142/head
Martin Zumsande 2 weeks ago
parent bb97b1ffa9
commit 6c9fe7b73e

@ -30,7 +30,7 @@ class P2PSeedNodes(BitcoinTestFramework):
with self.nodes[0].assert_debug_log(expected_msgs=[f"Empty addrman, adding seednode ({seed_node}) to addrfetch"], timeout=ADD_NEXT_SEEDNODE): with self.nodes[0].assert_debug_log(expected_msgs=[f"Empty addrman, adding seednode ({seed_node}) to addrfetch"], timeout=ADD_NEXT_SEEDNODE):
self.restart_node(0, extra_args=[f'-seednode={seed_node}']) self.restart_node(0, extra_args=[f'-seednode={seed_node}'])
def test_seednode_addrman_unreachable_peers(self): def test_seednode_non_empty_addrman(self):
self.log.info("Check that if addrman is non-empty, seednodes are queried with a delay") self.log.info("Check that if addrman is non-empty, seednodes are queried with a delay")
seed_node = "0.0.0.2" seed_node = "0.0.0.2"
node = self.nodes[0] node = self.nodes[0]
@ -40,9 +40,9 @@ class P2PSeedNodes(BitcoinTestFramework):
port = 8333 + i port = 8333 + i
node.addpeeraddress(ip, port) node.addpeeraddress(ip, port)
# Restart the node so seednode is processed again # Restart the node so seednode is processed again. Specify a non-working proxy to make sure no actual connections to random IPs are attempted.
with node.assert_debug_log(expected_msgs=["trying v1 connection"], timeout=ADD_NEXT_SEEDNODE): with node.assert_debug_log(expected_msgs=["trying v1 connection"], timeout=ADD_NEXT_SEEDNODE):
self.restart_node(0, extra_args=[f'-seednode={seed_node}']) self.restart_node(0, extra_args=[f'-seednode={seed_node}', '-proxy=127.0.0.1:1'])
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): 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):
node.setmocktime(int(time.time()) + ADD_NEXT_SEEDNODE + 1) node.setmocktime(int(time.time()) + ADD_NEXT_SEEDNODE + 1)
@ -50,7 +50,7 @@ class P2PSeedNodes(BitcoinTestFramework):
def run_test(self): def run_test(self):
self.test_no_seednode() self.test_no_seednode()
self.test_seednode_empty_addrman() self.test_seednode_empty_addrman()
self.test_seednode_addrman_unreachable_peers() self.test_seednode_non_empty_addrman()
if __name__ == '__main__': if __name__ == '__main__':

Loading…
Cancel
Save