mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-26 11:13:23 -03:00
test: getpeerinfo last_block and last_transaction tests
This commit is contained in:
parent
8a560a7d57
commit
21c57bacda
1 changed files with 17 additions and 3 deletions
|
@ -8,9 +8,12 @@ Tests correspond to code in rpc/net.cpp.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
from itertools import product
|
||||||
|
import time
|
||||||
|
|
||||||
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_equal,
|
assert_equal,
|
||||||
assert_greater_than_or_equal,
|
assert_greater_than_or_equal,
|
||||||
assert_greater_than,
|
assert_greater_than,
|
||||||
|
@ -48,17 +51,17 @@ class NetTest(BitcoinTestFramework):
|
||||||
self.supports_cli = False
|
self.supports_cli = False
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
self.log.info('Get out of IBD for the minfeefilter test')
|
self.log.info('Get out of IBD for the minfeefilter and getpeerinfo tests')
|
||||||
self.nodes[0].generate(1)
|
self.nodes[0].generate(101)
|
||||||
self.log.info('Connect nodes both way')
|
self.log.info('Connect nodes both way')
|
||||||
connect_nodes(self.nodes[0], 1)
|
connect_nodes(self.nodes[0], 1)
|
||||||
connect_nodes(self.nodes[1], 0)
|
connect_nodes(self.nodes[1], 0)
|
||||||
|
|
||||||
self._test_connection_count()
|
self._test_connection_count()
|
||||||
|
self._test_getpeerinfo()
|
||||||
self._test_getnettotals()
|
self._test_getnettotals()
|
||||||
self._test_getnetworkinfo()
|
self._test_getnetworkinfo()
|
||||||
self._test_getaddednodeinfo()
|
self._test_getaddednodeinfo()
|
||||||
self._test_getpeerinfo()
|
|
||||||
self.test_service_flags()
|
self.test_service_flags()
|
||||||
self._test_getnodeaddresses()
|
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')
|
assert_raises_rpc_error(-24, "Node has not been added", self.nodes[0].getaddednodeinfo, '1.1.1.1')
|
||||||
|
|
||||||
def _test_getpeerinfo(self):
|
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]
|
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
|
# check both sides of bidirectional connection between nodes
|
||||||
# the address bound to on one side will be the source address for the other node
|
# 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'])
|
assert_equal(peer_info[0][0]['addrbind'], peer_info[1][0]['addr'])
|
||||||
|
|
Loading…
Add table
Reference in a new issue