test(core/thp): fix timeout handling in `device_tests/thp/test_basic.py`
What changed, and why it matters
This commit only adjusts a hardware test script so it waits longer for the device to respond and checks the correct error code. It does not change the actual Trezor firmware or fix any security bug in the product.
No security action needed; this is a test-only reliability fix.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies tests/device_tests/thp/test_basic.py. It increases a read timeout from 0.1 s to 1 s to accommodate MicroPython event-loop restart latency on real hardware, removes an explicit 0.1 s timeout from another read call (using the default), and updates an assertion to compare against the proper ThpErrorCode.UNALLOCATED_CHANNEL constant instead of a hardcoded byte value. No firmware code is changed.
Changed components
tests/device_tests/thp/test_basic.pyInspect captured patch +4 / −3
diff --git a/tests/device_tests/thp/test_basic.py b/tests/device_tests/thp/test_basic.py
index 06e2c624..61b76306 100644
--- a/tests/device_tests/thp/test_basic.py
+++ b/tests/device_tests/thp/test_basic.py
@@ -4,6 +4,7 @@ from trezorlib import messages, protocol_v1
from trezorlib.debuglink import TrezorTestContext as Client
from trezorlib.mapping import DEFAULT_MAPPING
from trezorlib.thp import control_byte, thp_io
+from trezorlib.thp.exceptions import ThpErrorCode
from trezorlib.thp.message import Message
from trezorlib.transport import Timeout, Transport
@@ -29,7 +30,7 @@ def test_v1(client: Client):
# There should be no response for continuation packet (starts with "?" only)
write_padded(client.transport, b"? Cont packet")
with pytest.raises(Timeout):
- client.transport.read_chunk(timeout=0.1)
+ client.transport.read_chunk(timeout=1)
def test_v2_unallocated(client: Client):
@@ -40,7 +41,7 @@ def test_v2_unallocated(client: Client):
data=bytes.fromhex("0011223344556677"),
)
write_padded(client.transport, message.to_bytes())
- response = thp_io.read(client.transport, timeout=0.1)
+ response = thp_io.read(client.transport)
assert response.cid == 0x789A
assert response.ctrl_byte == control_byte.ERROR
- assert response.data == b"\x02"
+ assert response.data == bytes([ThpErrorCode.UNALLOCATED_CHANNEL])
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.