aboutsummaryrefslogtreecommitdiff
path: root/test/functional/net.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/net.py')
-rwxr-xr-xtest/functional/net.py54
1 files changed, 50 insertions, 4 deletions
diff --git a/test/functional/net.py b/test/functional/net.py
index e9463c7dc7..9eae140455 100755
--- a/test/functional/net.py
+++ b/test/functional/net.py
@@ -7,15 +7,15 @@
Tests correspond to code in rpc/net.cpp.
"""
-from decimal import Decimal
import time
from test_framework.test_framework import BitcoinTestFramework
-from test_framework.authproxy import JSONRPCException
from test_framework.util import (
assert_equal,
- start_nodes,
+ assert_raises_jsonrpc,
connect_nodes_bi,
+ p2p_port,
+ start_nodes,
)
@@ -32,8 +32,41 @@ class NetTest(BitcoinTestFramework):
self.sync_all()
def run_test(self):
+ self._test_connection_count()
+ self._test_getnettotals()
+ self._test_getnetworkinginfo()
+ self._test_getaddednodeinfo()
+
+ def _test_connection_count(self):
+ # connect_nodes_bi connects each node to the other
+ assert_equal(self.nodes[0].getconnectioncount(), 2)
+
+ def _test_getnettotals(self):
+ # check that getnettotals totalbytesrecv and totalbytessent
+ # are consistent with getpeerinfo
+ peer_info = self.nodes[0].getpeerinfo()
+ assert_equal(len(peer_info), 2)
+ net_totals = self.nodes[0].getnettotals()
+ assert_equal(sum([peer['bytesrecv'] for peer in peer_info]),
+ net_totals['totalbytesrecv'])
+ assert_equal(sum([peer['bytessent'] for peer in peer_info]),
+ net_totals['totalbytessent'])
+ # test getnettotals and getpeerinfo by doing a ping
+ # the bytes sent/received should change
+ # note ping and pong are 32 bytes each
+ self.nodes[0].ping()
+ time.sleep(0.1)
+ peer_info_after_ping = self.nodes[0].getpeerinfo()
+ net_totals_after_ping = self.nodes[0].getnettotals()
+ for before, after in zip(peer_info, peer_info_after_ping):
+ assert_equal(before['bytesrecv_per_msg']['pong'] + 32, after['bytesrecv_per_msg']['pong'])
+ assert_equal(before['bytessent_per_msg']['ping'] + 32, after['bytessent_per_msg']['ping'])
+ assert_equal(net_totals['totalbytesrecv'] + 32*2, net_totals_after_ping['totalbytesrecv'])
+ assert_equal(net_totals['totalbytessent'] + 32*2, net_totals_after_ping['totalbytessent'])
+
+ def _test_getnetworkinginfo(self):
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True)
- assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2) # bilateral connection
+ assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2)
self.nodes[0].setnetworkactive(False)
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], False)
@@ -49,6 +82,19 @@ class NetTest(BitcoinTestFramework):
assert_equal(self.nodes[0].getnetworkinfo()['networkactive'], True)
assert_equal(self.nodes[0].getnetworkinfo()['connections'], 2)
+ def _test_getaddednodeinfo(self):
+ assert_equal(self.nodes[0].getaddednodeinfo(), [])
+ # add a node (node2) to node0
+ ip_port = "127.0.0.1:{}".format(p2p_port(2))
+ self.nodes[0].addnode(ip_port, 'add')
+ # check that the node has indeed been added
+ added_nodes = self.nodes[0].getaddednodeinfo(ip_port)
+ assert_equal(len(added_nodes), 1)
+ assert_equal(added_nodes[0]['addednode'], ip_port)
+ # check that a non-existant node returns an error
+ assert_raises_jsonrpc(-24, "Node has not been added",
+ self.nodes[0].getaddednodeinfo, '1.1.1.1')
+
if __name__ == '__main__':
NetTest().main()