WIP: test: p2p: check v1 magic bytes only after the full header

bitcoin/bitcoin: PR #36730

1 suggestion

Optional improvements

Link

[suggestion] · The 24-byte rejection boundary lacks deterministic coverage

The parser now waits correctly for 24 bytes, but the existing downgrade test does not deterministically catch a return to rejecting wrong magic after four bytes.

Location: test/functional/test_framework/p2p.py:360 (head).

Details and suggested fix

p2p_v2_encrypted.py checks that the downgrade succeeds without controlling the node's sends. The old ordering can still pass when the node sends at least 24 bytes before the Python peer disconnects, since ShouldReconnectV1() tracks bytes sent rather than bytes received by Python.

Add a socket-free regression test using a P2PConnection subclass that captures on_message, initialized with peer_connect_helper('0', 0, 'regtest', 1). Feed a wrong-magic header to data_received one byte at a time and assert that bytes 1 through 23 do not raise, then byte 24 raises ValueError. Separately check that a fragmented valid message is delivered exactly once. Only the wrong-magic case distinguishes this change from the base ordering. If these tests live in p2p.py, register p2p in feature_framework_unit_tests.py.


Coverage details