diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index b837282e..dcfff578 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -1 +1,2 @@ 00323cbeb01d1a44b3843a963a54cbce7b6e0a2a +721d1b1efc7b6a96e0ea10aaf0a907294677b12d diff --git a/.github/workflows/build_and_functional_tests.yml b/.github/workflows/build_and_functional_tests.yml index 91689a6c..04ae55f4 100644 --- a/.github/workflows/build_and_functional_tests.yml +++ b/.github/workflows/build_and_functional_tests.yml @@ -41,7 +41,6 @@ jobs: with: download_app_binaries_artifact: "app_aleo_binaries" regenerate_snapshots: ${{ github.event_name == 'workflow_dispatch' && inputs.golden_run == 'Open a PR' }} - test_dir: "tests/standalone" tests_swap: name: Run swap tests using the reusable workflow diff --git a/.github/workflows/coding_style_checks.yml b/.github/workflows/coding_style_checks.yml index 45b04581..343047cf 100644 --- a/.github/workflows/coding_style_checks.yml +++ b/.github/workflows/coding_style_checks.yml @@ -21,4 +21,3 @@ jobs: uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_lint.yml@v1 with: source: './src' - extensions: 'h,c' diff --git a/.github/workflows/misspellings_checks.yml b/.github/workflows/misspellings_checks.yml index 8b7b497c..3f394bcd 100644 --- a/.github/workflows/misspellings_checks.yml +++ b/.github/workflows/misspellings_checks.yml @@ -18,4 +18,4 @@ jobs: name: Check misspellings uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_spell_check.yml@v1 with: - ignore_words_list: onTop,TE + ignore_words_list: onTop,TE diff --git a/.github/workflows/python_client_checks.yml b/.github/workflows/python_client_checks.yml index 512848aa..de4bf239 100644 --- a/.github/workflows/python_client_checks.yml +++ b/.github/workflows/python_client_checks.yml @@ -20,5 +20,5 @@ jobs: with: run_type_check: true src_directory: . - setup_directory: tests/application_client + setup_directory: tests req_directory: tests/standalone diff --git a/.github/workflows/unit_tests.yml b/.github/workflows/unit_tests.yml index 6809f435..1c948930 100644 --- a/.github/workflows/unit_tests.yml +++ b/.github/workflows/unit_tests.yml @@ -14,5 +14,3 @@ jobs: name: Call Ledger unit_test uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_unit_tests.yml@v1 secrets: inherit - with: - test_directory: unit-tests diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 585227e3..ad249b81 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,9 +4,10 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v5.0.0 + rev: v6.0.0 hooks: - id: trailing-whitespace + args: ['--markdown-linebreak-ext=md'] - id: end-of-file-fixer - id: mixed-line-ending - id: check-added-large-files @@ -14,35 +15,38 @@ repos: - id: check-case-conflict - repo: https://github.com/codespell-project/codespell - rev: v2.4.1 + rev: v2.4.2 hooks: - id: codespell + args: ['--ignore-words-list', 'onTop,TE'] - repo: https://github.com/pre-commit/mirrors-clang-format - rev: v14.0.6 + rev: v21.1.8 hooks: - id: clang-format types_or: [c] - repo: https://github.com/Mateusz-Grzelinski/actionlint-py - rev: v1.7.7.23 + rev: v1.7.12.24 hooks: - id: actionlint types_or: [yaml] args: [-shellcheck='' -pyflakes=''] - - repo: https://github.com/markdownlint/markdownlint - rev: v0.12.0 + - repo: https://github.com/DavidAnson/markdownlint-cli2 + rev: v0.22.1 hooks: - - id: markdownlint + - id: markdownlint-cli2 types_or: [markdown] + exclude: 'CHANGELOG\.md' - repo: https://github.com/astral-sh/ruff-pre-commit - # Ruff version. rev: v0.15.20 hooks: # Run the linter. - id: ruff-check - args: [ --fix ] + types_or: [python, pyi] + args: [--fix] # Run the formatter. - id: ruff-format + types_or: [python, pyi] diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 00000000..976ba029 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,2 @@ +[mypy] +ignore_missing_imports = True diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 00000000..efacbdd2 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +testpaths = tests/standalone +pythonpath = tests/standalone diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 00000000..8572cc06 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,19 @@ +target-version = "py311" +line-length = 130 + +# Vendored third-party packages: not our code to lint. +exclude = [ +] + +[lint] +select = [ + "E", # pycodestyle errors + "F", # pyflakes + "I", # isort + "B", # bugbear + "UP", # pyupgrade + "RUF", # ruff-native rules +] + +ignore = [ +] diff --git a/tests/application_client/bech32m.py b/tests/application_client/bech32m.py index edb8abf1..a2d8368f 100644 --- a/tests/application_client/bech32m.py +++ b/tests/application_client/bech32m.py @@ -59,9 +59,7 @@ def convert_bits( return True @staticmethod - def encode( - output: list[int], hrp: list[int], data: list[int], is_m_encoding: bool - ) -> bool: + def encode(output: list[int], hrp: list[int], data: list[int], is_m_encoding: bool) -> bool: chk = 1 for item in hrp: ch = item @@ -88,7 +86,7 @@ def encode( chk = BECH32M.polymod_step(chk) ^ item output.append(ord(BECH32M.CHARSET[item])) - for i in range(6): + for _ in range(6): chk = BECH32M.polymod_step(chk) chk ^= BECH32M.final_constant(is_m_encoding) for i in range(6): @@ -103,10 +101,7 @@ def decode(hrp: list[int], data: list[int], input_data: list[int]) -> bool: return False data_offset = 0 - while ( - data_offset < len(input_data) - and input_data[len(input_data) - 1 - data_offset] != 49 - ): + while data_offset < len(input_data) and input_data[len(input_data) - 1 - data_offset] != 49: data_offset += 1 hrp_len = len(input_data) - (1 + data_offset) diff --git a/tests/application_client/bigint_256.py b/tests/application_client/bigint_256.py index 34f6fbe6..a2eb739c 100644 --- a/tests/application_client/bigint_256.py +++ b/tests/application_client/bigint_256.py @@ -46,12 +46,7 @@ def is_even(self) -> bool: return not self.is_odd() def is_zero(self) -> bool: - return ( - self.value[0] == 0 - and self.value[1] == 0 - and self.value[2] == 0 - and self.value[3] == 0 - ) + return self.value[0] == 0 and self.value[1] == 0 and self.value[2] == 0 and self.value[3] == 0 def div2(self): t = 0 @@ -70,18 +65,10 @@ def add_carry_u64(c: int, a: int, b: int) -> tuple[int, int]: def add_nocarry(self, other) -> bool: carry = 0 - self.value[0], carry = BigInteger256.add_carry_u64( - carry, self.value[0], other.value[0] - ) - self.value[1], carry = BigInteger256.add_carry_u64( - carry, self.value[1], other.value[1] - ) - self.value[2], carry = BigInteger256.add_carry_u64( - carry, self.value[2], other.value[2] - ) - self.value[3], carry = BigInteger256.add_carry_u64( - carry, self.value[3], other.value[3] - ) + self.value[0], carry = BigInteger256.add_carry_u64(carry, self.value[0], other.value[0]) + self.value[1], carry = BigInteger256.add_carry_u64(carry, self.value[1], other.value[1]) + self.value[2], carry = BigInteger256.add_carry_u64(carry, self.value[2], other.value[2]) + self.value[3], carry = BigInteger256.add_carry_u64(carry, self.value[3], other.value[3]) return carry != 0 @staticmethod @@ -96,16 +83,8 @@ def subborrow_u64(c: int, a: int, b: int) -> tuple[int, int]: def sub_noborrow(self, other) -> bool: borrow = 0 - self.value[0], borrow = BigInteger256.subborrow_u64( - borrow, self.value[0], other.value[0] - ) - self.value[1], borrow = BigInteger256.subborrow_u64( - borrow, self.value[1], other.value[1] - ) - self.value[2], borrow = BigInteger256.subborrow_u64( - borrow, self.value[2], other.value[2] - ) - self.value[3], borrow = BigInteger256.subborrow_u64( - borrow, self.value[3], other.value[3] - ) + self.value[0], borrow = BigInteger256.subborrow_u64(borrow, self.value[0], other.value[0]) + self.value[1], borrow = BigInteger256.subborrow_u64(borrow, self.value[1], other.value[1]) + self.value[2], borrow = BigInteger256.subborrow_u64(borrow, self.value[2], other.value[2]) + self.value[3], borrow = BigInteger256.subborrow_u64(borrow, self.value[3], other.value[3]) return borrow != 0 diff --git a/tests/application_client/command_sender.py b/tests/application_client/command_sender.py index 9ee6cfa6..aa65c63f 100644 --- a/tests/application_client/command_sender.py +++ b/tests/application_client/command_sender.py @@ -75,14 +75,10 @@ def get_app_and_version(self) -> RAPDU: ) def get_version(self) -> RAPDU: - return self.backend.exchange( - cla=CLA, ins=InsType.CMD_GET_VERSION, p1=0x00, p2=0x00, data=b"" - ) + return self.backend.exchange(cla=CLA, ins=InsType.CMD_GET_VERSION, p1=0x00, p2=0x00, data=b"") def get_app_name(self) -> RAPDU: - return self.backend.exchange( - cla=CLA, ins=InsType.CMD_GET_APP_NAME, p1=0x00, p2=0x00, data=b"" - ) + return self.backend.exchange(cla=CLA, ins=InsType.CMD_GET_APP_NAME, p1=0x00, p2=0x00, data=b"") def get_address_without_confirmation(self, path: str) -> RAPDU: return self.backend.exchange( @@ -121,13 +117,9 @@ def get_tvk(self, tx_datas: dict) -> RAPDU: if len(apdus) != 0: for item in apdus[:-1]: apdu = bytes.fromhex(item) - self.backend.exchange( - cla=apdu[0], ins=apdu[1], p1=apdu[2], p2=apdu[3], data=apdu[5:] - ) + self.backend.exchange(cla=apdu[0], ins=apdu[1], p1=apdu[2], p2=apdu[3], data=apdu[5:]) apdu = bytes.fromhex(apdus[-1]) - return self.backend.exchange( - cla=apdu[0], ins=apdu[1], p1=apdu[2], p2=apdu[3], data=apdu[5:] - ) + return self.backend.exchange(cla=apdu[0], ins=apdu[1], p1=apdu[2], p2=apdu[3], data=apdu[5:]) return RAPDU(0x0000, b"") @contextmanager @@ -138,15 +130,12 @@ def sign_transaction(self, tx_datas: dict) -> Generator[None, None, None]: return for item in apdus[:-1]: apdu = bytes.fromhex(item) - self.backend.exchange( - cla=apdu[0], ins=apdu[1], p1=apdu[2], p2=apdu[3], data=apdu[5:] - ) + self.backend.exchange(cla=apdu[0], ins=apdu[1], p1=apdu[2], p2=apdu[3], data=apdu[5:]) apdu = bytes.fromhex(apdus[-1]) - with self.backend.exchange_async( - cla=apdu[0], ins=apdu[1], p1=apdu[2], p2=apdu[3], data=apdu[5:] - ) as response: + with self.backend.exchange_async(cla=apdu[0], ins=apdu[1], p1=apdu[2], p2=apdu[3], data=apdu[5:]) as response: yield response # Retrieve the last asynchronous response from the backend - def get_async_response(self) -> RAPDU | None: + def get_async_response(self) -> RAPDU: + assert self.backend.last_async_response is not None return self.backend.last_async_response diff --git a/tests/application_client/setup.cfg b/tests/application_client/setup.cfg index 7edf401e..f1b54e36 100644 --- a/tests/application_client/setup.cfg +++ b/tests/application_client/setup.cfg @@ -1,14 +1,2 @@ [tool:pytest] addopts = --strict-markers - -[pycodestyle] -max-line-length = 140 - -[mypy-hid.*] -ignore_missing_imports = True - -[mypy-pytest.*] -ignore_missing_imports = True - -[mypy-ledgered.*] -ignore_missing_imports = True diff --git a/tests/application_client/transaction.py b/tests/application_client/transaction.py index d29bd25a..e44f3563 100644 --- a/tests/application_client/transaction.py +++ b/tests/application_client/transaction.py @@ -91,13 +91,13 @@ def extract_tlv(tlv: str) -> tuple[TlvTypes, int, str, int]: else: t = Transaction.TlvTypes(0) - l = int(tlv[offset : offset + 2], base=16) + length = int(tlv[offset : offset + 2], base=16) offset += 2 - v = tlv[offset : offset + 2 * l] - offset += 2 * l + v = tlv[offset : offset + 2 * length] + offset += 2 * length - return t, l, v, offset + return t, length, v, offset @staticmethod def gen_chunks(lst: str, n: int) -> list[tuple]: @@ -138,9 +138,7 @@ def get_input_type_from_string(input_type: str) -> str: elif sp_input_type[-1] == "private": val += "02" + Transaction.get_plaintext_type_from_string(sp_input_type[0]) elif sp_input_type[-1] == "record": - val += ( - f"03{len(sp_input_type[0]):02x}{sp_input_type[0].encode('ascii').hex()}" - ) + val += f"03{len(sp_input_type[0]):02x}{sp_input_type[0].encode('ascii').hex()}" elif sp_input_type[-1] == "external_record": val += "04" elif sp_input_type[-1] == "merkle_proof": @@ -203,18 +201,14 @@ def generate_request(request: dict, is_root: bool) -> str: else: val += Transaction.forge_tlv(Transaction.TlvTypes.NETWORK_ID, "0001") # Program id - val += Transaction.forge_tlv( - Transaction.TlvTypes.PROGRAM_ID, f"{request['program_id'].encode().hex()}" - ) + val += Transaction.forge_tlv(Transaction.TlvTypes.PROGRAM_ID, f"{request['program_id'].encode().hex()}") # Function name val += Transaction.forge_tlv( Transaction.TlvTypes.FUNCTION_NAME, f"{request['function_name'].encode().hex()}", ) # Input count - val += Transaction.forge_tlv( - Transaction.TlvTypes.INPUT_COUNT, f"{len(request['inputs']):02x}" - ) + val += Transaction.forge_tlv(Transaction.TlvTypes.INPUT_COUNT, f"{len(request['inputs']):02x}") # Input values & types val += Transaction.generate_input(request["inputs"]) # Nested call count @@ -225,9 +219,7 @@ def generate_request(request: dict, is_root: bool) -> str: ) if "program_checksum" in request and len(request["program_checksum"]): - val += Transaction.forge_tlv( - Transaction.TlvTypes.PROGRAM_CHECKSUM, request["program_checksum"] - ) + val += Transaction.forge_tlv(Transaction.TlvTypes.PROGRAM_CHECKSUM, request["program_checksum"]) return val @@ -253,22 +245,16 @@ def gen_intent_apdu(self, tx: dict) -> list[str]: # Version req += Transaction.forge_tlv(Transaction.TlvTypes.VERSION, "01") # max_base_fee - req += Transaction.forge_tlv( - Transaction.TlvTypes.MAX_BASE_FEE, f"{tx['max_base_fee']:08x}" - ) + req += Transaction.forge_tlv(Transaction.TlvTypes.MAX_BASE_FEE, f"{tx['max_base_fee']:08x}") # max_priority_fee - req += Transaction.forge_tlv( - Transaction.TlvTypes.MAX_PRIORITY_FEE, f"{tx['max_priority_fee']:08x}" - ) + req += Transaction.forge_tlv(Transaction.TlvTypes.MAX_PRIORITY_FEE, f"{tx['max_priority_fee']:08x}") # fee_function_name req += Transaction.forge_tlv( Transaction.TlvTypes.FEE_FUNCTION_NAME, tx["fee_function_name"].encode().hex(), ) # fee_program_id - req += Transaction.forge_tlv( - Transaction.TlvTypes.FEE_PROGRAM_ID, tx["fee_program_id"].encode().hex() - ) + req += Transaction.forge_tlv(Transaction.TlvTypes.FEE_PROGRAM_ID, tx["fee_program_id"].encode().hex()) # request req += Transaction.forge_tlv( Transaction.TlvTypes.REQUEST, diff --git a/tests/standalone/test_app_mainmenu.py b/tests/standalone/test_app_mainmenu.py index 0efb708c..51bba38b 100644 --- a/tests/standalone/test_app_mainmenu.py +++ b/tests/standalone/test_app_mainmenu.py @@ -1,11 +1,11 @@ +from pathlib import Path + from ledgered.devices import Device, DeviceType from ragger.navigator import Navigator, NavInsID # In this test we check the behavior of the device main menu -def test_app_mainmenu( - device: Device, navigator: Navigator, test_name: str, default_screenshot_path: str -) -> None: +def test_app_mainmenu(device: Device, navigator: Navigator, test_name: str, default_screenshot_path: str) -> None: # Navigate in the main menu instructions = [] if device.is_nano: @@ -16,11 +16,7 @@ def test_app_mainmenu( NavInsID.RIGHT_CLICK, NavInsID.BOTH_CLICK, ] - elif ( - device.type is DeviceType.STAX - or device.type is DeviceType.FLEX - or device.type is DeviceType.APEX_P - ): + elif device.type is DeviceType.STAX or device.type is DeviceType.FLEX or device.type is DeviceType.APEX_P: instructions += [ NavInsID.USE_CASE_HOME_SETTINGS, NavInsID.USE_CASE_SETTINGS_MULTI_PAGE_EXIT, @@ -28,7 +24,7 @@ def test_app_mainmenu( assert len(instructions) > 0 navigator.navigate_and_compare( - default_screenshot_path, + Path(default_screenshot_path), test_name, instructions, screen_change_before_first_instruction=False, diff --git a/tests/standalone/test_get_address_cmd.py b/tests/standalone/test_get_address_cmd.py index 424e955b..2cecb046 100644 --- a/tests/standalone/test_get_address_cmd.py +++ b/tests/standalone/test_get_address_cmd.py @@ -39,9 +39,7 @@ def test_get_address_no_confirm(backend: BackendInterface) -> None: # In this test we check that the CMD_GET_ADDRESS works in confirmation mode -def test_get_address_confirm_accepted( - backend: BackendInterface, scenario_navigator: NavigateWithScenario -) -> None: +def test_get_address_confirm_accepted(backend: BackendInterface, scenario_navigator: NavigateWithScenario) -> None: client = CommandSender(backend) path = "m/44'/683'/0'/0'" with client.get_address_with_confirmation(path=path): @@ -50,16 +48,11 @@ def test_get_address_confirm_accepted( response = client.get_async_response().data _, address = unpack_get_address_response(response) - assert ( - address.decode("utf-8") - == "aleo1k7349nakx72h3q3gm8zg6f0dksnkp9p9ha93lrx6zu2gnvjzpyrsj28j54" - ) + assert address.decode("utf-8") == "aleo1k7349nakx72h3q3gm8zg6f0dksnkp9p9ha93lrx6zu2gnvjzpyrsj28j54" # In this test we check that the CMD_GET_ADDRESS in confirmation mode replies an error if the user refuses -def test_get_address_confirm_refused( - backend: BackendInterface, scenario_navigator: NavigateWithScenario -) -> None: +def test_get_address_confirm_refused(backend: BackendInterface, scenario_navigator: NavigateWithScenario) -> None: client = CommandSender(backend) path = "m/44'/683'/0'/0'" diff --git a/tests/standalone/test_get_view_key_cmd.py b/tests/standalone/test_get_view_key_cmd.py index e6a9ce87..bc713caf 100644 --- a/tests/standalone/test_get_view_key_cmd.py +++ b/tests/standalone/test_get_view_key_cmd.py @@ -7,9 +7,7 @@ # In this test we check that the CMD_GET_VIEW_KEY works in confirmation mode -def test_get_view_key_confirm_accepted( - backend: BackendInterface, scenario_navigator: NavigateWithScenario -) -> None: +def test_get_view_key_confirm_accepted(backend: BackendInterface, scenario_navigator: NavigateWithScenario) -> None: client = CommandSender(backend) path = "m/44'/683'/0'/0'" with client.get_view_key(path=path): @@ -18,16 +16,11 @@ def test_get_view_key_confirm_accepted( response = client.get_async_response().data _, address = unpack_get_view_key_response(response) - assert ( - address.decode("utf-8") - == "AViewKey1fnXDtDJz1Vr8hRFXa7ZxwWA37E3TX9MrQJei691gSJkA" - ) + assert address.decode("utf-8") == "AViewKey1fnXDtDJz1Vr8hRFXa7ZxwWA37E3TX9MrQJei691gSJkA" # In this test we check that the CMD_GET_VIEW_KEY in confirmation mode replies an error if the user refuses -def test_get_view_key_confirm_refused( - backend: BackendInterface, scenario_navigator: NavigateWithScenario -) -> None: +def test_get_view_key_confirm_refused(backend: BackendInterface, scenario_navigator: NavigateWithScenario) -> None: client = CommandSender(backend) path = "m/44'/683'/0'/0'" diff --git a/tests/standalone/test_sign_transaction.py b/tests/standalone/test_sign_transaction.py index 61b2109e..1c5127c9 100644 --- a/tests/standalone/test_sign_transaction.py +++ b/tests/standalone/test_sign_transaction.py @@ -1,3 +1,5 @@ +from typing import Any + import pytest from application_client.command_sender import CommandSender, InsType from application_client.response_unpacker import ( @@ -39,7 +41,7 @@ def forge_public_transfer( program_checksum: str = "", ) -> dict: - data = { + data: dict[str, Any] = { "type": "intent", "max_base_fee": max_base_fee, "max_priority_fee": max_priority_fee, @@ -70,7 +72,7 @@ def forge_private_transfer( program_checksum: str = "", ) -> dict: - data = { + data: dict[str, Any] = { "type": "intent", "max_base_fee": max_base_fee, "max_priority_fee": max_priority_fee, @@ -101,7 +103,7 @@ def forge_batch_private_transfer( amount: int, program_checksum: str = "", ) -> dict: - data = { + data: dict[str, Any] = { "type": "intent", "max_base_fee": max_base_fee, "max_priority_fee": max_priority_fee, @@ -125,10 +127,8 @@ def forge_batch_private_transfer( return data -def forge_nested_call_join( - r0: list[str], r1: list[str], program_id: str, program_checksum: str = "" -): - data = {"type": "nested_call"} +def forge_nested_call_join(r0: list[str], r1: list[str], program_id: str, program_checksum: str = ""): + data: dict[str, Any] = {"type": "nested_call"} data["request"] = { "network_id": "mainnet", "program_id": program_id, @@ -144,10 +144,8 @@ def forge_nested_call_join( return data -def forge_nested_call_private_transfer( - record: list[str], address_to: str, amount: int, program_checksum: str = "" -): - data = {"type": "nested_call"} +def forge_nested_call_private_transfer(record: list[str], address_to: str, amount: int, program_checksum: str = ""): + data: dict[str, Any] = {"type": "nested_call"} data["request"] = { "network_id": "mainnet", "program_id": "credits.aleo", @@ -173,7 +171,7 @@ def forge_arc22_token_public_transfer( program_checksum: str = "", ) -> dict: - data = { + data: dict[str, Any] = { "type": "intent", "max_base_fee": max_base_fee, "max_priority_fee": max_priority_fee, @@ -206,7 +204,7 @@ def forge_arc22_token_private_transfer( program_checksum: str = "", ) -> dict: - data = { + data: dict[str, Any] = { "type": "intent", "max_base_fee": max_base_fee, "max_priority_fee": max_priority_fee, @@ -240,7 +238,7 @@ def forge_arc22_token_batch_private_transfer( merkle_proof: list[str], program_checksum: str = "", ) -> dict: - data = { + data: dict[str, Any] = { "type": "intent", "max_base_fee": max_base_fee, "max_priority_fee": max_priority_fee, @@ -276,7 +274,7 @@ def forge_arc22_token_private_to_public_transfer( program_checksum: str = "", ) -> dict: - data = { + data: dict[str, Any] = { "type": "intent", "max_base_fee": max_base_fee, "max_priority_fee": max_priority_fee, @@ -309,7 +307,7 @@ def forge_arc22_token_public_to_private_transfer( program_checksum: str = "", ) -> dict: - data = { + data: dict[str, Any] = { "type": "intent", "max_base_fee": max_base_fee, "max_priority_fee": max_priority_fee, @@ -339,7 +337,7 @@ def forge_nested_call_arc22_token_private_transfer( merkle_proof: list[str], program_checksum: str = "", ) -> dict: - data = {"type": "nested_call"} + data: dict[str, Any] = {"type": "nested_call"} data["request"] = { "network_id": "mainnet", "program_id": program_name, @@ -357,10 +355,8 @@ def forge_nested_call_arc22_token_private_transfer( return data -def forge_public_fee( - base_fee: int, priority_fee: int, execution_id: str, program_checksum: str = "" -) -> dict: - data = {"type": "fee"} +def forge_public_fee(base_fee: int, priority_fee: int, execution_id: str, program_checksum: str = "") -> dict: + data: dict[str, Any] = {"type": "fee"} data["request"] = { "network_id": "mainnet", "program_id": "credits.aleo", @@ -384,7 +380,7 @@ def forge_private_fee( execution_id: str, program_checksum: str = "", ) -> dict: - data = {"type": "fee"} + data: dict[str, Any] = {"type": "fee"} data["request"] = { "network_id": "mainnet", "program_id": "credits.aleo", @@ -402,9 +398,7 @@ def forge_private_fee( return data -def test_sign_transaction_errors( - backend: BackendInterface, scenario_navigator: NavigateWithScenario -) -> None: +def test_sign_transaction_errors(backend: BackendInterface, scenario_navigator: NavigateWithScenario) -> None: client = CommandSender(backend) with pytest.raises(ExceptionRAPDU) as e: @@ -412,20 +406,14 @@ def test_sign_transaction_errors( assert e.value.status == StatusWords.SWO_WRONG_DATA_LENGTH with pytest.raises(ExceptionRAPDU) as e: - backend.exchange_raw( - bytes.fromhex("E006000013048000002c800000008000000080000000FFFF") - ) + backend.exchange_raw(bytes.fromhex("E006000013048000002c800000008000000080000000FFFF")) assert e.value.status == StatusWords.SWO_INSUFFICIENT_MEMORY with pytest.raises(ExceptionRAPDU) as e: - backend.exchange_raw( - bytes.fromhex("E006000113048000002c8000000080000000800000000000") - ) + backend.exchange_raw(bytes.fromhex("E006000113048000002c8000000080000000800000000000")) assert e.value.status == StatusWords.SWO_CONDITIONS_NOT_SATISFIED - backend.exchange_raw( - bytes.fromhex("E006000014048000002c800000008000000080000000000211") - ) + backend.exchange_raw(bytes.fromhex("E006000014048000002c800000008000000080000000000211")) with pytest.raises(ExceptionRAPDU) as e: backend.exchange_raw(bytes.fromhex("E0060001022233")) assert e.value.status == StatusWords.SWO_WRONG_DATA_LENGTH @@ -443,15 +431,11 @@ def test_sign_transaction_errors( assert e.value.status == StatusWords.SWO_CONDITIONS_NOT_SATISFIED with pytest.raises(ExceptionRAPDU) as e: - backend.exchange_raw( - bytes.fromhex("E0060000130b8000002c8000000080000000800000000000") - ) + backend.exchange_raw(bytes.fromhex("E0060000130b8000002c8000000080000000800000000000")) assert e.value.status == StatusWords.SWO_WRONG_DATA_LENGTH -def test_sign_transaction_refused( - backend: BackendInterface, scenario_navigator: NavigateWithScenario -) -> None: +def test_sign_transaction_refused(backend: BackendInterface, scenario_navigator: NavigateWithScenario) -> None: client = CommandSender(backend) tx_datas = forge_public_transfer( 500, @@ -474,7 +458,7 @@ def test_sign_transaction_refused( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Transaction rejected", timeout=3, screen_change_before_first_instruction=False, @@ -482,9 +466,7 @@ def test_sign_transaction_refused( ) -def test_sign_transaction_fee_timeout( - backend: BackendInterface, scenario_navigator: NavigateWithScenario -) -> None: +def test_sign_transaction_fee_timeout(backend: BackendInterface, scenario_navigator: NavigateWithScenario) -> None: client = CommandSender(backend) tx_datas = forge_public_transfer( 500, @@ -514,7 +496,7 @@ def test_sign_transaction_fee_timeout( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Fees signature", timeout=30, screen_change_before_first_instruction=False, @@ -522,9 +504,7 @@ def test_sign_transaction_fee_timeout( ) -def test_sign_transaction_wrong_fee( - backend: BackendInterface, scenario_navigator: NavigateWithScenario -) -> None: +def test_sign_transaction_wrong_fee(backend: BackendInterface, scenario_navigator: NavigateWithScenario) -> None: client = CommandSender(backend) tx_datas = forge_public_transfer( 500, @@ -561,9 +541,7 @@ def test_sign_transaction_wrong_fee( assert e.value.status == StatusWords.SWO_INCORRECT_DATA -def test_sign_transaction_transfer_public( - backend: BackendInterface, scenario_navigator: NavigateWithScenario -) -> None: +def test_sign_transaction_transfer_public(backend: BackendInterface, scenario_navigator: NavigateWithScenario) -> None: client = CommandSender(backend) tx_datas = forge_public_transfer( 500, @@ -600,7 +578,7 @@ def test_sign_transaction_transfer_public( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Transaction signed", timeout=3, screen_change_before_first_instruction=False, @@ -621,9 +599,7 @@ def test_sign_transaction_transfer_public( assert check_response(unpacked, expected) -def test_sign_transaction_transfer_private( - backend: BackendInterface, scenario_navigator: NavigateWithScenario -) -> None: +def test_sign_transaction_transfer_private(backend: BackendInterface, scenario_navigator: NavigateWithScenario) -> None: client = CommandSender(backend) record = [ "3614797564276936744957924747041031196891698846785520060979425601577054464500field", @@ -668,7 +644,7 @@ def test_sign_transaction_transfer_private( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Transaction signed", timeout=3, screen_change_before_first_instruction=False, @@ -690,9 +666,7 @@ def test_sign_transaction_transfer_private( assert check_response(unpacked, expected) -def test_sign_transaction_transfer_private_zero_fees( - backend: BackendInterface, scenario_navigator: NavigateWithScenario -) -> None: +def test_sign_transaction_transfer_private_zero_fees(backend: BackendInterface, scenario_navigator: NavigateWithScenario) -> None: client = CommandSender(backend) record = [ "3614797564276936744957924747041031196891698846785520060979425601577054464500field", @@ -725,9 +699,7 @@ def test_sign_transaction_transfer_private_zero_fees( assert check_response(unpacked, expected) -def test_sign_transaction_transfer_batch_private( - backend: BackendInterface, scenario_navigator: NavigateWithScenario -) -> None: +def test_sign_transaction_transfer_batch_private(backend: BackendInterface, scenario_navigator: NavigateWithScenario) -> None: client = CommandSender(backend) tx_datas = {"type": "get_tvk", "path": "m/44'/683'/0'/0'", "index": 0} @@ -791,7 +763,7 @@ def test_sign_transaction_transfer_batch_private( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Prepare Tx 10/15", timeout=3, screen_change_before_first_instruction=False, @@ -828,7 +800,7 @@ def test_sign_transaction_transfer_batch_private( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Calculating fees", timeout=3, screen_change_before_first_instruction=False, @@ -862,7 +834,7 @@ def test_sign_transaction_transfer_batch_private( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Transaction signed", timeout=3, screen_change_before_first_instruction=False, @@ -950,7 +922,7 @@ def test_sign_transaction_transfer_batch_private_zero_fees( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Prepare Tx 10/15", timeout=3, screen_change_before_first_instruction=False, @@ -987,7 +959,7 @@ def test_sign_transaction_transfer_batch_private_zero_fees( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Transaction signed", timeout=3, screen_change_before_first_instruction=False, @@ -1071,7 +1043,7 @@ def test_sign_transaction_transfer_batch_private_timeout( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Fees signature", timeout=20, screen_change_before_first_instruction=False, @@ -1162,7 +1134,7 @@ def test_sign_transaction_transfer_batch_private_wrong_nc( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Prepare Tx 10/15", timeout=3, screen_change_before_first_instruction=False, @@ -1204,7 +1176,7 @@ def test_sign_transaction_transfer_batch_private_wrong_nc( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Calculating fees", timeout=3, screen_change_before_first_instruction=False, @@ -1303,7 +1275,7 @@ def test_sign_transaction_transfer_batch_private_wrong_tvk( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Prepare Tx 10/15", timeout=3, screen_change_before_first_instruction=False, @@ -1394,9 +1366,7 @@ def test_get_tvk_derived_index_skip(backend: BackendInterface) -> None: # Skip index 1, request index 2 directly path_data = bytes.fromhex("048000002c800002ab8000000080000000") + bytes([2]) with pytest.raises(ExceptionRAPDU) as e: - backend.exchange( - cla=0xE0, ins=InsType.CMD_GET_TVK, p1=0x01, p2=0x00, data=path_data - ) + backend.exchange(cla=0xE0, ins=InsType.CMD_GET_TVK, p1=0x01, p2=0x00, data=path_data) assert e.value.status == StatusWords.SWO_INCORRECT_DATA @@ -1410,19 +1380,15 @@ def test_get_tvk_derived_missing_index_byte(backend: BackendInterface) -> None: # Send derived request with path only (no index byte) path_data = bytes.fromhex("048000002c800002ab8000000080000000") with pytest.raises(ExceptionRAPDU) as e: - backend.exchange( - cla=0xE0, ins=InsType.CMD_GET_TVK, p1=0x01, p2=0x00, data=path_data - ) + backend.exchange(cla=0xE0, ins=InsType.CMD_GET_TVK, p1=0x01, p2=0x00, data=path_data) assert e.value.status == StatusWords.SWO_INCORRECT_DATA -def test_sign_transaction_get_tvk_timeout( - backend: BackendInterface, scenario_navigator: NavigateWithScenario -) -> None: +def test_sign_transaction_get_tvk_timeout(backend: BackendInterface, scenario_navigator: NavigateWithScenario) -> None: client = CommandSender(backend) tx_datas = {"type": "get_tvk", "path": "m/44'/683'/0'/0'", "index": 0} - client.get_tvk(tx_datas=tx_datas).data + _ = client.get_tvk(tx_datas=tx_datas).data if scenario_navigator.device.is_nano: instruction = NavInsID.LEFT_CLICK @@ -1430,7 +1396,7 @@ def test_sign_transaction_get_tvk_timeout( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Aleo", timeout=15, screen_change_before_first_instruction=False, @@ -1438,9 +1404,7 @@ def test_sign_transaction_get_tvk_timeout( ) -def test_sign_transaction_token_arc22_unknown( - backend: BackendInterface, scenario_navigator: NavigateWithScenario -) -> None: +def test_sign_transaction_token_arc22_unknown(backend: BackendInterface, scenario_navigator: NavigateWithScenario) -> None: client = CommandSender(backend) tx_datas = forge_arc22_token_public_transfer( 500, @@ -1459,7 +1423,7 @@ def test_sign_transaction_token_arc22_unknown( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Transaction rejected", timeout=3, screen_change_before_first_instruction=False, @@ -1509,7 +1473,7 @@ def test_sign_transaction_token_arc22_transfer_public( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Transaction signed", timeout=3, screen_change_before_first_instruction=False, @@ -1539,9 +1503,7 @@ def test_sign_transaction_token_arc22_transfer_private( "2426895214035216932245297778850989035038538961658726507442215877484415082794field", "0220642863446832956019507279394572297489712696240584424406852292692897199577field", ] - merkle_proof = [ - "3614797564276936744957924747041031196891698846785520060979425601577054464500field" - ] * 34 + merkle_proof = ["3614797564276936744957924747041031196891698846785520060979425601577054464500field"] * 34 tx_datas = forge_arc22_token_private_transfer( 500, @@ -1583,7 +1545,7 @@ def test_sign_transaction_token_arc22_transfer_private( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Transaction signed", timeout=3, screen_change_before_first_instruction=False, @@ -1627,9 +1589,7 @@ def test_sign_transaction_token_arc22_transfer_batch_private( "d5f4b9312020d52c6752cb927e00771b300e8742e7cbe2cffe79a2a9f1641e03f1020000b6a58dc9bd8dc99591a5d1cd0503100019000000000000806381fe03232753113751635f57729543c73e2ab3641901f57fec18b1e560b28b80000000", "d5f4b9312020d52c6752cb927e00771b300e8742e7cbe2cffe79a2a9f1641e03f1020000b6a58dc9bd8dc99591a5d1cd0503100019000000000000c0eed4b40239bab0f49f52a8a88613dc6ea6aec32d2d23df9a005edf7d940ecfb980000000", ] - merkle_proof = [ - "3614797564276936744957924747041031196891698846785520060979425601577054464500field" - ] * 34 + merkle_proof = ["3614797564276936744957924747041031196891698846785520060979425601577054464500field"] * 34 tx_datas = forge_arc22_token_batch_private_transfer( 500, @@ -1677,7 +1637,7 @@ def test_sign_transaction_token_arc22_transfer_batch_private( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Prepare Tx 10/15", timeout=3, screen_change_before_first_instruction=False, @@ -1716,7 +1676,7 @@ def test_sign_transaction_token_arc22_transfer_batch_private( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Calculating fees", timeout=3, screen_change_before_first_instruction=False, @@ -1750,7 +1710,7 @@ def test_sign_transaction_token_arc22_transfer_batch_private( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Transaction signed", timeout=3, screen_change_before_first_instruction=False, @@ -1781,9 +1741,7 @@ def test_sign_transaction_token_arc22_transfer_private_to_public( "2426895214035216932245297778850989035038538961658726507442215877484415082794field", "0220642863446832956019507279394572297489712696240584424406852292692897199577field", ] - merkle_proof = [ - "3614797564276936744957924747041031196891698846785520060979425601577054464500field" - ] * 34 + merkle_proof = ["3614797564276936744957924747041031196891698846785520060979425601577054464500field"] * 34 tx_datas = forge_arc22_token_private_to_public_transfer( 500, @@ -1825,7 +1783,7 @@ def test_sign_transaction_token_arc22_transfer_private_to_public( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Transaction signed", timeout=3, screen_change_before_first_instruction=False, @@ -1887,7 +1845,7 @@ def test_sign_transaction_token_arc22_transfer_public_to_private( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Transaction signed", timeout=3, screen_change_before_first_instruction=False, @@ -1907,9 +1865,8 @@ def test_sign_transaction_token_arc22_transfer_public_to_private( } assert check_response(unpacked, expected) -def test_sign_transaction_fees_in_nested_call( - backend: BackendInterface, scenario_navigator: NavigateWithScenario -) -> None: + +def test_sign_transaction_fees_in_nested_call(backend: BackendInterface, scenario_navigator: NavigateWithScenario) -> None: client = CommandSender(backend) tx_datas = {"type": "get_tvk", "path": "m/44'/683'/0'/0'", "index": 0} @@ -1923,7 +1880,7 @@ def test_sign_transaction_fees_in_nested_call( tx_datas = {"type": "get_tvk", "path": "m/44'/683'/0'/0'", "index": 2} response = client.get_tvk(tx_datas=tx_datas).data unpacked = unpack_get_tvk_response(response) - tvk_2 = unpacked["tvk"] + _ = unpacked["tvk"] external_record = [ "d5f4b9312020d52c6752cb927e00771b300e8742e7cbe2cffe79a2a9f1641e03f1020000b6a58dc9bd8dc99591a5d1cd0503100019000000000000806381fe03232753113751635f57729543c73e2ab3641901f57fec18b1e560b28b80000000", @@ -1973,7 +1930,7 @@ def test_sign_transaction_fees_in_nested_call( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Prepare Tx 10/15", timeout=3, screen_change_before_first_instruction=False, @@ -2003,7 +1960,7 @@ def test_sign_transaction_fees_in_nested_call( record, "7266375125414209082394925781071362722506946030314916664133746682226945366259field", ) - tx_datas['type'] = 'nested_call' + tx_datas["type"] = "nested_call" with pytest.raises(ExceptionRAPDU) as e: with client.sign_transaction(tx_datas=tx_datas): if scenario_navigator.device.is_nano: @@ -2012,7 +1969,7 @@ def test_sign_transaction_fees_in_nested_call( instruction = NavInsID.USE_CASE_REVIEW_TAP scenario_navigator.navigator.navigate_until_text( navigate_instruction=instruction, - validation_instructions=None, + validation_instructions=[], text="Transaction signed", timeout=3, screen_change_before_first_instruction=False, diff --git a/tests/standalone/utils.py b/tests/standalone/utils.py index 7327e424..f25022a3 100644 --- a/tests/standalone/utils.py +++ b/tests/standalone/utils.py @@ -30,9 +30,7 @@ def verify_version(version: str) -> None: vers_dict = {} vers_str = "" lines = _read_makefile() - version_re = re.compile( - r"^APPVERSION_(?P\w)\s?=\s?(?P\d*)", re.IGNORECASE - ) + version_re = re.compile(r"^APPVERSION_(?P\w)\s?=\s?(?P\d*)", re.IGNORECASE) for line in lines: info = version_re.match(line) if info: @@ -50,6 +48,6 @@ def _read_makefile() -> list[str]: parent = Path(__file__).parent.parent.parent.resolve() makefile = f"{parent}/Makefile" - with open(makefile, "r", encoding="utf-8") as f_p: + with open(makefile, encoding="utf-8") as f_p: lines = f_p.readlines() return lines diff --git a/tests/swap/_helper_tool.py b/tests/swap/_helper_tool.py index d60af5be..37a068c8 100644 --- a/tests/swap/_helper_tool.py +++ b/tests/swap/_helper_tool.py @@ -36,9 +36,7 @@ } -def run_cmd( - cmd: str, cwd: Path = Path("."), print_output: bool = False, no_throw: bool = False -) -> str: +def run_cmd(cmd: str, cwd: Path = Path("."), print_output: bool = False, no_throw: bool = False) -> str: print(f"[run_cmd] Running: '{cmd}'' inside '{cwd}'") @@ -121,6 +119,6 @@ def clone_and_pull_ethereum(): def build_and_copy_ethereum(): build_app( APP_ETHEREUM_CLONE_DIR, - flags="COIN=ethereum CHAIN=ethereum CAL_TEST_KEY=1 DOMAIN_NAME_TEST_KEY=1 SET_PLUGIN_TEST_KEY=1 NFT_TEST_KEY=1 TRUSTED_NAME_TEST_KEY=1", + flags="COIN=ethereum CHAIN=ethereum CAL_TEST_KEY=1 DOMAIN_NAME_TEST_KEY=1 SET_PLUGIN_TEST_KEY=1 NFT_TEST_KEY=1 TRUSTED_NAME_TEST_KEY=1", # noqa: E501 ) copy_build_output(APP_ETHEREUM_CLONE_DIR, APP_ETHEREUM_DIR) diff --git a/tests/swap/test_aleo.py b/tests/swap/test_aleo.py index a5ea1bfd..d36e04aa 100644 --- a/tests/swap/test_aleo.py +++ b/tests/swap/test_aleo.py @@ -1,3 +1,5 @@ +from typing import Any + import pytest from application_client.command_sender import CommandSender from ledger_app_clients.exchange.test_runner import ( @@ -17,7 +19,7 @@ def forge_public_transfer( program_checksum: str = "", ) -> dict: - data = { + data: dict[str, Any] = { "type": "intent", "max_base_fee": max_base_fee, "max_priority_fee": max_priority_fee, @@ -39,10 +41,8 @@ def forge_public_transfer( return data -def forge_public_fee( - base_fee: int, priority_fee: int, execution_id: str, program_checksum: str = "" -) -> dict: - data = {"type": "fee"} +def forge_public_fee(base_fee: int, priority_fee: int, execution_id: str, program_checksum: str = "") -> dict: + data: dict[str, Any] = {"type": "fee"} data["request"] = { "network_id": "mainnet", "program_id": "credits.aleo", @@ -68,7 +68,7 @@ def forge_arc22_token_public_transfer( program_checksum: str = "", ) -> dict: - data = { + data: dict[str, Any] = { "type": "intent", "max_base_fee": max_base_fee, "max_priority_fee": max_priority_fee, @@ -94,15 +94,11 @@ class GenericAleoTests(ExchangeTestRunner): # The coin configuration of our currency. Replace by your own currency_configuration = cal.ALEO_CURRENCY_CONFIGURATION # A valid template address of a supposed trade partner. - valid_destination_1 = ( - "aleo1sfydt6z6cnqjx3hcgk9ajw03ecj6uqlfcm9u3p3gdhckzcc2w5xqv3v3pe" - ) + valid_destination_1 = "aleo1sfydt6z6cnqjx3hcgk9ajw03ecj6uqlfcm9u3p3gdhckzcc2w5xqv3v3pe" # A memo to use associated with the destination address if applicable. valid_destination_memo_1 = "" # A second valid template address of a supposed trade partner. - valid_destination_2 = ( - "aleo1ktwldl75earvxjur7devnqvdccjeuqa6807078klkg0a0l6ayq8qu9xzg4" - ) + valid_destination_2 = "aleo1ktwldl75earvxjur7devnqvdccjeuqa6807078klkg0a0l6ayq8qu9xzg4" # A second memo to use associated with the destination address if applicable. valid_destination_memo_2 = "" # The address of the Speculos seed on the ALEO_PATH. @@ -131,7 +127,7 @@ def perform_final_tx(self, destination, send_amount, fees, memo): tx_datas["path"] = "m/44'/683'/0'/0'" with client.sign_transaction(tx_datas=tx_datas): pass - rapdu = client.get_async_response() + _ = client.get_async_response() if fees != 0: tx_datas = forge_public_fee( @@ -141,7 +137,7 @@ def perform_final_tx(self, destination, send_amount, fees, memo): ) with client.sign_transaction(tx_datas=tx_datas): pass - rapdu = client.get_async_response() + _ = client.get_async_response() class ZeroFeeAleoTests(GenericAleoTests): @@ -158,13 +154,11 @@ class USADTokenTests(GenericAleoTests): def perform_final_tx(self, destination, send_amount, fees, memo): client = CommandSender(self.backend) - tx_datas = forge_arc22_token_public_transfer( - 0, fees, destination, send_amount, "usad_stablecoin.aleo" - ) + tx_datas = forge_arc22_token_public_transfer(0, fees, destination, send_amount, "usad_stablecoin.aleo") tx_datas["path"] = "m/44'/683'/0'/0'" with client.sign_transaction(tx_datas=tx_datas): pass - rapdu = client.get_async_response() + _ = client.get_async_response() if fees != 0: tx_datas = forge_public_fee( @@ -174,7 +168,7 @@ def perform_final_tx(self, destination, send_amount, fees, memo): ) with client.sign_transaction(tx_datas=tx_datas): pass - rapdu = client.get_async_response() + _ = client.get_async_response() class ZeroFeeUSADTokenTests(USADTokenTests): @@ -191,13 +185,11 @@ class FAKETokenTests2(GenericAleoTests): def perform_final_tx(self, destination, send_amount, fees, memo): client = CommandSender(self.backend) - tx_datas = forge_arc22_token_public_transfer( - 0, fees, destination, send_amount, "fake_stablecoin.aleo" - ) + tx_datas = forge_arc22_token_public_transfer(0, fees, destination, send_amount, "fake_stablecoin.aleo") tx_datas["path"] = "m/44'/683'/0'/0'" with client.sign_transaction(tx_datas=tx_datas): pass - rapdu = client.get_async_response() + _ = client.get_async_response() if fees != 0: tx_datas = forge_public_fee( @@ -207,7 +199,7 @@ def perform_final_tx(self, destination, send_amount, fees, memo): ) with client.sign_transaction(tx_datas=tx_datas): pass - rapdu = client.get_async_response() + _ = client.get_async_response() class TestsAleo: @@ -225,9 +217,7 @@ def test_aleo_swap_usad(self, backend, exchange_navigation_helper): USADTokenTests(backend, exchange_navigation_helper).run_test("swap_valid_1") def test_aleo_swap_usad_zero_fee(self, backend, exchange_navigation_helper): - ZeroFeeUSADTokenTests(backend, exchange_navigation_helper).run_test( - "swap_valid_1" - ) + ZeroFeeUSADTokenTests(backend, exchange_navigation_helper).run_test("swap_valid_1") def test_aleo_swap_fake_1(self, backend, exchange_navigation_helper): with pytest.raises(ExceptionRAPDU) as e: @@ -236,7 +226,5 @@ def test_aleo_swap_fake_1(self, backend, exchange_navigation_helper): def test_aleo_swap_fake_2(self, backend, exchange_navigation_helper): with pytest.raises(ExceptionRAPDU) as e: - FAKETokenTests2(backend, exchange_navigation_helper).run_test( - "swap_valid_1" - ) + FAKETokenTests2(backend, exchange_navigation_helper).run_test("swap_valid_1") assert e.value.status in [0xC000, 0x6A80] diff --git a/tools/python/algorithms/bhp.py b/tools/python/algorithms/bhp.py index b95c33b0..0de2687e 100644 --- a/tools/python/algorithms/bhp.py +++ b/tools/python/algorithms/bhp.py @@ -21,9 +21,9 @@ def __init__(self, F): self.F = F def get_lookup_base(self, path): - json_file = open(path, "r") + json_file = open(path) lookup_content = json.load(json_file) - json_file.close + json_file.close() lookup_base = [] @@ -54,7 +54,7 @@ def hash( input, input_total_bit_len, sum=None, - buff_init=[], + buff_init=None, base_start=0, input_start=0, ): @@ -65,17 +65,15 @@ def hash( for input_block_index in range(input_nb_of_block): if input_block_index == 0: if sum is None: - bhp_buffer += self.buffer_to_boolean( - self.F.DOMAIN, self.F.DOMAIN_SIZE_IN_BITS - ) + bhp_buffer += self.buffer_to_boolean(self.F.DOMAIN, self.F.DOMAIN_SIZE_IN_BITS) bhp_buffer += self.buffer_to_boolean(input, input_total_bit_len) + if buff_init is None: + buff_init = [] bhp_buffer = buff_init + bhp_buffer[input_start:] input_total_bit_len -= input_start if len(bhp_buffer) % self.BHP_CHUNK_SIZE: - for index in range( - self.BHP_CHUNK_SIZE - (len(bhp_buffer) % self.BHP_CHUNK_SIZE) - ): + for _index in range(self.BHP_CHUNK_SIZE - (len(bhp_buffer) % self.BHP_CHUNK_SIZE)): bhp_buffer.append(False) if sum is None: diff --git a/tools/python/algorithms/poseidon_default.py b/tools/python/algorithms/poseidon_default.py index 4b687046..2b07a360 100644 --- a/tools/python/algorithms/poseidon_default.py +++ b/tools/python/algorithms/poseidon_default.py @@ -1,3 +1,5 @@ +from typing import ClassVar + from crypto.field import Field @@ -42,7 +44,7 @@ def __init__( self.head = 0 - for i in range(160): + for _ in range(160): self.next_bit() def next_bit(self): @@ -82,7 +84,7 @@ def bits_to_int(self, bits): class PoseidonDefault: - params = { + params: ClassVar[dict] = { "2": {"alpha": 17, "full_rounds": 8, "partial_rounds": 31}, "3": {"alpha": 17, "full_rounds": 8, "partial_rounds": 31}, "4": {"alpha": 17, "full_rounds": 8, "partial_rounds": 31}, @@ -102,11 +104,11 @@ def __init__(self, rate): def get_field_elements_rejection_sampling(self, num_elements): output = [] - for i in range(num_elements): + for _ in range(num_elements): while True: bits = [] self.lfsr.it_init(Field.MODULUS_BITS) - for j in range(Field.MODULUS_BITS): + for _ in range(Field.MODULUS_BITS): bits.append(self.lfsr.it_next()) val = self.lfsr.bits_to_int(bits) if val < Field.MODULUS.to_int(): @@ -119,10 +121,10 @@ def get_field_elements_rejection_sampling(self, num_elements): def get_field_elements_mod_p(self, num_elems): output = [] num_bits = Field.MODULUS_BITS - for i in range(num_elems): + for _ in range(num_elems): bits = [] self.lfsr.it_init(num_bits) - for j in range(Field.MODULUS_BITS): + for _ in range(Field.MODULUS_BITS): bits.append(self.lfsr.it_next()) val = self.lfsr.bits_to_int(bits) val = val.to_bytes(32, byteorder="big") @@ -166,7 +168,7 @@ def find_poseidon_ark_and_mds(self): self.partial_rounds, ) ark = [] - for i in range(self.full_rounds + self.partial_rounds): + for _ in range(self.full_rounds + self.partial_rounds): output = self.get_field_elements_rejection_sampling(self.rate + 1) ark.append(output) diff --git a/tools/python/crypto/bigint_256.py b/tools/python/crypto/bigint_256.py index 0ddefc91..c64ad23d 100644 --- a/tools/python/crypto/bigint_256.py +++ b/tools/python/crypto/bigint_256.py @@ -46,12 +46,7 @@ def is_even(self) -> bool: return not self.is_odd() def is_zero(self) -> bool: - return ( - self.value[0] == 0 - and self.value[1] == 0 - and self.value[2] == 0 - and self.value[3] == 0 - ) + return self.value[0] == 0 and self.value[1] == 0 and self.value[2] == 0 and self.value[3] == 0 def div2(self): t = 0 @@ -69,18 +64,10 @@ def add_carry_u64(c: int, a: int, b: int): def add_nocarry(self, other) -> bool: carry = 0 - self.value[0], carry = BigInteger256.add_carry_u64( - carry, self.value[0], other.value[0] - ) - self.value[1], carry = BigInteger256.add_carry_u64( - carry, self.value[1], other.value[1] - ) - self.value[2], carry = BigInteger256.add_carry_u64( - carry, self.value[2], other.value[2] - ) - self.value[3], carry = BigInteger256.add_carry_u64( - carry, self.value[3], other.value[3] - ) + self.value[0], carry = BigInteger256.add_carry_u64(carry, self.value[0], other.value[0]) + self.value[1], carry = BigInteger256.add_carry_u64(carry, self.value[1], other.value[1]) + self.value[2], carry = BigInteger256.add_carry_u64(carry, self.value[2], other.value[2]) + self.value[3], carry = BigInteger256.add_carry_u64(carry, self.value[3], other.value[3]) return carry != 0 def subborrow_u64(c: int, a: int, b: int): @@ -94,18 +81,10 @@ def subborrow_u64(c: int, a: int, b: int): def sub_noborrow(self, other) -> bool: borrow = 0 - self.value[0], borrow = BigInteger256.subborrow_u64( - borrow, self.value[0], other.value[0] - ) - self.value[1], borrow = BigInteger256.subborrow_u64( - borrow, self.value[1], other.value[1] - ) - self.value[2], borrow = BigInteger256.subborrow_u64( - borrow, self.value[2], other.value[2] - ) - self.value[3], borrow = BigInteger256.subborrow_u64( - borrow, self.value[3], other.value[3] - ) + self.value[0], borrow = BigInteger256.subborrow_u64(borrow, self.value[0], other.value[0]) + self.value[1], borrow = BigInteger256.subborrow_u64(borrow, self.value[1], other.value[1]) + self.value[2], borrow = BigInteger256.subborrow_u64(borrow, self.value[2], other.value[2]) + self.value[3], borrow = BigInteger256.subborrow_u64(borrow, self.value[3], other.value[3]) return borrow != 0 def print_int(self): diff --git a/tools/python/crypto/codecs/bech32m.py b/tools/python/crypto/codecs/bech32m.py index cbb42cf4..0ed66900 100644 --- a/tools/python/crypto/codecs/bech32m.py +++ b/tools/python/crypto/codecs/bech32m.py @@ -1,8 +1,11 @@ +from typing import ClassVar + + class BECH32M: CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l" # fmt: off - CHARSET_REVERSED = [ + CHARSET_REVERSED: ClassVar[list] = [ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 15, -1, 10, 17, 21, 20, 26, 30, 7, 5, -1, -1, -1, -1, -1, -1, -1, 29, -1, 24, 13, 25, 9, 8, 23, -1, 18, 22, 31, 27, @@ -52,9 +55,7 @@ def convert_bits( return True - def encode( - output: list[int], hrp: list[int], data: list[int], is_m_encoding: bool - ) -> bool: + def encode(output: list[int], hrp: list[int], data: list[int], is_m_encoding: bool) -> bool: chk = 1 for item in hrp: ch = item @@ -81,7 +82,7 @@ def encode( chk = BECH32M.polymod_step(chk) ^ data[i] output.append(ord(BECH32M.CHARSET[data[i]])) - for i in range(6): + for _ in range(6): chk = BECH32M.polymod_step(chk) chk ^= BECH32M.final_constant(is_m_encoding) for i in range(6): diff --git a/tools/python/crypto/fp_256.py b/tools/python/crypto/fp_256.py index 9468c317..fdca99a7 100644 --- a/tools/python/crypto/fp_256.py +++ b/tools/python/crypto/fp_256.py @@ -51,94 +51,62 @@ def mul_assign(self, other): carry2 = 0 # Iteration 0 - r[0], carry1 = self.mac_with_carry( - r[0], self.value.value[0], other.value.value[0], 0 - ) + r[0], carry1 = self.mac_with_carry(r[0], self.value.value[0], other.value.value[0], 0) k = (r[0] * self.F.INV) % 0x10000000000000000 _, carry2 = self.mac_with_carry(r[0], k, self.F.MODULUS.value[0], 0) - r[1], carry1 = self.mac_with_carry( - r[1], self.value.value[1], other.value.value[0], carry1 - ) + r[1], carry1 = self.mac_with_carry(r[1], self.value.value[1], other.value.value[0], carry1) r[0], carry2 = self.mac_with_carry(r[1], k, self.F.MODULUS.value[1], carry2) - r[2], carry1 = self.mac_with_carry( - r[2], self.value.value[2], other.value.value[0], carry1 - ) + r[2], carry1 = self.mac_with_carry(r[2], self.value.value[2], other.value.value[0], carry1) r[1], carry2 = self.mac_with_carry(r[2], k, self.F.MODULUS.value[2], carry2) - r[3], carry1 = self.mac_with_carry( - r[3], self.value.value[3], other.value.value[0], carry1 - ) + r[3], carry1 = self.mac_with_carry(r[3], self.value.value[3], other.value.value[0], carry1) r[2], carry2 = self.mac_with_carry(r[3], k, self.F.MODULUS.value[3], carry2) r[3] = carry1 + carry2 # Iteration 2 - r[0], carry1 = self.mac_with_carry( - r[0], self.value.value[0], other.value.value[1], 0 - ) + r[0], carry1 = self.mac_with_carry(r[0], self.value.value[0], other.value.value[1], 0) k = (r[0] * self.F.INV) % 0x10000000000000000 _, carry2 = self.mac_with_carry(r[0], k, self.F.MODULUS.value[0], 0) - r[1], carry1 = self.mac_with_carry( - r[1], self.value.value[1], other.value.value[1], carry1 - ) + r[1], carry1 = self.mac_with_carry(r[1], self.value.value[1], other.value.value[1], carry1) r[0], carry2 = self.mac_with_carry(r[1], k, self.F.MODULUS.value[1], carry2) - r[2], carry1 = self.mac_with_carry( - r[2], self.value.value[2], other.value.value[1], carry1 - ) + r[2], carry1 = self.mac_with_carry(r[2], self.value.value[2], other.value.value[1], carry1) r[1], carry2 = self.mac_with_carry(r[2], k, self.F.MODULUS.value[2], carry2) - r[3], carry1 = self.mac_with_carry( - r[3], self.value.value[3], other.value.value[1], carry1 - ) + r[3], carry1 = self.mac_with_carry(r[3], self.value.value[3], other.value.value[1], carry1) r[2], carry2 = self.mac_with_carry(r[3], k, self.F.MODULUS.value[3], carry2) r[3] = carry1 + carry2 # Iteration 2 - r[0], carry1 = self.mac_with_carry( - r[0], self.value.value[0], other.value.value[2], 0 - ) + r[0], carry1 = self.mac_with_carry(r[0], self.value.value[0], other.value.value[2], 0) k = (r[0] * self.F.INV) % 0x10000000000000000 _, carry2 = self.mac_with_carry(r[0], k, self.F.MODULUS.value[0], 0) - r[1], carry1 = self.mac_with_carry( - r[1], self.value.value[1], other.value.value[2], carry1 - ) + r[1], carry1 = self.mac_with_carry(r[1], self.value.value[1], other.value.value[2], carry1) r[0], carry2 = self.mac_with_carry(r[1], k, self.F.MODULUS.value[1], carry2) - r[2], carry1 = self.mac_with_carry( - r[2], self.value.value[2], other.value.value[2], carry1 - ) + r[2], carry1 = self.mac_with_carry(r[2], self.value.value[2], other.value.value[2], carry1) r[1], carry2 = self.mac_with_carry(r[2], k, self.F.MODULUS.value[2], carry2) - r[3], carry1 = self.mac_with_carry( - r[3], self.value.value[3], other.value.value[2], carry1 - ) + r[3], carry1 = self.mac_with_carry(r[3], self.value.value[3], other.value.value[2], carry1) r[2], carry2 = self.mac_with_carry(r[3], k, self.F.MODULUS.value[3], carry2) r[3] = carry1 + carry2 # Iteration 3 - r[0], carry1 = self.mac_with_carry( - r[0], self.value.value[0], other.value.value[3], 0 - ) + r[0], carry1 = self.mac_with_carry(r[0], self.value.value[0], other.value.value[3], 0) k = (r[0] * self.F.INV) % 0x10000000000000000 _, carry2 = self.mac_with_carry(r[0], k, self.F.MODULUS.value[0], 0) - r[1], carry1 = self.mac_with_carry( - r[1], self.value.value[1], other.value.value[3], carry1 - ) + r[1], carry1 = self.mac_with_carry(r[1], self.value.value[1], other.value.value[3], carry1) r[0], carry2 = self.mac_with_carry(r[1], k, self.F.MODULUS.value[1], carry2) - r[2], carry1 = self.mac_with_carry( - r[2], self.value.value[2], other.value.value[3], carry1 - ) + r[2], carry1 = self.mac_with_carry(r[2], self.value.value[2], other.value.value[3], carry1) r[1], carry2 = self.mac_with_carry(r[2], k, self.F.MODULUS.value[2], carry2) - r[3], carry1 = self.mac_with_carry( - r[3], self.value.value[3], other.value.value[3], carry1 - ) + r[3], carry1 = self.mac_with_carry(r[3], self.value.value[3], other.value.value[3], carry1) r[2], carry2 = self.mac_with_carry(r[3], k, self.F.MODULUS.value[3], carry2) r[3] = carry1 + carry2 @@ -240,7 +208,7 @@ def to_big_int(self): def pow(self, alpha): r = Fp256(self.F, self.value.to_int()) - for i in range(alpha - 1): + for _ in range(alpha - 1): self.mul_assign(r) def sum_of_products(self, b): diff --git a/tools/python/crypto/group.py b/tools/python/crypto/group.py index e326be1c..cb36ef51 100644 --- a/tools/python/crypto/group.py +++ b/tools/python/crypto/group.py @@ -3,12 +3,8 @@ class Group: - EDWARDS_A = BigInteger256( - [0x8CF500000000000E, 0xE75281EF6000000E, 0x49DC37A90B0BA012, 0x55F8B2C6E710AB9] - ) - EDWARDS_D = BigInteger256( - [0xD047FFFFFFFF5E30, 0xF0A91026FFFF57D2, 0x9013F560D102582, 0x9FD242CA7BE5700] - ) + EDWARDS_A = BigInteger256([0x8CF500000000000E, 0xE75281EF6000000E, 0x49DC37A90B0BA012, 0x55F8B2C6E710AB9]) + EDWARDS_D = BigInteger256([0xD047FFFFFFFF5E30, 0xF0A91026FFFF57D2, 0x9013F560D102582, 0x9FD242CA7BE5700]) def __init__(self, x=None, y=None): self.x = x diff --git a/tools/python/gen_program_function.py b/tools/python/gen_program_function.py index b800f1ea..de4136e9 100644 --- a/tools/python/gen_program_function.py +++ b/tools/python/gen_program_function.py @@ -149,23 +149,22 @@ def add_c_header(c_file): digest = bhp.hash(input, len(input) * 8) item["hashes"].append(digest) + d = digest.value.value if network_id == 1: print( - f" = {{0x{digest.value.value[0]:016x}, 0x{digest.value.value[1]:016x}, 0x{digest.value.value[2]:016x}, 0x{digest.value.value[3]:016x}}}}}}}}},", + f" = {{0x{d[0]:016x}, 0x{d[1]:016x}, 0x{d[2]:016x}, 0x{d[3]:016x}}}}}}}}},", file=c_file, ) else: print( - f" = {{0x{digest.value.value[0]:016x}, 0x{digest.value.value[1]:016x}, 0x{digest.value.value[2]:016x}, 0x{digest.value.value[3]:016x}}}}},", + f" = {{0x{d[0]:016x}, 0x{d[1]:016x}, 0x{d[2]:016x}, 0x{d[3]:016x}}}}},", file=c_file, ) print("};", file=c_file) print(file=c_file) - print( - "const program_parameter_t program_parameters[NB_OF_PROGRAMS] = {", file=c_file - ) + print("const program_parameter_t program_parameters[NB_OF_PROGRAMS] = {", file=c_file) max_len = 0 for program_id in programs.keys(): max_len = max(max_len, len(program_id)) @@ -177,9 +176,7 @@ def add_c_header(c_file): file=c_file, ) print( - " .functions = {}{}}},".format( - str_program_id, " " * (max_len - len(str_program_id)) - ), + " .functions = {}{}}},".format(str_program_id, " " * (max_len - len(str_program_id))), file=c_file, ) print("};", file=c_file) diff --git a/tools/python/gen_tokens.py b/tools/python/gen_tokens.py index b2da6089..ad5f98b6 100644 --- a/tools/python/gen_tokens.py +++ b/tools/python/gen_tokens.py @@ -57,7 +57,7 @@ def add_c_header(c_file): args = parser.parse_args() # Sanity checks - if args.file == None: + if args.file is None: exit(-1) json_file = open(args.file) @@ -105,9 +105,7 @@ def add_c_header(c_file): program_id_network = sp_program_id[1] str_program_id = program_id_name + "_" + program_id_network print( - "#define NB_OF_{}_FUNCTIONS ({:d})".format( - str_program_id.upper(), len(token["functions"]) - ), + "#define NB_OF_{}_FUNCTIONS ({:d})".format(str_program_id.upper(), len(token["functions"])), file=c_file, ) print( @@ -119,9 +117,7 @@ def add_c_header(c_file): print(" " + function_name) print(f' {{.name = "{function_name}",', file=c_file) print(" .tx_type = {},".format(function["tx_type"]), file=c_file) - print( - " .input_count = {:d},".format(function["input_count"]), file=c_file - ) + print(" .input_count = {:d},".format(function["input_count"]), file=c_file) print(" .bhp_1024_hashes", file=c_file) function["hashes"] = [] for network_id in range(2): @@ -142,14 +138,15 @@ def add_c_header(c_file): digest = bhp.hash(input, len(input) * 8) function["hashes"].append(digest) + d = digest.value.value if network_id == 1: print( - f" = {{0x{digest.value.value[0]:016x}, 0x{digest.value.value[1]:016x}, 0x{digest.value.value[2]:016x}, 0x{digest.value.value[3]:016x}}}}}}}}},", + f" = {{0x{d[0]:016x}, 0x{d[1]:016x}, 0x{d[2]:016x}, 0x{d[3]:016x}}}}}}}}},", file=c_file, ) else: print( - f" = {{0x{digest.value.value[0]:016x}, 0x{digest.value.value[1]:016x}, 0x{digest.value.value[2]:016x}, 0x{digest.value.value[3]:016x}}}}},", + f" = {{0x{d[0]:016x}, 0x{d[1]:016x}, 0x{d[2]:016x}, 0x{d[3]:016x}}}}},", file=c_file, ) @@ -177,8 +174,9 @@ def add_c_header(c_file): ) print(" .token_id", file=c_file) print(" = {.big.u64", file=c_file) + t = token_id.value.value print( - f" = {{0x{token_id.value.value[0]:016x}, 0x{token_id.value.value[1]:016x}, 0x{token_id.value.value[2]:016x}, 0x{token_id.value.value[3]:016x}}}}},", + f" = {{0x{t[0]:016x}, 0x{t[1]:016x}, 0x{t[2]:016x}, 0x{t[3]:016x}}}}},", file=c_file, ) print( @@ -186,9 +184,7 @@ def add_c_header(c_file): file=c_file, ) print( - " .functions = {}{}}},".format( - str_program_id, " " * (max_len - len(str_program_id)) - ), + " .functions = {}{}}},".format(str_program_id, " " * (max_len - len(str_program_id))), file=c_file, ) diff --git a/tools/python/test_apdu.py b/tools/python/test_apdu.py index 6c867a7d..f2a6f49b 100644 --- a/tools/python/test_apdu.py +++ b/tools/python/test_apdu.py @@ -4,7 +4,7 @@ import json import sys -from ledgerblue.comm import getDongle +from ledgerblue.comm import getDongle, getDongleTCP sys.path.append("../../") from tests.application_client.transaction import Transaction @@ -25,7 +25,7 @@ tx = Transaction() - if args.dry_run == False: + if not args.dry_run: if args.tcp: dongle = getDongleTCP("127.0.0.1", 1237) else: