1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-01 20:08:26 +00:00

test(python): fix device tests

This commit is contained in:
M1nd3r 2024-11-26 15:57:24 +01:00
parent 285ed36378
commit e930a411f4
2 changed files with 20 additions and 18 deletions

View File

@ -33,9 +33,9 @@ def test_layout(client: Client):
@pytest.mark.models("legacy") @pytest.mark.models("legacy")
@pytest.mark.setup_client(mnemonic=MNEMONIC12) @pytest.mark.setup_client(mnemonic=MNEMONIC12)
def test_mnemonic(client: Client): def test_mnemonic(session: Session):
client.ensure_unlocked() session.ensure_unlocked()
mnemonic = client.debug.state().mnemonic_secret mnemonic = session.client.debug.state().mnemonic_secret
assert mnemonic == MNEMONIC12.encode() assert mnemonic == MNEMONIC12.encode()

View File

@ -19,6 +19,7 @@ import pytest
from trezorlib import device, exceptions, messages from trezorlib import device, exceptions, messages
from trezorlib.client import MAX_PIN_LENGTH from trezorlib.client import MAX_PIN_LENGTH
from trezorlib.debuglink import TrezorClientDebugLink as Client from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.debuglink import SessionDebugWrapper as Session
from trezorlib.tools import parse_path from trezorlib.tools import parse_path
PinType = messages.PinMatrixRequestType PinType = messages.PinMatrixRequestType
@ -109,15 +110,16 @@ def test_set_remove_wipe_code(client: Client):
assert client.features.wipe_code_protection is False assert client.features.wipe_code_protection is False
def test_set_wipe_code_mismatch(client: Client): def test_set_wipe_code_mismatch(session: Session):
# Check that there is no wipe code protection. # Check that there is no wipe code protection.
client.ensure_unlocked() session.ensure_unlocked()
assert client.features.wipe_code_protection is False session.refresh_features()
assert session.features.wipe_code_protection is False
# Let's set a new wipe code. # Let's set a new wipe code.
with client: with session.client as client, session:
client.use_pin_sequence([WIPE_CODE4, WIPE_CODE6]) client.use_pin_sequence([WIPE_CODE4, WIPE_CODE6])
client.set_expected_responses( session.set_expected_responses(
[ [
messages.ButtonRequest(), messages.ButtonRequest(),
messages.PinMatrixRequest(type=PinType.WipeCodeFirst), messages.PinMatrixRequest(type=PinType.WipeCodeFirst),
@ -126,10 +128,10 @@ def test_set_wipe_code_mismatch(client: Client):
] ]
) )
with pytest.raises(exceptions.TrezorFailure): with pytest.raises(exceptions.TrezorFailure):
device.change_wipe_code(client) device.change_wipe_code(session)
# Check that there is no wipe code protection. # Check that there is no wipe code protection.
client.init_device() client.refresh_features()
assert client.features.wipe_code_protection is False assert client.features.wipe_code_protection is False
@ -183,24 +185,24 @@ def test_set_pin_to_wipe_code(client: Client):
@pytest.mark.parametrize("invalid_wipe_code", ("1204", "", WIPE_CODE_TOO_LONG)) @pytest.mark.parametrize("invalid_wipe_code", ("1204", "", WIPE_CODE_TOO_LONG))
def test_set_wipe_code_invalid(client: Client, invalid_wipe_code): def test_set_wipe_code_invalid(session: Session, invalid_wipe_code):
# Let's set the wipe code # Let's set the wipe code
ret = client.call_raw(messages.ChangeWipeCode()) ret = session.call_raw(messages.ChangeWipeCode())
assert isinstance(ret, messages.ButtonRequest) assert isinstance(ret, messages.ButtonRequest)
# Confirm # Confirm
client.debug.press_yes() session.client.debug.press_yes()
ret = client.call_raw(messages.ButtonAck()) ret = session.call_raw(messages.ButtonAck())
# Enter a wipe code containing an invalid digit # Enter a wipe code containing an invalid digit
assert isinstance(ret, messages.PinMatrixRequest) assert isinstance(ret, messages.PinMatrixRequest)
assert ret.type == PinType.WipeCodeFirst assert ret.type == PinType.WipeCodeFirst
ret = client.call_raw(messages.PinMatrixAck(pin=invalid_wipe_code)) ret = session.call_raw(messages.PinMatrixAck(pin=invalid_wipe_code))
# Ensure the invalid wipe code is detected # Ensure the invalid wipe code is detected
assert isinstance(ret, messages.Failure) assert isinstance(ret, messages.Failure)
# Check that there's still no wipe code protection. # Check that there's still no wipe code protection.
client.init_device() session.refresh_features()
client.ensure_unlocked() session.ensure_unlocked()
assert client.features.wipe_code_protection is False assert session.features.wipe_code_protection is False