diff --git a/python/Makefile b/python/Makefile index c13fad930c..5926f59761 100644 --- a/python/Makefile +++ b/python/Makefile @@ -2,7 +2,7 @@ PYTHON=python3 SETUP=$(PYTHON) setup.py EXCLUDES=.vscode -STYLE_TARGETS=src/trezorlib setup.py +STYLE_TARGETS=src tests tools helper-scripts setup.py all: build @@ -45,7 +45,7 @@ git-clean: style: black $(STYLE_TARGETS) - isort --apply --recursive $(STYLE_TARGETS) + isort $(STYLE_TARGETS) autoflake -i --remove-all-unused-imports -r $(STYLE_TARGETS) flake8 make pyright diff --git a/python/tests/test_btc.py b/python/tests/test_btc.py index 37b75c1787..9aef4e5886 100644 --- a/python/tests/test_btc.py +++ b/python/tests/test_btc.py @@ -19,7 +19,6 @@ from decimal import Decimal from trezorlib import btc - # https://btc1.trezor.io/api/tx-specific/f5e735549daeb480d4348f2574b8967a4f149715edb220a742d8bb654d668348 TX_JSON_BIG = """ { @@ -217,7 +216,7 @@ def test_from_json(): assert i.sequence == v["sequence"] for v, o in zip(tx_dict["vout"], tx.bin_outputs): - assert o.amount == int(Decimal(v["value"]) * (10 ** 8)) + assert o.amount == int(Decimal(v["value"]) * (10**8)) assert o.script_pubkey.hex() == v["scriptPubKey"]["hex"] @@ -233,5 +232,5 @@ def test_coinbase_from_json(): coinbase = tx.inputs[0] assert coinbase.prev_hash == b"\x00" * 32 - assert coinbase.prev_index == 2 ** 32 - 1 + assert coinbase.prev_index == 2**32 - 1 assert coinbase.script_sig.hex() == tx_dict["vin"][0]["coinbase"] diff --git a/python/tests/test_firmware.py b/python/tests/test_firmware.py index 728be1966e..c3736705a6 100644 --- a/python/tests/test_firmware.py +++ b/python/tests/test_firmware.py @@ -6,9 +6,9 @@ import requests from trezorlib import firmware from trezorlib.firmware import ( - VendorFirmware, LegacyFirmware, LegacyV2Firmware, + VendorFirmware, VendorHeader, ) diff --git a/python/tests/test_merkle_tree.py b/python/tests/test_merkle_tree.py index 3f441d4c8b..7a9f3672e7 100644 --- a/python/tests/test_merkle_tree.py +++ b/python/tests/test_merkle_tree.py @@ -14,19 +14,18 @@ # You should have received a copy of the License along with this library. # If not, see . -import pytest - import typing as t -from trezorlib.merkle_tree import ( - MerkleTree, - Leaf, - Node, - leaf_hash, - internal_hash, - evaluate_proof, -) +import pytest +from trezorlib.merkle_tree import ( + Leaf, + MerkleTree, + Node, + evaluate_proof, + internal_hash, + leaf_hash, +) NODE_VECTORS = ( # node, expected_hash ( # leaf node diff --git a/python/tests/test_protobuf_encoding.py b/python/tests/test_protobuf_encoding.py index bb2d68b850..a8e9934d09 100644 --- a/python/tests/test_protobuf_encoding.py +++ b/python/tests/test_protobuf_encoding.py @@ -14,9 +14,9 @@ # You should have received a copy of the License along with this library. # If not, see . +import logging from enum import IntEnum from io import BytesIO -import logging import pytest @@ -90,7 +90,7 @@ class DefaultFields(protobuf.MessageType): class RecursiveMessage(protobuf.MessageType): FIELDS = { 1: protobuf.Field("uvarint", "uint64"), - 2: protobuf.Field("recursivefield", "RecursiveMessage", required=False) + 2: protobuf.Field("recursivefield", "RecursiveMessage", required=False), } @@ -170,7 +170,7 @@ def test_sint_uint(): # roundtrip: assert protobuf.uint_to_sint(protobuf.sint_to_uint(1234567891011)) == 1234567891011 - assert protobuf.uint_to_sint(protobuf.sint_to_uint(-(2 ** 32))) == -(2 ** 32) + assert protobuf.uint_to_sint(protobuf.sint_to_uint(-(2**32))) == -(2**32) def test_simple_message(): @@ -314,11 +314,8 @@ def test_recursive(): msg = RecursiveMessage( uvarint=1, recursivefield=RecursiveMessage( - uvarint=2, - recursivefield=RecursiveMessage( - uvarint=3 - ) - ) + uvarint=2, recursivefield=RecursiveMessage(uvarint=3) + ), ) buf = dump_message(msg) diff --git a/python/tests/test_stellar.py b/python/tests/test_stellar.py index 7aa3bebd10..143afc130f 100644 --- a/python/tests/test_stellar.py +++ b/python/tests/test_stellar.py @@ -20,10 +20,10 @@ try: from stellar_sdk import ( Account, Asset, + MuxedAccount, Network, TransactionBuilder, TrustLineEntryFlag, - MuxedAccount, ) from stellar_sdk.strkey import StrKey except ImportError: diff --git a/python/tests/test_tools.py b/python/tests/test_tools.py index d1b2e373d4..4edb2b3931 100644 --- a/python/tests/test_tools.py +++ b/python/tests/test_tools.py @@ -19,12 +19,30 @@ from trezorlib import tools def test_descriptor_checksum(): VECTOR = [ - ("pkh([5c9e228d/44'/0'/0']xpub6BiVtCpG9fQPxnPmHXG8PhtzQdWC2Su4qWu6XW9tpWFYhxydCLJGrWBJZ5H6qTAHdPQ7pQhtpjiYZVZARo14qHiay2fvrX996oEP42u8wZy/0/*)", "vzuemqzv"), - ("pkh([5c9e228d/44'/0'/0']xpub6BiVtCpG9fQPxnPmHXG8PhtzQdWC2Su4qWu6XW9tpWFYhxydCLJGrWBJZ5H6qTAHdPQ7pQhtpjiYZVZARo14qHiay2fvrX996oEP42u8wZy/1/*)", "akecx4j5"), - ("sh(wpkh([5c9e228d/49'/0'/0']xpub6CVKsQYXc9awxgV1tWbG4foDvdcnieK2JkbpPEBKB5WwAPKBZ1mstLbKVB4ov7QzxzjaxNK6EfmNY5Jsk2cG26EVcEkycGW4tchT2dyUhrx/0/*))", "jkfqtdfw"), - ("sh(wpkh([5c9e228d/49'/0'/0']xpub6CVKsQYXc9awxgV1tWbG4foDvdcnieK2JkbpPEBKB5WwAPKBZ1mstLbKVB4ov7QzxzjaxNK6EfmNY5Jsk2cG26EVcEkycGW4tchT2dyUhrx/1/*))", "8h8knju3"), - ("wpkh([5c9e228d/84'/0'/0']xpub6DDUPHpUo4pcy43iJeZjbSVWGav1SMMmuWdMHiGtkK8rhKmfbomtkwW6GKs1GGAKehT6QRocrmda3WWxXawpjmwaUHfFRXuKrXSapdckEYF/0/*)", "l4dc6ccr"), - ("wpkh([5c9e228d/84'/0'/0']xpub6DDUPHpUo4pcy43iJeZjbSVWGav1SMMmuWdMHiGtkK8rhKmfbomtkwW6GKs1GGAKehT6QRocrmda3WWxXawpjmwaUHfFRXuKrXSapdckEYF/1/*)", "wpge8dgm"), + ( + "pkh([5c9e228d/44'/0'/0']xpub6BiVtCpG9fQPxnPmHXG8PhtzQdWC2Su4qWu6XW9tpWFYhxydCLJGrWBJZ5H6qTAHdPQ7pQhtpjiYZVZARo14qHiay2fvrX996oEP42u8wZy/0/*)", + "vzuemqzv", + ), + ( + "pkh([5c9e228d/44'/0'/0']xpub6BiVtCpG9fQPxnPmHXG8PhtzQdWC2Su4qWu6XW9tpWFYhxydCLJGrWBJZ5H6qTAHdPQ7pQhtpjiYZVZARo14qHiay2fvrX996oEP42u8wZy/1/*)", + "akecx4j5", + ), + ( + "sh(wpkh([5c9e228d/49'/0'/0']xpub6CVKsQYXc9awxgV1tWbG4foDvdcnieK2JkbpPEBKB5WwAPKBZ1mstLbKVB4ov7QzxzjaxNK6EfmNY5Jsk2cG26EVcEkycGW4tchT2dyUhrx/0/*))", + "jkfqtdfw", + ), + ( + "sh(wpkh([5c9e228d/49'/0'/0']xpub6CVKsQYXc9awxgV1tWbG4foDvdcnieK2JkbpPEBKB5WwAPKBZ1mstLbKVB4ov7QzxzjaxNK6EfmNY5Jsk2cG26EVcEkycGW4tchT2dyUhrx/1/*))", + "8h8knju3", + ), + ( + "wpkh([5c9e228d/84'/0'/0']xpub6DDUPHpUo4pcy43iJeZjbSVWGav1SMMmuWdMHiGtkK8rhKmfbomtkwW6GKs1GGAKehT6QRocrmda3WWxXawpjmwaUHfFRXuKrXSapdckEYF/0/*)", + "l4dc6ccr", + ), + ( + "wpkh([5c9e228d/84'/0'/0']xpub6DDUPHpUo4pcy43iJeZjbSVWGav1SMMmuWdMHiGtkK8rhKmfbomtkwW6GKs1GGAKehT6QRocrmda3WWxXawpjmwaUHfFRXuKrXSapdckEYF/1/*)", + "wpge8dgm", + ), ] for d, c in VECTOR: assert tools.descriptor_checksum(d) == c diff --git a/python/tests/test_transport.py b/python/tests/test_transport.py index 9a5a747baa..78e36553a6 100644 --- a/python/tests/test_transport.py +++ b/python/tests/test_transport.py @@ -34,8 +34,8 @@ def test_disabled_transport(): def test_import_all_transports(): from trezorlib.transport.bridge import BridgeTransport from trezorlib.transport.hid import HidTransport - from trezorlib.transport.webusb import WebUsbTransport from trezorlib.transport.udp import UdpTransport + from trezorlib.transport.webusb import WebUsbTransport assert BridgeTransport assert HidTransport diff --git a/python/tools/deserialize_tx.py b/python/tools/deserialize_tx.py index 6430f4684a..0197f55bfd 100755 --- a/python/tools/deserialize_tx.py +++ b/python/tools/deserialize_tx.py @@ -48,11 +48,11 @@ class CompactUintAdapter(c.Adapter): def _encode(self, obj: int, context: Any, path: Any) -> dict: if obj < 0xFD: return {"base": obj} - if obj < 2 ** 16: + if obj < 2**16: return {"base": 0xFD, "ext": obj} - if obj < 2 ** 32: + if obj < 2**32: return {"base": 0xFE, "ext": obj} - if obj < 2 ** 64: + if obj < 2**64: return {"base": 0xFF, "ext": obj} raise ValueError("Value too big for compact uint") diff --git a/python/tools/pybridge.py b/python/tools/pybridge.py index d5cefb02fa..a9e75383a7 100644 --- a/python/tools/pybridge.py +++ b/python/tools/pybridge.py @@ -27,21 +27,21 @@ from gevent import monkey monkey.patch_all() import json +import logging import struct import time import typing as t -import logging import click -from bottle import run, post, request, response +from bottle import post, request, response, run -import trezorlib.transport import trezorlib.mapping import trezorlib.models +import trezorlib.transport from trezorlib.client import TrezorClient -from trezorlib.ui import TrezorClientUI from trezorlib.protobuf import format_message from trezorlib.transport.bridge import BridgeTransport +from trezorlib.ui import TrezorClientUI # ignore bridge. we are the bridge BridgeTransport.ENABLED = False diff --git a/python/tools/trezor-otp.py b/python/tools/trezor-otp.py index 929a9f745f..bc0b66daa9 100755 --- a/python/tools/trezor-otp.py +++ b/python/tools/trezor-otp.py @@ -22,6 +22,7 @@ import re import sys import pyotp + from trezorlib.client import TrezorClient from trezorlib.misc import decrypt_keyvalue, encrypt_keyvalue from trezorlib.tools import parse_path