Skip to content

Commit 63e90e1

Browse files
committed
test: check for specific disconnect reasons in p2p_blockfilters.py
This ensures that the disconnect happens for the expected reason and also makes it easier to navigate between implementation and test code, i.e. both the questions "do we have test coverage for this disconnect?" (from an implementation reader's perspective) and "where is the code handling this disconnect?" (from a test reader's perspective) can be answered simply by grep-ping the corresponding debug message. Can be easiest reviewed with `-w` (to ignore whitespace changes).
1 parent d096743 commit 63e90e1

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

test/functional/p2p_blockfilters.py

+29-19
Original file line numberDiff line numberDiff line change
@@ -211,38 +211,48 @@ def run_test(self):
211211
]
212212
for request in requests:
213213
peer_1 = self.nodes[1].add_p2p_connection(P2PInterface())
214-
peer_1.send_message(request)
215-
peer_1.wait_for_disconnect()
214+
with self.nodes[1].assert_debug_log(expected_msgs=["requested unsupported block filter type"]):
215+
peer_1.send_message(request)
216+
peer_1.wait_for_disconnect()
216217

217218
self.log.info("Check that invalid requests result in disconnection.")
218219
requests = [
219220
# Requesting too many filters results in disconnection.
220-
msg_getcfilters(
221-
filter_type=FILTER_TYPE_BASIC,
222-
start_height=0,
223-
stop_hash=int(main_block_hash, 16),
221+
(
222+
msg_getcfilters(
223+
filter_type=FILTER_TYPE_BASIC,
224+
start_height=0,
225+
stop_hash=int(main_block_hash, 16),
226+
), "requested too many cfilters/cfheaders"
224227
),
225228
# Requesting too many filter headers results in disconnection.
226-
msg_getcfheaders(
227-
filter_type=FILTER_TYPE_BASIC,
228-
start_height=0,
229-
stop_hash=int(tip_hash, 16),
229+
(
230+
msg_getcfheaders(
231+
filter_type=FILTER_TYPE_BASIC,
232+
start_height=0,
233+
stop_hash=int(tip_hash, 16),
234+
), "requested too many cfilters/cfheaders"
230235
),
231236
# Requesting unknown filter type results in disconnection.
232-
msg_getcfcheckpt(
233-
filter_type=255,
234-
stop_hash=int(main_block_hash, 16),
237+
(
238+
msg_getcfcheckpt(
239+
filter_type=255,
240+
stop_hash=int(main_block_hash, 16),
241+
), "requested unsupported block filter type"
235242
),
236243
# Requesting unknown hash results in disconnection.
237-
msg_getcfcheckpt(
238-
filter_type=FILTER_TYPE_BASIC,
239-
stop_hash=123456789,
244+
(
245+
msg_getcfcheckpt(
246+
filter_type=FILTER_TYPE_BASIC,
247+
stop_hash=123456789,
248+
), "requested invalid block hash"
240249
),
241250
]
242-
for request in requests:
251+
for request, expected_log_msg in requests:
243252
peer_0 = self.nodes[0].add_p2p_connection(P2PInterface())
244-
peer_0.send_message(request)
245-
peer_0.wait_for_disconnect()
253+
with self.nodes[0].assert_debug_log(expected_msgs=[expected_log_msg]):
254+
peer_0.send_message(request)
255+
peer_0.wait_for_disconnect()
246256

247257
self.log.info("Test -peerblockfilters without -blockfilterindex raises an error")
248258
self.stop_node(0)

0 commit comments

Comments
 (0)