Skip to content

Commit 21c57ba

Browse files
committed
test: getpeerinfo last_block and last_transaction tests
1 parent 8a560a7 commit 21c57ba

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

test/functional/rpc_net.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
"""
99

1010
from decimal import Decimal
11+
from itertools import product
12+
import time
1113

1214
from test_framework.test_framework import BitcoinTestFramework
1315
from test_framework.util import (
16+
assert_approx,
1417
assert_equal,
1518
assert_greater_than_or_equal,
1619
assert_greater_than,
@@ -48,17 +51,17 @@ def set_test_params(self):
4851
self.supports_cli = False
4952

5053
def run_test(self):
51-
self.log.info('Get out of IBD for the minfeefilter test')
52-
self.nodes[0].generate(1)
54+
self.log.info('Get out of IBD for the minfeefilter and getpeerinfo tests')
55+
self.nodes[0].generate(101)
5356
self.log.info('Connect nodes both way')
5457
connect_nodes(self.nodes[0], 1)
5558
connect_nodes(self.nodes[1], 0)
5659

5760
self._test_connection_count()
61+
self._test_getpeerinfo()
5862
self._test_getnettotals()
5963
self._test_getnetworkinfo()
6064
self._test_getaddednodeinfo()
61-
self._test_getpeerinfo()
6265
self.test_service_flags()
6366
self._test_getnodeaddresses()
6467

@@ -140,7 +143,18 @@ def _test_getaddednodeinfo(self):
140143
assert_raises_rpc_error(-24, "Node has not been added", self.nodes[0].getaddednodeinfo, '1.1.1.1')
141144

142145
def _test_getpeerinfo(self):
146+
# Create a few getpeerinfo last_block/last_transaction values.
147+
if self.is_wallet_compiled():
148+
self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1)
149+
self.nodes[1].generate(1)
150+
self.sync_all()
151+
time_now = int(time.time())
143152
peer_info = [x.getpeerinfo() for x in self.nodes]
153+
# Verify last_block and last_transaction keys/values.
154+
for node, peer, field in product(range(self.num_nodes), range(2), ['last_block', 'last_transaction']):
155+
assert field in peer_info[node][peer].keys()
156+
if peer_info[node][peer][field] != 0:
157+
assert_approx(peer_info[node][peer][field], time_now, vspan=60)
144158
# check both sides of bidirectional connection between nodes
145159
# the address bound to on one side will be the source address for the other node
146160
assert_equal(peer_info[0][0]['addrbind'], peer_info[1][0]['addr'])

0 commit comments

Comments
 (0)