mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-22 04:22:07 +00:00
fix(core): fix conflicts and style, part 1
[no changelog]
This commit is contained in:
parent
f00011d480
commit
2c61321857
@ -1,9 +1,12 @@
|
|||||||
|
from trezor.wire import message_handler
|
||||||
|
|
||||||
if not __debug__:
|
if not __debug__:
|
||||||
from trezor.utils import halt
|
from trezor.utils import halt
|
||||||
|
|
||||||
halt("debug mode inactive")
|
halt("debug mode inactive")
|
||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
|
import utime
|
||||||
from micropython import const
|
from micropython import const
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
@ -34,7 +37,7 @@ if __debug__:
|
|||||||
|
|
||||||
layout_change_chan = loop.mailbox()
|
layout_change_chan = loop.mailbox()
|
||||||
|
|
||||||
DEBUG_CONTEXT: context.CodecContext | None = None
|
DEBUG_CONTEXT: context.Context | None = None
|
||||||
|
|
||||||
REFRESH_INDEX = 0
|
REFRESH_INDEX = 0
|
||||||
|
|
||||||
@ -368,7 +371,7 @@ if __debug__:
|
|||||||
|
|
||||||
global DEBUG_CONTEXT
|
global DEBUG_CONTEXT
|
||||||
|
|
||||||
DEBUG_CONTEXT = ctx = context.Context(iface, 0, WIRE_BUFFER_DEBUG)
|
DEBUG_CONTEXT = ctx = context.CodecContext(iface, WIRE_BUFFER_DEBUG)
|
||||||
|
|
||||||
if storage.layout_watcher:
|
if storage.layout_watcher:
|
||||||
try:
|
try:
|
||||||
@ -393,14 +396,13 @@ if __debug__:
|
|||||||
msg_type = f"{msg.type} - unknown message type"
|
msg_type = f"{msg.type} - unknown message type"
|
||||||
log.debug(
|
log.debug(
|
||||||
__name__,
|
__name__,
|
||||||
"%s:%x receive: <%s>",
|
"%s receive: <%s>",
|
||||||
ctx.iface.iface_num(),
|
ctx.iface.iface_num(),
|
||||||
ctx.sid,
|
|
||||||
msg_type,
|
msg_type,
|
||||||
)
|
)
|
||||||
|
|
||||||
if msg.type not in WORKFLOW_HANDLERS:
|
if msg.type not in WORKFLOW_HANDLERS:
|
||||||
await ctx.write(wire.unexpected_message())
|
await ctx.write(message_handler.unexpected_message())
|
||||||
continue
|
continue
|
||||||
|
|
||||||
elif req_type is None:
|
elif req_type is None:
|
||||||
@ -411,7 +413,7 @@ if __debug__:
|
|||||||
await ctx.write(Success())
|
await ctx.write(Success())
|
||||||
continue
|
continue
|
||||||
|
|
||||||
req_msg = wire.wrap_protobuf_load(msg.data, req_type)
|
req_msg = message_handler.wrap_protobuf_load(msg.data, req_type)
|
||||||
try:
|
try:
|
||||||
res_msg = await WORKFLOW_HANDLERS[msg.type](req_msg)
|
res_msg = await WORKFLOW_HANDLERS[msg.type](req_msg)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
# pylint: disable=wrong-import-position
|
# pylint: disable=wrong-import-position
|
||||||
import utime
|
import utime
|
||||||
import trezorui2
|
|
||||||
from micropython import const
|
from micropython import const
|
||||||
from trezorui import Display
|
from trezorui import Display
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
import trezorui2
|
||||||
from trezor import io, log, loop, utils, workflow
|
from trezor import io, log, loop, utils, workflow
|
||||||
from trezor.messages import ButtonAck, ButtonRequest
|
from trezor.messages import ButtonAck, ButtonRequest
|
||||||
from trezor.wire import context
|
from trezor.wire import context
|
||||||
@ -295,7 +295,7 @@ class Layout(Generic[T]):
|
|||||||
|
|
||||||
def _paint(self) -> None:
|
def _paint(self) -> None:
|
||||||
"""Paint the layout and ensure that homescreen cache is properly invalidated."""
|
"""Paint the layout and ensure that homescreen cache is properly invalidated."""
|
||||||
import storage.cache as storage_cache
|
import storage.cache_common as storage_cache
|
||||||
|
|
||||||
painted = self.layout.paint()
|
painted = self.layout.paint()
|
||||||
if painted:
|
if painted:
|
||||||
@ -343,12 +343,13 @@ class Layout(Generic[T]):
|
|||||||
down the layout if appropriate, do nothing otherwise."""
|
down the layout if appropriate, do nothing otherwise."""
|
||||||
if msg is None:
|
if msg is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
# XXX DOES NOT WORK YET
|
# XXX DOES NOT WORK YET
|
||||||
if isinstance(msg, ButtonRequest):
|
if isinstance(msg, ButtonRequest):
|
||||||
# FIXME: special return value for "layout has changed"
|
# FIXME: special return value for "layout has changed"
|
||||||
# and the buttonrequest is an attribute on that value
|
# and the buttonrequest is an attribute on that value
|
||||||
from apps.debug import notify_layout_change
|
from apps.debug import notify_layout_change
|
||||||
|
|
||||||
notify_layout_change(self)
|
notify_layout_change(self)
|
||||||
|
|
||||||
# when emitting a message, there should not be another one already waiting
|
# when emitting a message, there should not be another one already waiting
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import storage.cache as storage_cache
|
import storage.cache_common as storage_cache
|
||||||
import trezorui2
|
import trezorui2
|
||||||
from trezor import TR, ui
|
from trezor import TR, ui
|
||||||
|
|
||||||
@ -41,7 +41,9 @@ class Homescreen(HomescreenBase):
|
|||||||
) -> None:
|
) -> None:
|
||||||
level = 1
|
level = 1
|
||||||
if notification is not None:
|
if notification is not None:
|
||||||
notification = notification.rstrip("!") # TODO handle TS5 that doesn't have it
|
notification = notification.rstrip(
|
||||||
|
"!"
|
||||||
|
) # TODO handle TS5 that doesn't have it
|
||||||
if notification == TR.homescreen__title_coinjoin_authorized:
|
if notification == TR.homescreen__title_coinjoin_authorized:
|
||||||
level = 3
|
level = 3
|
||||||
elif notification == TR.homescreen__title_experimental_mode:
|
elif notification == TR.homescreen__title_experimental_mode:
|
||||||
@ -121,11 +123,13 @@ class Busyscreen(HomescreenBase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
async def get_result(self) -> Any:
|
async def get_result(self) -> Any:
|
||||||
|
from trezor.wire import context
|
||||||
|
|
||||||
from apps.base import set_homescreen
|
from apps.base import set_homescreen
|
||||||
|
|
||||||
# Handle timeout.
|
# Handle timeout.
|
||||||
result = await super().get_result()
|
result = await super().get_result()
|
||||||
assert result == trezorui2.CANCELLED
|
assert result == trezorui2.CANCELLED
|
||||||
storage_cache.delete(storage_cache.APP_COMMON_BUSY_DEADLINE_MS)
|
context.cache_delete(storage_cache.APP_COMMON_BUSY_DEADLINE_MS)
|
||||||
set_homescreen()
|
set_homescreen()
|
||||||
return result
|
return result
|
||||||
|
@ -6,7 +6,7 @@ from trezor.enums import ButtonRequestType
|
|||||||
from trezor.messages import ButtonAck, ButtonRequest
|
from trezor.messages import ButtonAck, ButtonRequest
|
||||||
from trezor.wire import ActionCancelled, context
|
from trezor.wire import ActionCancelled, context
|
||||||
|
|
||||||
from ..common import raise_if_not_confirmed, interact, with_info, draw_simple
|
from ..common import draw_simple, interact, raise_if_not_confirmed, with_info
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import Any, Awaitable, Iterable, NoReturn, Sequence, TypeVar
|
from typing import Any, Awaitable, Iterable, NoReturn, Sequence, TypeVar
|
||||||
|
@ -8,7 +8,6 @@ from trezor.wire import ActionCancelled
|
|||||||
from ..common import interact
|
from ..common import interact
|
||||||
from . import raise_if_not_confirmed, show_success
|
from . import raise_if_not_confirmed, show_success
|
||||||
|
|
||||||
|
|
||||||
CONFIRMED = trezorui2.CONFIRMED # global_import_cache
|
CONFIRMED = trezorui2.CONFIRMED # global_import_cache
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ from trezor import TR, ui, utils
|
|||||||
from trezor.enums import ButtonRequestType
|
from trezor.enums import ButtonRequestType
|
||||||
from trezor.wire import ActionCancelled
|
from trezor.wire import ActionCancelled
|
||||||
|
|
||||||
from ..common import interact, raise_if_not_confirmed, draw_simple
|
from ..common import draw_simple, interact, raise_if_not_confirmed
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import Any, Awaitable, Iterable, NoReturn, Sequence
|
from typing import Any, Awaitable, Iterable, NoReturn, Sequence
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from typing import Sequence
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import trezorui2
|
import trezorui2
|
||||||
from trezor import TR
|
from trezor import TR
|
||||||
|
@ -5,7 +5,7 @@ from trezor import TR, ui, utils
|
|||||||
from trezor.enums import ButtonRequestType
|
from trezor.enums import ButtonRequestType
|
||||||
from trezor.wire import ActionCancelled
|
from trezor.wire import ActionCancelled
|
||||||
|
|
||||||
from ..common import interact, raise_if_not_confirmed, with_info, draw_simple
|
from ..common import draw_simple, interact, raise_if_not_confirmed, with_info
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import Awaitable, Iterable, NoReturn, Sequence
|
from typing import Awaitable, Iterable, NoReturn, Sequence
|
||||||
|
@ -6,7 +6,6 @@ from trezor.enums import ButtonRequestType
|
|||||||
|
|
||||||
from ..common import interact, raise_if_not_confirmed
|
from ..common import interact, raise_if_not_confirmed
|
||||||
|
|
||||||
|
|
||||||
CONFIRMED = trezorui2.CONFIRMED # global_import_cache
|
CONFIRMED = trezorui2.CONFIRMED # global_import_cache
|
||||||
|
|
||||||
|
|
||||||
@ -233,7 +232,7 @@ def slip39_prompt_threshold(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def slip39_prompt_number_of_shares(group_id: int | None = None) -> Awaitable[int]:
|
def slip39_prompt_number_of_shares(num_words: int, group_id: int | None = None) -> int:
|
||||||
count = 5
|
count = 5
|
||||||
min_count = 1
|
min_count = 1
|
||||||
max_count = 16
|
max_count = 16
|
||||||
|
@ -90,6 +90,8 @@ class CodecContext(Context):
|
|||||||
self, expected_types: Container[int], expected_type: type[LoadedMessageType]
|
self, expected_types: Container[int], expected_type: type[LoadedMessageType]
|
||||||
) -> LoadedMessageType: ...
|
) -> LoadedMessageType: ...
|
||||||
|
|
||||||
|
reading: bool = False
|
||||||
|
|
||||||
async def read(
|
async def read(
|
||||||
self,
|
self,
|
||||||
expected_types: Container[int],
|
expected_types: Container[int],
|
||||||
|
@ -4,7 +4,6 @@ from ubinascii import hexlify
|
|||||||
import trezorui2
|
import trezorui2
|
||||||
from trezor import loop, protobuf, workflow
|
from trezor import loop, protobuf, workflow
|
||||||
from trezor.crypto import random
|
from trezor.crypto import random
|
||||||
from trezor.ui.layouts.tt import RustLayout
|
|
||||||
from trezor.wire import context, message_handler, protocol_common
|
from trezor.wire import context, message_handler, protocol_common
|
||||||
from trezor.wire.context import UnexpectedMessageException
|
from trezor.wire.context import UnexpectedMessageException
|
||||||
from trezor.wire.errors import ActionCancelled, SilentError
|
from trezor.wire.errors import ActionCancelled, SilentError
|
||||||
@ -29,7 +28,7 @@ class PairingDisplayData:
|
|||||||
self.code_qr_code: bytes | None = None
|
self.code_qr_code: bytes | None = None
|
||||||
self.code_nfc_unidirectional: bytes | None = None
|
self.code_nfc_unidirectional: bytes | None = None
|
||||||
|
|
||||||
def get_display_layout(self) -> RustLayout:
|
def get_display_layout(self):
|
||||||
# TODO have different layouts when there is only QR code or only Code Entry
|
# TODO have different layouts when there is only QR code or only Code Entry
|
||||||
qr_str = ""
|
qr_str = ""
|
||||||
code_str = ""
|
code_str = ""
|
||||||
@ -38,16 +37,14 @@ class PairingDisplayData:
|
|||||||
if self.code_code_entry is not None:
|
if self.code_code_entry is not None:
|
||||||
code_str = self._get_code_code_entry_str()
|
code_str = self._get_code_code_entry_str()
|
||||||
|
|
||||||
return RustLayout(
|
return trezorui2.show_address_details( # noqa
|
||||||
trezorui2.show_address_details( # noqa
|
qr_title="Scan QR code to pair",
|
||||||
qr_title="Scan QR code to pair",
|
address=qr_str,
|
||||||
address=qr_str,
|
case_sensitive=True,
|
||||||
case_sensitive=True,
|
details_title="",
|
||||||
details_title="",
|
account="Code to rewrite:\n" + code_str,
|
||||||
account="Code to rewrite:\n" + code_str,
|
path="",
|
||||||
path="",
|
xpubs=[],
|
||||||
xpubs=[],
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def _get_code_code_entry_str(self) -> str:
|
def _get_code_code_entry_str(self) -> str:
|
||||||
|
@ -62,7 +62,9 @@ def tap_to_confirm(debug: "DebugLink") -> LayoutContent | None:
|
|||||||
elif debug.model in (models.T2B1,):
|
elif debug.model in (models.T2B1,):
|
||||||
return debug.read_layout() # type: ignore
|
return debug.read_layout() # type: ignore
|
||||||
elif debug.model in (models.T3T1,):
|
elif debug.model in (models.T3T1,):
|
||||||
return debug.click(buttons.TAP_TO_CONFIRM, )
|
return debug.click(
|
||||||
|
buttons.TAP_TO_CONFIRM,
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("Unknown model")
|
raise RuntimeError("Unknown model")
|
||||||
|
|
||||||
@ -120,11 +122,15 @@ def navigate_to_action_and_press(
|
|||||||
|
|
||||||
def unlock_gesture(debug: "DebugLink") -> LayoutContent | None:
|
def unlock_gesture(debug: "DebugLink") -> LayoutContent | None:
|
||||||
if debug.model in (models.T2T1,):
|
if debug.model in (models.T2T1,):
|
||||||
return debug.click(buttons.OK, ) # type: ignore
|
return debug.click(
|
||||||
|
buttons.OK,
|
||||||
|
) # type: ignore
|
||||||
elif debug.model in (models.T2B1,):
|
elif debug.model in (models.T2B1,):
|
||||||
return debug.press_right() # type: ignore
|
return debug.press_right() # type: ignore
|
||||||
elif debug.model in (models.T3T1,):
|
elif debug.model in (models.T3T1,):
|
||||||
return debug.click(buttons.TAP_TO_CONFIRM, ) # type: ignore
|
return debug.click(
|
||||||
|
buttons.TAP_TO_CONFIRM,
|
||||||
|
) # type: ignore
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("Unknown model")
|
raise RuntimeError("Unknown model")
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@ import pytest
|
|||||||
|
|
||||||
from trezorlib import device, messages, models
|
from trezorlib import device, messages, models
|
||||||
|
|
||||||
from ..common import EXTERNAL_ENTROPY, WITH_MOCK_URANDOM, generate_entropy
|
|
||||||
from .. import translations as TR
|
from .. import translations as TR
|
||||||
|
from ..common import EXTERNAL_ENTROPY, WITH_MOCK_URANDOM, generate_entropy
|
||||||
from . import reset
|
from . import reset
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -73,12 +73,16 @@ def test_backup_slip39_custom(
|
|||||||
groups=[(share_threshold, share_count)],
|
groups=[(share_threshold, share_count)],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# confirm backup configuration
|
# confirm backup configuration
|
||||||
if share_count > 1:
|
if share_count > 1:
|
||||||
TR.assert_template(debug.read_layout().text_content(), "reset__create_x_of_y_multi_share_backup_template")
|
TR.assert_template(
|
||||||
|
debug.read_layout().text_content(),
|
||||||
|
"reset__create_x_of_y_multi_share_backup_template",
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
TR.assert_template(debug.read_layout().text_content(), "backup__info_single_share_backup")
|
TR.assert_template(
|
||||||
|
debug.read_layout().text_content(), "backup__info_single_share_backup"
|
||||||
|
)
|
||||||
reset.confirm_read(debug)
|
reset.confirm_read(debug)
|
||||||
|
|
||||||
# confirm backup intro
|
# confirm backup intro
|
||||||
|
@ -20,8 +20,8 @@ import pytest
|
|||||||
|
|
||||||
from trezorlib import device, messages
|
from trezorlib import device, messages
|
||||||
|
|
||||||
from ..common import WITH_MOCK_URANDOM
|
|
||||||
from .. import translations as TR
|
from .. import translations as TR
|
||||||
|
from ..common import WITH_MOCK_URANDOM
|
||||||
from . import reset
|
from . import reset
|
||||||
from .common import go_next
|
from .common import go_next
|
||||||
|
|
||||||
|
@ -97,7 +97,9 @@ def test_reset_slip39_basic(
|
|||||||
raise RuntimeError("not a supported combination")
|
raise RuntimeError("not a supported combination")
|
||||||
|
|
||||||
# confirm checklist
|
# confirm checklist
|
||||||
TR.assert_in(debug.read_layout().text_content(), "reset__slip39_checklist_write_down")
|
TR.assert_in(
|
||||||
|
debug.read_layout().text_content(), "reset__slip39_checklist_write_down"
|
||||||
|
)
|
||||||
reset.confirm_read(debug)
|
reset.confirm_read(debug)
|
||||||
|
|
||||||
# confirm backup warning
|
# confirm backup warning
|
||||||
|
@ -429,7 +429,6 @@ def pytest_configure(config: "Config") -> None:
|
|||||||
IdMaker._idval_from_value = idval_from_value
|
IdMaker._idval_from_value = idval_from_value
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_runtest_setup(item: pytest.Item) -> None:
|
def pytest_runtest_setup(item: pytest.Item) -> None:
|
||||||
"""Called for each test item (class, individual tests).
|
"""Called for each test item (class, individual tests).
|
||||||
|
|
||||||
|
@ -468,7 +468,9 @@ class EthereumFlow:
|
|||||||
if self.client.model in (models.T2T1, models.T3T1):
|
if self.client.model in (models.T2T1, models.T3T1):
|
||||||
# confirm intro
|
# confirm intro
|
||||||
if info:
|
if info:
|
||||||
self.debug.click(buttons.CORNER_BUTTON, )
|
self.debug.click(
|
||||||
|
buttons.CORNER_BUTTON,
|
||||||
|
)
|
||||||
TR.assert_equals_multiple(
|
TR.assert_equals_multiple(
|
||||||
self.debug.read_layout().title(),
|
self.debug.read_layout().title(),
|
||||||
[
|
[
|
||||||
|
Loading…
Reference in New Issue
Block a user