Skip to content

Commit

Permalink
fix style after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
M1nd3r committed Dec 20, 2024
1 parent abbbbd0 commit 8256fc8
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion core/src/apps/thp/pairing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion core/src/trezor/wire/thp/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def receive_packet(self, packet: utils.BufferType) -> Awaitable[None] | None:
# 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
Expand Down
4 changes: 2 additions & 2 deletions core/src/trezor/wire/thp/pairing_context.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -42,7 +42,7 @@ def get_display_layout(self) -> ui.Layout:
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,
Expand Down
3 changes: 2 additions & 1 deletion core/tests/test_apps.bitcoin.approver.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa: F403,F405
from common import * # isort:skip

import storage.cache_codec
Expand All @@ -12,13 +13,13 @@
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
Expand Down
1 change: 1 addition & 0 deletions core/tests/test_apps.bitcoin.authorization.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa: F403,F405
from common import * # isort:skip

import storage.cache_codec
Expand Down
7 changes: 4 additions & 3 deletions core/tests/test_storage.cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
_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

Expand Down Expand Up @@ -319,8 +320,8 @@ def test_delete(self):
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))

Expand Down Expand Up @@ -377,7 +378,7 @@ def test_session_queue(self):
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))
Expand Down
1 change: 1 addition & 0 deletions core/tests/test_trezor.wire.thp.checksum.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa: F403,F405
from common import * # isort:skip

if utils.USE_THP:
Expand Down
5 changes: 3 additions & 2 deletions core/tests/test_trezor.wire.thp.crypto.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa: F403,F405
from common import * # isort:skip
from trezorcrypto import aesgcm, curve25519

Expand Down Expand Up @@ -101,8 +102,8 @@ def test_hkdf(self):

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:
Expand Down
12 changes: 9 additions & 3 deletions core/tests/test_trezor.wire.thp.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -28,8 +29,13 @@
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

Expand Down Expand Up @@ -251,7 +257,7 @@ def test_channel_errors(self):

# 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

Expand Down
5 changes: 2 additions & 3 deletions core/tests/test_trezor.wire.thp.writer.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
4 changes: 2 additions & 2 deletions core/tests/test_trezor.wire.thp_deprecated.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa: F403,F405
from common import * # isort:skip
import ustruct
from typing import TYPE_CHECKING
Expand All @@ -11,9 +12,8 @@
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

Expand Down
1 change: 1 addition & 0 deletions core/tests/thp_common.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa: F403,F405
from trezor import utils
from trezor.wire.thp import ChannelState

Expand Down

0 comments on commit 8256fc8

Please sign in to comment.