1 #!/usr/bin/env python3
2 # Copyright (c) 2021-present The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 """
6 Test ports handling for I2P hosts
7 """
8 9 from test_framework.test_framework import BitcoinTestFramework
10 from test_framework.util import p2p_port
11 12 13 class I2PPorts(BitcoinTestFramework):
14 def set_test_params(self):
15 self.num_nodes = 1
16 # Use the p2p port of the non-existing next node as the proxy port
17 self.proxy = f"127.0.0.1:{p2p_port(self.num_nodes)}"
18 # The test assumes that an I2P SAM proxy is not listening here.
19 self.extra_args = [[f"-i2psam={self.proxy}"]]
20 21 def run_test(self):
22 node = self.nodes[0]
23 24 self.log.info("Ensure we don't try to connect if port!=0")
25 addr = "zsxwyo6qcn3chqzwxnseusqgsnuw3maqnztkiypyfxtya4snkoka.b32.i2p:8333"
26 with node.assert_debug_log(expected_msgs=[f"Error connecting to {addr}, connection refused due to arbitrary port 8333"]):
27 node.addnode(node=addr, command="onetry")
28 29 self.log.info("Ensure we try to connect if port=0 and get an error due to missing I2P proxy")
30 addr = "h3r6bkn46qxftwja53pxiykntegfyfjqtnzbm6iv6r5mungmqgmq.b32.i2p:0"
31 with node.assert_debug_log(expected_msgs=[f"Error connecting to {addr}: Cannot connect to {self.proxy}"]):
32 node.addnode(node=addr, command="onetry")
33 34 35 if __name__ == '__main__':
36 I2PPorts(__file__).main()
37