Skip to content

Commit 256120d

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#26519: test: Add getpeerinfo test for missing version message
fa68d08 test: Add getpeerinfo test for missing version message (MacroFake) Pull request description: There seems to be a lot of discussion about behaviour/code that is completely untested. Fix this by adding a test. The test documents the current behaviour and helps to detect when the behaviour changes in the future. ACKs for top commit: jonatack: ACK fa68d08 mzumsande: Code Review ACK fa68d08 Tree-SHA512: d092b30d5bdb46712c91a7c5bd2d0c82a0da281f1460967aa4e32c648b15d8d97870ded9565a90af34874eb468aad8b99694a2485af6807994e7cfc05482aa8c
2 parents b3c76ab + fa68d08 commit 256120d

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/functional/rpc_net.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,54 @@ def test_getpeerinfo(self):
107107
# Check dynamically generated networks list in getpeerinfo help output.
108108
assert "(ipv4, ipv6, onion, i2p, cjdns, not_publicly_routable)" in self.nodes[0].help("getpeerinfo")
109109

110+
self.log.info("Check getpeerinfo output before a version message was sent")
111+
no_version_peer_id = 2
112+
no_version_peer_conntime = int(time.time())
113+
self.nodes[0].setmocktime(no_version_peer_conntime)
114+
with self.nodes[0].assert_debug_log([f"Added connection peer={no_version_peer_id}"]):
115+
self.nodes[0].add_p2p_connection(P2PInterface(), send_version=False, wait_for_verack=False)
116+
self.nodes[0].setmocktime(0)
117+
peer_info = self.nodes[0].getpeerinfo()[no_version_peer_id]
118+
peer_info.pop("addr")
119+
peer_info.pop("addrbind")
120+
assert_equal(
121+
peer_info,
122+
{
123+
"addr_processed": 0,
124+
"addr_rate_limited": 0,
125+
"addr_relay_enabled": False,
126+
"bip152_hb_from": False,
127+
"bip152_hb_to": False,
128+
"bytesrecv": 0,
129+
"bytesrecv_per_msg": {},
130+
"bytessent": 0,
131+
"bytessent_per_msg": {},
132+
"connection_type": "inbound",
133+
"conntime": no_version_peer_conntime,
134+
"id": no_version_peer_id,
135+
"inbound": True,
136+
"inflight": [],
137+
"last_block": 0,
138+
"last_transaction": 0,
139+
"lastrecv": 0,
140+
"lastsend": 0,
141+
"minfeefilter": Decimal("0E-8"),
142+
"network": "not_publicly_routable",
143+
"permissions": [],
144+
"presynced_headers": -1,
145+
"relaytxes": False,
146+
"services": "0000000000000000",
147+
"servicesnames": [],
148+
"startingheight": -1,
149+
"subver": "",
150+
"synced_blocks": -1,
151+
"synced_headers": -1,
152+
"timeoffset": 0,
153+
"version": 0,
154+
},
155+
)
156+
self.nodes[0].disconnect_p2ps()
157+
110158
def test_getnettotals(self):
111159
self.log.info("Test getnettotals")
112160
# Test getnettotals and getpeerinfo by doing a ping. The bytes

0 commit comments

Comments
 (0)