|
26 | 26 | addnode connect to IPv6
|
27 | 27 | addnode connect to onion
|
28 | 28 | addnode connect to generic DNS name
|
| 29 | +
|
| 30 | +- Test getnetworkinfo for each node |
29 | 31 | """
|
30 | 32 |
|
31 | 33 | import socket
|
|
41 | 43 | from test_framework.netutil import test_ipv6_local
|
42 | 44 |
|
43 | 45 | RANGE_BEGIN = PORT_MIN + 2 * PORT_RANGE # Start after p2p and rpc ports
|
44 |
| -# From GetNetworkName() in netbase.cpp: |
45 |
| -NET_UNROUTABLE = "" |
| 46 | + |
| 47 | +# Networks returned by RPC getpeerinfo, defined in src/netbase.cpp::GetNetworkName() |
| 48 | +NET_UNROUTABLE = "unroutable" |
46 | 49 | NET_IPV4 = "ipv4"
|
47 | 50 | NET_IPV6 = "ipv6"
|
48 | 51 | NET_ONION = "onion"
|
49 | 52 |
|
| 53 | +# Networks returned by RPC getnetworkinfo, defined in src/rpc/net.cpp::GetNetworksInfo() |
| 54 | +NETWORKS = frozenset({NET_IPV4, NET_IPV6, NET_ONION}) |
| 55 | + |
50 | 56 |
|
51 | 57 | class ProxyTest(BitcoinTestFramework):
|
52 | 58 | def set_test_params(self):
|
@@ -84,14 +90,14 @@ def setup_nodes(self):
|
84 | 90 | self.serv3 = Socks5Server(self.conf3)
|
85 | 91 | self.serv3.start()
|
86 | 92 |
|
87 |
| - # Note: proxies are not used to connect to local nodes |
88 |
| - # this is because the proxy to use is based on CService.GetNetwork(), which return NET_UNROUTABLE for localhost |
| 93 | + # Note: proxies are not used to connect to local nodes. This is because the proxy to |
| 94 | + # use is based on CService.GetNetwork(), which returns NET_UNROUTABLE for localhost. |
89 | 95 | args = [
|
90 | 96 | ['-listen', '-proxy=%s:%i' % (self.conf1.addr),'-proxyrandomize=1'],
|
91 | 97 | ['-listen', '-proxy=%s:%i' % (self.conf1.addr),'-onion=%s:%i' % (self.conf2.addr),'-proxyrandomize=0'],
|
92 | 98 | ['-listen', '-proxy=%s:%i' % (self.conf2.addr),'-proxyrandomize=1'],
|
93 | 99 | []
|
94 |
| - ] |
| 100 | + ] |
95 | 101 | if self.have_ipv6:
|
96 | 102 | args[3] = ['-listen', '-proxy=[%s]:%i' % (self.conf3.addr),'-proxyrandomize=0', '-noonion']
|
97 | 103 | self.add_nodes(self.num_nodes, extra_args=args)
|
@@ -189,30 +195,34 @@ def networks_dict(d):
|
189 | 195 | r[x['name']] = x
|
190 | 196 | return r
|
191 | 197 |
|
192 |
| - # test RPC getnetworkinfo |
| 198 | + self.log.info("Test RPC getnetworkinfo") |
193 | 199 | n0 = networks_dict(self.nodes[0].getnetworkinfo())
|
194 |
| - for net in ['ipv4','ipv6','onion']: |
| 200 | + assert_equal(NETWORKS, n0.keys()) |
| 201 | + for net in NETWORKS: |
195 | 202 | assert_equal(n0[net]['proxy'], '%s:%i' % (self.conf1.addr))
|
196 | 203 | assert_equal(n0[net]['proxy_randomize_credentials'], True)
|
197 | 204 | assert_equal(n0['onion']['reachable'], True)
|
198 | 205 |
|
199 | 206 | n1 = networks_dict(self.nodes[1].getnetworkinfo())
|
200 |
| - for net in ['ipv4','ipv6']: |
| 207 | + assert_equal(NETWORKS, n1.keys()) |
| 208 | + for net in ['ipv4', 'ipv6']: |
201 | 209 | assert_equal(n1[net]['proxy'], '%s:%i' % (self.conf1.addr))
|
202 | 210 | assert_equal(n1[net]['proxy_randomize_credentials'], False)
|
203 | 211 | assert_equal(n1['onion']['proxy'], '%s:%i' % (self.conf2.addr))
|
204 | 212 | assert_equal(n1['onion']['proxy_randomize_credentials'], False)
|
205 | 213 | assert_equal(n1['onion']['reachable'], True)
|
206 | 214 |
|
207 | 215 | n2 = networks_dict(self.nodes[2].getnetworkinfo())
|
208 |
| - for net in ['ipv4','ipv6','onion']: |
| 216 | + assert_equal(NETWORKS, n2.keys()) |
| 217 | + for net in NETWORKS: |
209 | 218 | assert_equal(n2[net]['proxy'], '%s:%i' % (self.conf2.addr))
|
210 | 219 | assert_equal(n2[net]['proxy_randomize_credentials'], True)
|
211 | 220 | assert_equal(n2['onion']['reachable'], True)
|
212 | 221 |
|
213 | 222 | if self.have_ipv6:
|
214 | 223 | n3 = networks_dict(self.nodes[3].getnetworkinfo())
|
215 |
| - for net in ['ipv4','ipv6']: |
| 224 | + assert_equal(NETWORKS, n3.keys()) |
| 225 | + for net in NETWORKS: |
216 | 226 | assert_equal(n3[net]['proxy'], '[%s]:%i' % (self.conf3.addr))
|
217 | 227 | assert_equal(n3[net]['proxy_randomize_credentials'], False)
|
218 | 228 | assert_equal(n3['onion']['reachable'], False)
|
|
0 commit comments