MCPcopy Create free account
hub / github.com/ElementsProject/elements / test_getnodeaddresses

Method test_getnodeaddresses

test/functional/rpc_net.py:187–236  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

185 self.nodes[0].disconnect_p2ps()
186
187 def test_getnodeaddresses(self):
188 self.log.info("Test getnodeaddresses")
189 self.nodes[0].add_p2p_connection(P2PInterface())
190
191 # Add an IPv6 address to the address manager.
192 ipv6_addr = "1233:3432:2434:2343:3234:2345:6546:4534"
193 self.nodes[0].addpeeraddress(address=ipv6_addr, port=8333)
194
195 # Add 10,000 IPv4 addresses to the address manager. Due to the way bucket
196 # and bucket positions are calculated, some of these addresses will collide.
197 imported_addrs = []
198 for i in range(10000):
199 first_octet = i >> 8
200 second_octet = i % 256
201 a = f"{first_octet}.{second_octet}.1.1"
202 imported_addrs.append(a)
203 self.nodes[0].addpeeraddress(a, 8333)
204
205 # Fetch the addresses via the RPC and test the results.
206 assert_equal(len(self.nodes[0].getnodeaddresses()), 1) # default count is 1
207 assert_equal(len(self.nodes[0].getnodeaddresses(count=2)), 2)
208 assert_equal(len(self.nodes[0].getnodeaddresses(network="ipv4", count=8)), 8)
209
210 # Maximum possible addresses in AddrMan is 10000. The actual number will
211 # usually be less due to bucket and bucket position collisions.
212 node_addresses = self.nodes[0].getnodeaddresses(0, "ipv4")
213 assert_greater_than(len(node_addresses), 5000)
214 assert_greater_than(10000, len(node_addresses))
215 for a in node_addresses:
216 assert_greater_than(a["time"], 1527811200) # 1st June 2018
217 assert_equal(a["services"], P2P_SERVICES)
218 assert a["address"] in imported_addrs
219 assert_equal(a["port"], 8333)
220 assert_equal(a["network"], "ipv4")
221
222 # Test the IPv6 address.
223 res = self.nodes[0].getnodeaddresses(0, "ipv6")
224 assert_equal(len(res), 1)
225 assert_equal(res[0]["address"], ipv6_addr)
226 assert_equal(res[0]["network"], "ipv6")
227 assert_equal(res[0]["port"], 8333)
228 assert_equal(res[0]["services"], P2P_SERVICES)
229
230 # Test for the absence of onion, I2P and CJDNS addresses.
231 for network in ["onion", "i2p", "cjdns"]:
232 assert_equal(self.nodes[0].getnodeaddresses(0, network), [])
233
234 # Test invalid arguments.
235 assert_raises_rpc_error(-8, "Address count out of range", self.nodes[0].getnodeaddresses, -1)
236 assert_raises_rpc_error(-8, "Network not recognized: Foo", self.nodes[0].getnodeaddresses, 1, "Foo")
237
238 def test_addpeeraddress(self):
239 """RPC addpeeraddress sets the source address equal to the destination address.

Callers 1

run_testMethod · 0.95

Calls 6

P2PInterfaceClass · 0.90
assert_equalFunction · 0.90
assert_greater_thanFunction · 0.90
assert_raises_rpc_errorFunction · 0.90
infoMethod · 0.80
add_p2p_connectionMethod · 0.45

Tested by

no test coverage detected