aboutsummaryrefslogtreecommitdiff
path: root/test/functional/rpc_net.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/rpc_net.py')
-rwxr-xr-xtest/functional/rpc_net.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py
index a46518200c..1e525214fa 100755
--- a/test/functional/rpc_net.py
+++ b/test/functional/rpc_net.py
@@ -13,11 +13,14 @@ from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
assert_greater_than_or_equal,
+ assert_greater_than,
assert_raises_rpc_error,
connect_nodes_bi,
p2p_port,
wait_until,
)
+from test_framework.mininode import P2PInterface
+from test_framework.messages import CAddress, msg_addr, NODE_NETWORK, NODE_WITNESS
class NetTest(BitcoinTestFramework):
def set_test_params(self):
@@ -31,6 +34,7 @@ class NetTest(BitcoinTestFramework):
self._test_getnetworkinginfo()
self._test_getaddednodeinfo()
self._test_getpeerinfo()
+ self._test_getnodeaddresses()
def _test_connection_count(self):
# connect_nodes_bi connects each node to the other
@@ -101,5 +105,40 @@ class NetTest(BitcoinTestFramework):
assert_equal(peer_info[0][0]['minfeefilter'], Decimal("0.00000500"))
assert_equal(peer_info[1][0]['minfeefilter'], Decimal("0.00001000"))
+ def _test_getnodeaddresses(self):
+ self.nodes[0].add_p2p_connection(P2PInterface())
+
+ # send some addresses to the node via the p2p message addr
+ msg = msg_addr()
+ imported_addrs = []
+ for i in range(256):
+ a = "123.123.123.{}".format(i)
+ imported_addrs.append(a)
+ addr = CAddress()
+ addr.time = 100000000
+ addr.nServices = NODE_NETWORK | NODE_WITNESS
+ 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
+ REQUEST_COUNT = 10
+ node_addresses = self.nodes[0].getnodeaddresses(REQUEST_COUNT)
+ assert_equal(len(node_addresses), REQUEST_COUNT)
+ for a in node_addresses:
+ assert_greater_than(a["time"], 1527811200) # 1st June 2018
+ assert_equal(a["services"], NODE_NETWORK | NODE_WITNESS)
+ assert a["address"] in imported_addrs
+ assert_equal(a["port"], 8333)
+
+ assert_raises_rpc_error(-8, "Address count out of range", self.nodes[0].getnodeaddresses, -1)
+
+ # addrman's size cannot be known reliably after insertion, as hash collisions may occur
+ # so only test that requesting a large number of addresses returns less than that
+ LARGE_REQUEST_COUNT = 10000
+ node_addresses = self.nodes[0].getnodeaddresses(LARGE_REQUEST_COUNT)
+ assert_greater_than(LARGE_REQUEST_COUNT, len(node_addresses))
+
if __name__ == '__main__':
NetTest().main()