2022-08-11 09:47:30 +00:00
|
|
|
# This file is part of the Trezor project.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2022 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
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2024-09-02 11:01:16 +00:00
|
|
|
from trezorlib import btc, device
|
|
|
|
from trezorlib.debuglink import LayoutType
|
2022-08-11 09:47:30 +00:00
|
|
|
from trezorlib.debuglink import TrezorClientDebugLink as Client
|
|
|
|
from trezorlib.tools import parse_path
|
|
|
|
|
|
|
|
PIN = "1234"
|
|
|
|
|
|
|
|
|
2023-07-18 12:52:11 +00:00
|
|
|
def _assert_busy(client: Client, should_be_busy: bool, screen: str = "Homescreen"):
|
|
|
|
assert client.features.busy is should_be_busy
|
2024-09-02 11:01:16 +00:00
|
|
|
if client.layout_type is not LayoutType.T1:
|
2023-07-18 12:52:11 +00:00
|
|
|
if should_be_busy:
|
|
|
|
assert "CoinJoinProgress" in client.debug.read_layout().all_components()
|
|
|
|
else:
|
|
|
|
assert client.debug.read_layout().main_component() == screen
|
|
|
|
|
|
|
|
|
2022-08-11 09:47:30 +00:00
|
|
|
@pytest.mark.setup_client(pin=PIN)
|
|
|
|
def test_busy_state(client: Client):
|
2023-07-18 12:52:11 +00:00
|
|
|
_assert_busy(client, False, "Lockscreen")
|
2022-08-11 09:47:30 +00:00
|
|
|
assert client.features.unlocked is False
|
|
|
|
|
|
|
|
# Show busy dialog for 1 minute.
|
|
|
|
device.set_busy(client, expiry_ms=60 * 1000)
|
2023-07-18 12:52:11 +00:00
|
|
|
_assert_busy(client, True)
|
2022-08-11 09:47:30 +00:00
|
|
|
assert client.features.unlocked is False
|
|
|
|
|
|
|
|
with client:
|
|
|
|
client.use_pin_sequence([PIN])
|
|
|
|
btc.get_address(
|
|
|
|
client, "Bitcoin", parse_path("m/44h/0h/0h/0/0"), show_display=True
|
|
|
|
)
|
|
|
|
|
|
|
|
client.refresh_features()
|
2023-07-18 12:52:11 +00:00
|
|
|
_assert_busy(client, True)
|
2022-08-11 09:47:30 +00:00
|
|
|
assert client.features.unlocked is True
|
|
|
|
|
|
|
|
# Hide the busy dialog.
|
|
|
|
device.set_busy(client, None)
|
|
|
|
|
2023-07-18 12:52:11 +00:00
|
|
|
_assert_busy(client, False)
|
2022-08-11 09:47:30 +00:00
|
|
|
assert client.features.unlocked is True
|
|
|
|
|
|
|
|
|
2023-07-12 08:15:04 +00:00
|
|
|
@pytest.mark.flaky(max_runs=5)
|
2022-08-11 09:47:30 +00:00
|
|
|
def test_busy_expiry(client: Client):
|
2023-11-21 12:51:59 +00:00
|
|
|
WAIT_TIME_MS = 1500
|
|
|
|
TOLERANCE = 1000
|
|
|
|
|
2023-07-18 12:52:11 +00:00
|
|
|
_assert_busy(client, False)
|
2023-11-21 12:51:59 +00:00
|
|
|
# Start a timer
|
|
|
|
start = time.monotonic()
|
2022-08-11 09:47:30 +00:00
|
|
|
# Show the busy dialog.
|
2023-11-21 12:51:59 +00:00
|
|
|
device.set_busy(client, expiry_ms=WAIT_TIME_MS)
|
2023-07-18 12:52:11 +00:00
|
|
|
_assert_busy(client, True)
|
|
|
|
|
2023-11-21 12:51:59 +00:00
|
|
|
# Wait until the layout changes
|
|
|
|
client.debug.wait_layout()
|
|
|
|
end = time.monotonic()
|
2022-08-11 09:47:30 +00:00
|
|
|
|
2023-11-21 12:51:59 +00:00
|
|
|
# Check that the busy dialog was shown for at least WAIT_TIME_MS.
|
|
|
|
duration = (end - start) * 1000
|
|
|
|
assert WAIT_TIME_MS <= duration <= WAIT_TIME_MS + TOLERANCE
|
2022-08-11 09:47:30 +00:00
|
|
|
|
|
|
|
# Check that the device is no longer busy.
|
2023-07-18 12:52:11 +00:00
|
|
|
# Also needs to come back to Homescreen (for UI tests).
|
2022-08-11 09:47:30 +00:00
|
|
|
client.refresh_features()
|
2023-07-18 12:52:11 +00:00
|
|
|
_assert_busy(client, False)
|