2021-01-18 20:18:56 +00:00
|
|
|
# This file is part of the Trezor project.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2012-2021 SatoshiLabs and contributors
|
|
|
|
#
|
|
|
|
# This library is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
# as published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the License along with this library.
|
|
|
|
# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
|
|
|
|
|
|
|
|
import time
|
2022-10-25 10:46:37 +00:00
|
|
|
from typing import TYPE_CHECKING
|
2021-01-18 20:18:56 +00:00
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2024-03-09 21:05:05 +00:00
|
|
|
from trezorlib import models
|
2024-09-02 11:01:16 +00:00
|
|
|
from trezorlib.debuglink import LayoutType
|
2024-03-09 21:05:05 +00:00
|
|
|
|
2021-01-18 20:18:56 +00:00
|
|
|
from .. import buttons, common
|
|
|
|
|
2022-10-25 10:46:37 +00:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from ..device_handler import BackgroundDeviceHandler
|
|
|
|
|
|
|
|
|
2021-01-18 20:18:56 +00:00
|
|
|
PIN4 = "1234"
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.setup_client(pin=PIN4)
|
2022-10-25 10:46:37 +00:00
|
|
|
def test_hold_to_lock(device_handler: "BackgroundDeviceHandler"):
|
2021-01-18 20:18:56 +00:00
|
|
|
debug = device_handler.debuglink()
|
|
|
|
|
2024-03-09 21:05:05 +00:00
|
|
|
short_duration = {
|
|
|
|
models.T1B1: 500,
|
|
|
|
models.T2B1: 500,
|
2024-09-02 11:01:16 +00:00
|
|
|
models.T3B1: 500,
|
2024-03-09 21:05:05 +00:00
|
|
|
models.T2T1: 1000,
|
|
|
|
models.T3T1: 1000,
|
|
|
|
}[debug.model]
|
|
|
|
lock_duration = {
|
|
|
|
models.T1B1: 1200,
|
|
|
|
models.T2B1: 1200,
|
2024-09-02 11:01:16 +00:00
|
|
|
models.T3B1: 1200,
|
2024-03-09 21:05:05 +00:00
|
|
|
models.T2T1: 3500,
|
|
|
|
models.T3T1: 3500,
|
|
|
|
}[debug.model]
|
2023-05-04 12:16:40 +00:00
|
|
|
|
2023-11-21 12:51:59 +00:00
|
|
|
def hold(duration: int) -> None:
|
2024-09-02 11:01:16 +00:00
|
|
|
if debug.layout_type is LayoutType.TR:
|
2023-11-21 12:51:59 +00:00
|
|
|
debug.press_right(hold_ms=duration)
|
2023-05-12 09:19:35 +00:00
|
|
|
else:
|
2023-11-21 12:51:59 +00:00
|
|
|
debug.click((13, 37), hold_ms=duration)
|
2021-01-18 20:18:56 +00:00
|
|
|
|
|
|
|
assert device_handler.features().unlocked is False
|
|
|
|
|
|
|
|
# unlock with message
|
|
|
|
device_handler.run(common.get_test_address)
|
2023-05-04 12:16:40 +00:00
|
|
|
|
2023-11-21 12:51:59 +00:00
|
|
|
assert "PinKeyboard" in debug.read_layout().all_components()
|
|
|
|
debug.input("1234")
|
2021-01-18 20:18:56 +00:00
|
|
|
assert device_handler.result()
|
|
|
|
|
|
|
|
assert device_handler.features().unlocked is True
|
|
|
|
|
|
|
|
# short touch
|
2023-05-04 12:16:40 +00:00
|
|
|
hold(short_duration)
|
|
|
|
|
|
|
|
time.sleep(0.5) # so that the homescreen appears again (hacky)
|
2021-01-18 20:18:56 +00:00
|
|
|
assert device_handler.features().unlocked is True
|
|
|
|
|
|
|
|
# lock
|
2023-05-04 12:16:40 +00:00
|
|
|
hold(lock_duration)
|
2021-01-18 20:18:56 +00:00
|
|
|
assert device_handler.features().unlocked is False
|
|
|
|
|
|
|
|
# unlock by touching
|
2024-09-02 11:01:16 +00:00
|
|
|
if debug.layout_type is LayoutType.TR:
|
2023-11-21 15:55:46 +00:00
|
|
|
layout = debug.press_right()
|
2023-05-12 09:19:35 +00:00
|
|
|
else:
|
2023-11-21 12:51:59 +00:00
|
|
|
layout = debug.click(buttons.INFO)
|
2023-06-20 07:25:02 +00:00
|
|
|
assert "PinKeyboard" in layout.all_components()
|
2023-11-21 12:51:59 +00:00
|
|
|
debug.input("1234")
|
2021-01-18 20:18:56 +00:00
|
|
|
|
|
|
|
assert device_handler.features().unlocked is True
|
|
|
|
|
|
|
|
# lock
|
2023-05-04 12:16:40 +00:00
|
|
|
hold(lock_duration)
|
2021-01-18 20:18:56 +00:00
|
|
|
assert device_handler.features().unlocked is False
|