@@ -54,9 +54,11 @@ def run_test(self):
54
54
# Especially the exchange of messages like getheaders and friends causes test failures here
55
55
self .nodes [0 ].ping ()
56
56
self .wait_until (lambda : all (['pingtime' in n for n in self .nodes [0 ].getpeerinfo ()]))
57
- self .log .info ('Connect nodes both way' )
57
+ # By default, the test framework sets up an addnode connection from
58
+ # node 1 --> node0. By connecting node0 --> node 1, we're left with
59
+ # the two nodes being connected both ways.
60
+ # Topology will look like: node0 <--> node1
58
61
self .connect_nodes (0 , 1 )
59
- self .connect_nodes (1 , 0 )
60
62
self .sync_all ()
61
63
62
64
self .test_connection_count ()
@@ -75,6 +77,41 @@ def test_connection_count(self):
75
77
# during network setup
76
78
assert_equal (self .nodes [0 ].getconnectioncount (), 3 )
77
79
80
+ def test_getpeerinfo (self ):
81
+ self .log .info ("Test getpeerinfo" )
82
+ # Create a few getpeerinfo last_block/last_transaction values.
83
+ self .wallet .send_self_transfer (from_node = self .nodes [0 ]) # Make a transaction so we can see it in the getpeerinfo results
84
+ self .nodes [1 ].generate (1 )
85
+ self .sync_all ()
86
+ time_now = self .mocktime
87
+ peer_info = [x .getpeerinfo () for x in self .nodes ]
88
+ # Verify last_block and last_transaction keys/values.
89
+ for node , peer , field in product (range (self .num_nodes - self .mn_count ), range (2 ), ['last_block' , 'last_transaction' ]):
90
+ assert field in peer_info [node ][peer ].keys ()
91
+ if peer_info [node ][peer ][field ] != 0 :
92
+ assert_approx (peer_info [node ][peer ][field ], time_now , vspan = 60 )
93
+ # check both sides of bidirectional connection between nodes
94
+ # the address bound to on one side will be the source address for the other node
95
+ assert_equal (peer_info [0 ][0 ]['addrbind' ], peer_info [1 ][0 ]['addr' ])
96
+ assert_equal (peer_info [1 ][0 ]['addrbind' ], peer_info [0 ][0 ]['addr' ])
97
+ # check the `servicesnames` field
98
+ for info in peer_info :
99
+ assert_net_servicesnames (int (info [0 ]["services" ], 0x10 ), info [0 ]["servicesnames" ])
100
+
101
+ # Check dynamically generated networks list in getpeerinfo help output.
102
+ assert "(ipv4, ipv6, onion, i2p, not_publicly_routable)" in self .nodes [0 ].help ("getpeerinfo" )
103
+ # This part is slightly different comparing to the Bitcoin implementation. This is expected because we create connections on network setup a bit differently too.
104
+ # We also create more connection during the test itself to test mn specific stats
105
+ assert_equal (peer_info [0 ][0 ]['connection_type' ], 'inbound' )
106
+ assert_equal (peer_info [0 ][1 ]['connection_type' ], 'inbound' )
107
+ assert_equal (peer_info [0 ][2 ]['connection_type' ], 'manual' )
108
+
109
+ assert_equal (peer_info [1 ][0 ]['connection_type' ], 'manual' )
110
+ assert_equal (peer_info [1 ][1 ]['connection_type' ], 'inbound' )
111
+
112
+ assert_equal (peer_info [2 ][0 ]['connection_type' ], 'manual' )
113
+
114
+
78
115
def test_getnettotals (self ):
79
116
self .log .info ("Test getnettotals" )
80
117
# Test getnettotals and getpeerinfo by doing a ping. The bytes
@@ -113,15 +150,13 @@ def test_getnetworkinfo(self):
113
150
114
151
with self .nodes [0 ].assert_debug_log (expected_msgs = ['SetNetworkActive: true\n ' ]):
115
152
self .nodes [0 ].setnetworkactive (state = True )
116
- # Connect nodes both ways.
117
153
self .connect_nodes (0 , 1 )
118
- self .connect_nodes (1 , 0 )
119
154
120
155
info = self .nodes [1 ].getnetworkinfo ()
121
156
assert_equal (info ['networkactive' ], True )
122
- assert_equal (info ['connections' ], 2 )
157
+ assert_equal (info ['connections' ], 1 )
123
158
assert_equal (info ['connections_in' ], 1 )
124
- assert_equal (info ['connections_out' ], 1 )
159
+ assert_equal (info ['connections_out' ], 0 )
125
160
assert_equal (info ['connections_mn' ], 0 )
126
161
assert_equal (info ['connections_mn_in' ], 0 )
127
162
assert_equal (info ['connections_mn_out' ], 0 )
@@ -135,15 +170,17 @@ def test_getnetworkinfo(self):
135
170
assert "(ipv4, ipv6, onion, i2p)" in self .nodes [0 ].help ("getnetworkinfo" )
136
171
137
172
self .log .info ('Test extended connections info' )
138
- self .connect_nodes (1 , 2 )
173
+ # Connect nodes both ways.
174
+ self .connect_nodes (0 , 1 )
175
+ self .connect_nodes (1 , 0 )
139
176
self .nodes [1 ].ping ()
140
177
self .wait_until (lambda : all (['pingtime' in n for n in self .nodes [1 ].getpeerinfo ()]))
141
- assert_equal (self .nodes [1 ].getnetworkinfo ()['connections' ], 3 )
178
+ assert_equal (self .nodes [1 ].getnetworkinfo ()['connections' ], 2 )
142
179
assert_equal (self .nodes [1 ].getnetworkinfo ()['connections_in' ], 1 )
143
- assert_equal (self .nodes [1 ].getnetworkinfo ()['connections_out' ], 2 )
144
- assert_equal (self .nodes [1 ].getnetworkinfo ()['connections_mn' ], 1 )
180
+ assert_equal (self .nodes [1 ].getnetworkinfo ()['connections_out' ], 1 )
181
+ assert_equal (self .nodes [1 ].getnetworkinfo ()['connections_mn' ], 0 )
145
182
assert_equal (self .nodes [1 ].getnetworkinfo ()['connections_mn_in' ], 0 )
146
- assert_equal (self .nodes [1 ].getnetworkinfo ()['connections_mn_out' ], 1 )
183
+ assert_equal (self .nodes [1 ].getnetworkinfo ()['connections_mn_out' ], 0 )
147
184
148
185
def test_getaddednodeinfo (self ):
149
186
self .log .info ("Test getaddednodeinfo" )
@@ -165,40 +202,6 @@ def test_getaddednodeinfo(self):
165
202
# check that a non-existent node returns an error
166
203
assert_raises_rpc_error (- 24 , "Node has not been added" , self .nodes [0 ].getaddednodeinfo , '1.1.1.1' )
167
204
168
- def test_getpeerinfo (self ):
169
- self .log .info ("Test getpeerinfo" )
170
- # Create a few getpeerinfo last_block/last_transaction values.
171
- self .wallet .send_self_transfer (from_node = self .nodes [0 ]) # Make a transaction so we can see it in the getpeerinfo results
172
- self .nodes [1 ].generate (1 )
173
- self .sync_all ()
174
- time_now = self .mocktime
175
- peer_info = [x .getpeerinfo () for x in self .nodes ]
176
- # Verify last_block and last_transaction keys/values.
177
- for node , peer , field in product (range (self .num_nodes - self .mn_count ), range (2 ), ['last_block' , 'last_transaction' ]):
178
- assert field in peer_info [node ][peer ].keys ()
179
- if peer_info [node ][peer ][field ] != 0 :
180
- assert_approx (peer_info [node ][peer ][field ], time_now , vspan = 60 )
181
- # check both sides of bidirectional connection between nodes
182
- # the address bound to on one side will be the source address for the other node
183
- assert_equal (peer_info [0 ][0 ]['addrbind' ], peer_info [1 ][0 ]['addr' ])
184
- assert_equal (peer_info [1 ][0 ]['addrbind' ], peer_info [0 ][0 ]['addr' ])
185
- # check the `servicesnames` field
186
- for info in peer_info :
187
- assert_net_servicesnames (int (info [0 ]["services" ], 0x10 ), info [0 ]["servicesnames" ])
188
-
189
- # Check dynamically generated networks list in getpeerinfo help output.
190
- assert "(ipv4, ipv6, onion, i2p, not_publicly_routable)" in self .nodes [0 ].help ("getpeerinfo" )
191
- # This part is slightly different comparing to the Bitcoin implementation. This is expected because we create connections on network setup a bit differently too.
192
- # We also create more connection during the test itself to test mn specific stats
193
- assert_equal (peer_info [0 ][0 ]['connection_type' ], 'inbound' )
194
- assert_equal (peer_info [0 ][1 ]['connection_type' ], 'inbound' )
195
- assert_equal (peer_info [0 ][2 ]['connection_type' ], 'manual' )
196
-
197
- assert_equal (peer_info [1 ][0 ]['connection_type' ], 'manual' )
198
- assert_equal (peer_info [1 ][1 ]['connection_type' ], 'inbound' )
199
-
200
- assert_equal (peer_info [2 ][0 ]['connection_type' ], 'manual' )
201
-
202
205
def test_service_flags (self ):
203
206
self .log .info ("Test service flags" )
204
207
self .nodes [0 ].add_p2p_connection (P2PInterface (), services = (1 << 4 ) | (1 << 63 ))
0 commit comments