@@ -32,6 +32,39 @@ def setup_network(self):
32
32
self .sync_all ()
33
33
34
34
def run_test (self ):
35
+ self ._test_connection_count ()
36
+ self ._test_getnettotals ()
37
+ self ._test_getnetworkinginfo ()
38
+ self ._test_getaddednodeinfo ()
39
+
40
+ def _test_connection_count (self ):
41
+ # connect_nodes_bi connects each node to the other
42
+ assert_equal (self .nodes [0 ].getconnectioncount (), 2 )
43
+
44
+ def _test_getnettotals (self ):
45
+ # check that getnettotals totalbytesrecv and totalbytessent
46
+ # are consistent with getpeerinfo
47
+ peer_info = self .nodes [0 ].getpeerinfo ()
48
+ assert_equal (len (peer_info ), 2 )
49
+ net_totals = self .nodes [0 ].getnettotals ()
50
+ assert_equal (sum ([peer ['bytesrecv' ] for peer in peer_info ]),
51
+ net_totals ['totalbytesrecv' ])
52
+ assert_equal (sum ([peer ['bytessent' ] for peer in peer_info ]),
53
+ net_totals ['totalbytessent' ])
54
+ # test getnettotals and getpeerinfo by doing a ping
55
+ # the bytes sent/received should change
56
+ # note ping and pong are 32 bytes each
57
+ self .nodes [0 ].ping ()
58
+ time .sleep (0.1 )
59
+ peer_info_after_ping = self .nodes [0 ].getpeerinfo ()
60
+ net_totals_after_ping = self .nodes [0 ].getnettotals ()
61
+ for before , after in zip (peer_info , peer_info_after_ping ):
62
+ assert_equal (before ['bytesrecv_per_msg' ]['pong' ] + 32 , after ['bytesrecv_per_msg' ]['pong' ])
63
+ assert_equal (before ['bytessent_per_msg' ]['ping' ] + 32 , after ['bytessent_per_msg' ]['ping' ])
64
+ assert_equal (net_totals ['totalbytesrecv' ] + 32 * 2 , net_totals_after_ping ['totalbytesrecv' ])
65
+ assert_equal (net_totals ['totalbytessent' ] + 32 * 2 , net_totals_after_ping ['totalbytessent' ])
66
+
67
+ def _test_getnetworkinginfo (self ):
35
68
assert_equal (self .nodes [0 ].getnetworkinfo ()['networkactive' ], True )
36
69
assert_equal (self .nodes [0 ].getnetworkinfo ()['connections' ], 2 )
37
70
@@ -49,7 +82,7 @@ def run_test(self):
49
82
assert_equal (self .nodes [0 ].getnetworkinfo ()['networkactive' ], True )
50
83
assert_equal (self .nodes [0 ].getnetworkinfo ()['connections' ], 2 )
51
84
52
- # test getaddednodeinfo
85
+ def _test_getaddednodeinfo ( self ):
53
86
assert_equal (self .nodes [0 ].getaddednodeinfo (), [])
54
87
# add a node (node2) to node0
55
88
ip_port = "127.0.0.1:{}" .format (p2p_port (2 ))
0 commit comments