From 21c57bacda766a4f56ee75a2872f5d0f94e3901e Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Sat, 15 Aug 2020 09:01:21 +0200 Subject: test: getpeerinfo last_block and last_transaction tests --- test/functional/rpc_net.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'test/functional') diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py index 192b60e5d2..1729ddc210 100755 --- a/test/functional/rpc_net.py +++ b/test/functional/rpc_net.py @@ -8,9 +8,12 @@ Tests correspond to code in rpc/net.cpp. """ from decimal import Decimal +from itertools import product +import time from test_framework.test_framework import BitcoinTestFramework from test_framework.util import ( + assert_approx, assert_equal, assert_greater_than_or_equal, assert_greater_than, @@ -48,17 +51,17 @@ class NetTest(BitcoinTestFramework): self.supports_cli = False def run_test(self): - self.log.info('Get out of IBD for the minfeefilter test') - self.nodes[0].generate(1) + self.log.info('Get out of IBD for the minfeefilter and getpeerinfo tests') + self.nodes[0].generate(101) self.log.info('Connect nodes both way') connect_nodes(self.nodes[0], 1) connect_nodes(self.nodes[1], 0) self._test_connection_count() + self._test_getpeerinfo() self._test_getnettotals() self._test_getnetworkinfo() self._test_getaddednodeinfo() - self._test_getpeerinfo() self.test_service_flags() self._test_getnodeaddresses() @@ -140,7 +143,18 @@ class NetTest(BitcoinTestFramework): assert_raises_rpc_error(-24, "Node has not been added", self.nodes[0].getaddednodeinfo, '1.1.1.1') def _test_getpeerinfo(self): + # Create a few getpeerinfo last_block/last_transaction values. + if self.is_wallet_compiled(): + self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1) + self.nodes[1].generate(1) + self.sync_all() + time_now = int(time.time()) peer_info = [x.getpeerinfo() for x in self.nodes] + # Verify last_block and last_transaction keys/values. + for node, peer, field in product(range(self.num_nodes), range(2), ['last_block', 'last_transaction']): + assert field in peer_info[node][peer].keys() + if peer_info[node][peer][field] != 0: + assert_approx(peer_info[node][peer][field], time_now, vspan=60) # check both sides of bidirectional connection between nodes # the address bound to on one side will be the source address for the other node assert_equal(peer_info[0][0]['addrbind'], peer_info[1][0]['addr']) -- cgit v1.2.3