Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_net.py
Show All 9 Lines | |||||
from decimal import Decimal | from decimal import Decimal | ||||
from itertools import product | from itertools import product | ||||
import time | import time | ||||
from test_framework.avatools import create_coinbase_stakes | from test_framework.avatools import create_coinbase_stakes | ||||
from test_framework.key import ECKey | from test_framework.key import ECKey | ||||
from test_framework.p2p import P2PInterface | from test_framework.p2p import P2PInterface | ||||
import test_framework.messages | import test_framework.messages | ||||
from test_framework.messages import ( | from test_framework.messages import NODE_NETWORK | ||||
CAddress, | |||||
msg_addr, | |||||
NODE_NETWORK, | |||||
) | |||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_approx, | assert_approx, | ||||
assert_equal, | assert_equal, | ||||
assert_greater_than_or_equal, | assert_greater_than_or_equal, | ||||
assert_greater_than, | assert_greater_than, | ||||
assert_raises_rpc_error, | assert_raises_rpc_error, | ||||
connect_nodes, | connect_nodes, | ||||
▲ Show 20 Lines • Show All 176 Lines • ▼ Show 20 Lines | def test_service_flags(self): | ||||
assert_equal(['UNKNOWN[2^5]', 'UNKNOWN[2^63]'], | assert_equal(['UNKNOWN[2^5]', 'UNKNOWN[2^63]'], | ||||
self.nodes[0].getpeerinfo()[-1]['servicesnames']) | self.nodes[0].getpeerinfo()[-1]['servicesnames']) | ||||
self.nodes[0].disconnect_p2ps() | self.nodes[0].disconnect_p2ps() | ||||
def test_getnodeaddresses(self): | def test_getnodeaddresses(self): | ||||
self.log.info("Test getnodeaddresses") | self.log.info("Test getnodeaddresses") | ||||
self.nodes[0].add_p2p_connection(P2PInterface()) | self.nodes[0].add_p2p_connection(P2PInterface()) | ||||
# send some addresses to the node via the p2p message addr | # Add some addresses to the Address Manager over RPC. Due to the way | ||||
msg = msg_addr() | # bucket and bucket position are calculated, some of these addresses | ||||
# will collide. | |||||
imported_addrs = [] | imported_addrs = [] | ||||
for i in range(256): | for i in range(10000): | ||||
a = "123.123.123.{}".format(i) | first_octet = i >> 8 | ||||
second_octet = i % 256 | |||||
a = "{}.{}.1.1".format(first_octet, second_octet) | |||||
imported_addrs.append(a) | imported_addrs.append(a) | ||||
addr = CAddress() | self.nodes[0].addpeeraddress(a, 8333) | ||||
addr.time = 100000000 | |||||
addr.nServices = NODE_NETWORK | |||||
addr.ip = a | |||||
addr.port = 8333 | |||||
msg.addrs.append(addr) | |||||
self.nodes[0].p2p.send_and_ping(msg) | |||||
# Obtain addresses via rpc call and check they were ones sent in before. | # Obtain addresses via rpc call and check they were ones sent in before. | ||||
# | # | ||||
# All addresses added above are in the same netgroup and so are assigned | # Maximum possible addresses in addrman is 10000, although actual | ||||
# to the same bucket. Maximum possible addresses in addrman is therefore | # number will usually be less due to bucket and bucket position | ||||
# 64, although actual number will usually be slightly less due to | # collisions. | ||||
# BucketPosition collisions. | |||||
node_addresses = self.nodes[0].getnodeaddresses(0) | node_addresses = self.nodes[0].getnodeaddresses(0) | ||||
assert_greater_than(len(node_addresses), 50) | assert_greater_than(len(node_addresses), 5000) | ||||
assert_greater_than(65, len(node_addresses)) | assert_greater_than(10000, len(node_addresses)) | ||||
for a in node_addresses: | for a in node_addresses: | ||||
assert_greater_than(a["time"], 1527811200) # 1st June 2018 | assert_greater_than(a["time"], 1527811200) # 1st June 2018 | ||||
assert_equal(a["services"], NODE_NETWORK) | assert_equal(a["services"], NODE_NETWORK) | ||||
assert a["address"] in imported_addrs | assert a["address"] in imported_addrs | ||||
assert_equal(a["port"], 8333) | assert_equal(a["port"], 8333) | ||||
node_addresses = self.nodes[0].getnodeaddresses(1) | node_addresses = self.nodes[0].getnodeaddresses(1) | ||||
assert_equal(len(node_addresses), 1) | assert_equal(len(node_addresses), 1) | ||||
Show All 14 Lines |