diff --git a/core/src/apps/thp/pairing.py b/core/src/apps/thp/pairing.py index a14e4d032e..0f47e6b967 100644 --- a/core/src/apps/thp/pairing.py +++ b/core/src/apps/thp/pairing.py @@ -129,7 +129,7 @@ async def _prepare_pairing(ctx: PairingContext) -> None: async def show_display_data( ctx: PairingContext, expected_types: Container[int] = () ) -> type[protobuf.MessageType]: - from trezorui2 import CANCELLED + from trezorui_api import CANCELLED read_task = ctx.read(expected_types) cancel_task = ctx.display_data.get_display_layout() diff --git a/core/src/trezor/wire/thp/channel.py b/core/src/trezor/wire/thp/channel.py index 2e6b78ef89..e085163b2c 100644 --- a/core/src/trezor/wire/thp/channel.py +++ b/core/src/trezor/wire/thp/channel.py @@ -132,7 +132,7 @@ class Channel: # TODO Check CRC and if valid, check tag, if valid update nonces self._finish_fallback() # TODO self.write() failure device is busy - use channel buffer to send this failure message!! - return + return None return received_message_handler.handle_received_message(self, buffer) elif self.expected_payload_length + INIT_HEADER_LENGTH > self.bytes_read: self.is_cont_packet_expected = True diff --git a/core/src/trezor/wire/thp/pairing_context.py b/core/src/trezor/wire/thp/pairing_context.py index 34065b122f..02f8db3a8a 100644 --- a/core/src/trezor/wire/thp/pairing_context.py +++ b/core/src/trezor/wire/thp/pairing_context.py @@ -1,7 +1,7 @@ from typing import TYPE_CHECKING from ubinascii import hexlify -import trezorui2 +import trezorui_api from trezor import loop, protobuf, workflow from trezor.crypto import random from trezor.wire import context, message_handler, protocol_common @@ -42,7 +42,7 @@ class PairingDisplayData: code_str = self._get_code_code_entry_str() return ui.Layout( - trezorui2.show_address_details( # noqa + trezorui_api.show_address_details( # noqa qr_title="Scan QR code to pair", address=qr_str, case_sensitive=True, diff --git a/core/tests/test_apps.bitcoin.approver.py b/core/tests/test_apps.bitcoin.approver.py index 17a870df7f..408f96d7ee 100644 --- a/core/tests/test_apps.bitcoin.approver.py +++ b/core/tests/test_apps.bitcoin.approver.py @@ -1,3 +1,4 @@ +# flake8: noqa: F403,F405 from common import * # isort:skip import storage.cache_codec @@ -12,13 +13,13 @@ from trezor.messages import ( TxOutput, ) from trezor.wire import context +from trezor.wire.codec.codec_context import CodecContext from apps.bitcoin.authorization import FEE_RATE_DECIMALS, CoinJoinAuthorization from apps.bitcoin.sign_tx.approvers import CoinJoinApprover from apps.bitcoin.sign_tx.bitcoin import Bitcoin from apps.bitcoin.sign_tx.tx_info import TxInfo from apps.common import coins -from trezor.wire.codec.codec_context import CodecContext if utils.USE_THP: import thp_common diff --git a/core/tests/test_apps.bitcoin.authorization.py b/core/tests/test_apps.bitcoin.authorization.py index 4faf202989..aedcadba92 100644 --- a/core/tests/test_apps.bitcoin.authorization.py +++ b/core/tests/test_apps.bitcoin.authorization.py @@ -1,3 +1,4 @@ +# flake8: noqa: F403,F405 from common import * # isort:skip import storage.cache_codec diff --git a/core/tests/test_storage.cache.py b/core/tests/test_storage.cache.py index 8b426dd070..1e43e09d98 100644 --- a/core/tests/test_storage.cache.py +++ b/core/tests/test_storage.cache.py @@ -14,10 +14,11 @@ if utils.USE_THP: _PROTOCOL_CACHE = cache_thp else: + from mock_storage import mock_storage from storage import cache, cache_codec from trezor.messages import EndSession, Initialize + from apps.base import handle_EndSession - from mock_storage import mock_storage _PROTOCOL_CACHE = cache_codec @@ -319,8 +320,8 @@ class TestStorageCache(unittest.TestCase): else: def setUpClass(self): - from trezor.wire.codec.codec_context import CodecContext from trezor.wire import context + from trezor.wire.codec.codec_context import CodecContext context.CURRENT_CONTEXT = CodecContext(None, bytearray(64)) @@ -377,7 +378,7 @@ class TestStorageCache(unittest.TestCase): session_id = cache_codec.start_session() self.assertEqual(cache_codec.start_session(session_id), session_id) get_active_session().set(KEY, b"A") - for i in range(_PROTOCOL_CACHE._MAX_SESSIONS_COUNT): + for _ in range(_PROTOCOL_CACHE._MAX_SESSIONS_COUNT): cache_codec.start_session() self.assertNotEqual(cache_codec.start_session(session_id), session_id) self.assertIsNone(get_active_session().get(KEY)) diff --git a/core/tests/test_trezor.wire.thp.checksum.py b/core/tests/test_trezor.wire.thp.checksum.py index 41c9325001..f5d59d6805 100644 --- a/core/tests/test_trezor.wire.thp.checksum.py +++ b/core/tests/test_trezor.wire.thp.checksum.py @@ -1,3 +1,4 @@ +# flake8: noqa: F403,F405 from common import * # isort:skip if utils.USE_THP: diff --git a/core/tests/test_trezor.wire.thp.crypto.py b/core/tests/test_trezor.wire.thp.crypto.py index d26785ce65..1eee57f8cb 100644 --- a/core/tests/test_trezor.wire.thp.crypto.py +++ b/core/tests/test_trezor.wire.thp.crypto.py @@ -1,3 +1,4 @@ +# flake8: noqa: F403,F405 from common import * # isort:skip from trezorcrypto import aesgcm, curve25519 @@ -101,8 +102,8 @@ class TestTrezorHostProtocolCrypto(unittest.TestCase): def test_iv_from_nonce(self): for v in self.vectors_iv: - x = v[0] - y = x.to_bytes(8, "big") + # x = v[0] + # y = x.to_bytes(8, "big") iv = crypto._get_iv_from_nonce(v[0]) self.assertEqual(iv, v[1]) with self.assertRaises(AssertionError) as e: diff --git a/core/tests/test_trezor.wire.thp.py b/core/tests/test_trezor.wire.thp.py index 95f6cb6322..f4e0bce287 100644 --- a/core/tests/test_trezor.wire.thp.py +++ b/core/tests/test_trezor.wire.thp.py @@ -1,3 +1,4 @@ +# flake8: noqa: F403,F405 from common import * # isort:skip from mock_wire_interface import MockHID from trezor import config, io, protobuf @@ -28,8 +29,13 @@ if utils.USE_THP: ThpEndRequest, ThpStartPairingRequest, ) - from trezor.wire.thp import thp_main, memory_manager - from trezor.wire.thp import ChannelState, checksum, interface_manager + from trezor.wire.thp import ( + ChannelState, + checksum, + interface_manager, + memory_manager, + thp_main, + ) from trezor.wire.thp.crypto import Handshake from trezor.wire.thp.pairing_context import PairingContext @@ -251,7 +257,7 @@ class TestTrezorHostProtocol(unittest.TestCase): # test invalid tag in handshake phase cid_2 = get_channel_id_from_response(expected_response_1) - cid_2_bytes = cid_2.to_bytes(2, "big") + # cid_2_bytes = cid_2.to_bytes(2, "big") channel = thp_main._CHANNELS[cid_2] channel.iface = self.interface diff --git a/core/tests/test_trezor.wire.thp.writer.py b/core/tests/test_trezor.wire.thp.writer.py index 0e50f5c4b5..0f6110761a 100644 --- a/core/tests/test_trezor.wire.thp.writer.py +++ b/core/tests/test_trezor.wire.thp.writer.py @@ -1,13 +1,12 @@ +# flake8: noqa: F403,F405 from common import * # isort:skip from typing import Any, Awaitable - if utils.USE_THP: import thp_common from mock_wire_interface import MockHID - from trezor.wire.thp import writer - from trezor.wire.thp import ENCRYPTED, PacketHeader + from trezor.wire.thp import ENCRYPTED, PacketHeader, writer @unittest.skipUnless(utils.USE_THP, "only needed for THP") diff --git a/core/tests/test_trezor.wire.thp_deprecated.py b/core/tests/test_trezor.wire.thp_deprecated.py index 12ef40bb7e..49f2256e69 100644 --- a/core/tests/test_trezor.wire.thp_deprecated.py +++ b/core/tests/test_trezor.wire.thp_deprecated.py @@ -1,3 +1,4 @@ +# flake8: noqa: F403,F405 from common import * # isort:skip import ustruct from typing import TYPE_CHECKING @@ -11,9 +12,8 @@ from trezor.wire.protocol_common import Message if utils.USE_THP: import thp_common import trezor.wire.thp - from trezor.wire.thp import thp_main from trezor.wire.thp import alternating_bit_protocol as ABP - from trezor.wire.thp import checksum + from trezor.wire.thp import checksum, thp_main from trezor.wire.thp.checksum import CHECKSUM_LENGTH from trezor.wire.thp.writer import PACKET_LENGTH diff --git a/core/tests/thp_common.py b/core/tests/thp_common.py index d22243d29e..86a023d3c6 100644 --- a/core/tests/thp_common.py +++ b/core/tests/thp_common.py @@ -1,3 +1,4 @@ +# flake8: noqa: F403,F405 from trezor import utils from trezor.wire.thp import ChannelState