From 6dd70e11a87ab0799b3c677ee57ad76e935f2145 Mon Sep 17 00:00:00 2001 From: Charles-Edouard de la Vergne Date: Tue, 30 Apr 2024 17:34:57 +0200 Subject: [PATCH] Fix python lint --- tests/ragger/setup.cfg | 9 +++++++-- .../staking_deposit/key_handling/key_derivation/path.py | 2 +- .../staking_deposit/key_handling/key_derivation/tree.py | 9 +++++---- tests/ragger/staking_deposit/utils/crypto.py | 9 +++------ tests/ragger/test_configuration_cmd.py | 1 + tests/ragger/test_erc20information.py | 4 ++-- tests/ragger/usage.md | 7 ++++--- 7 files changed, 23 insertions(+), 18 deletions(-) diff --git a/tests/ragger/setup.cfg b/tests/ragger/setup.cfg index c79fd88..d7f3b7b 100644 --- a/tests/ragger/setup.cfg +++ b/tests/ragger/setup.cfg @@ -7,11 +7,16 @@ disable = C0114, # missing-module-docstring C0116, # missing-function-docstring C0103, # invalid-name R0801, # duplicate-code - R0913 # too-many-arguments + R0903, # too-few-public-methods + R0913, # too-many-arguments + R0914, # too-many-locals + W0603, # global-statement + E0401 # import-error extension-pkg-whitelist=hid +max-line-length = 130 [pycodestyle] -max-line-length = 90 +max-line-length = 130 [mypy-hid.*] ignore_missing_imports = True diff --git a/tests/ragger/staking_deposit/key_handling/key_derivation/path.py b/tests/ragger/staking_deposit/key_handling/key_derivation/path.py index b9e2e2b..cb13719 100644 --- a/tests/ragger/staking_deposit/key_handling/key_derivation/path.py +++ b/tests/ragger/staking_deposit/key_handling/key_derivation/path.py @@ -3,7 +3,7 @@ from typing import List from bip_utils import Bip39SeedGenerator from bip_utils.utils.mnemonic import Mnemonic -from .tree import ( +from staking_deposit.key_handling.key_derivation.tree import ( derive_master_SK, derive_child_SK, ) diff --git a/tests/ragger/staking_deposit/key_handling/key_derivation/tree.py b/tests/ragger/staking_deposit/key_handling/key_derivation/tree.py index 53fcd0e..977017f 100644 --- a/tests/ragger/staking_deposit/key_handling/key_derivation/tree.py +++ b/tests/ragger/staking_deposit/key_handling/key_derivation/tree.py @@ -1,16 +1,17 @@ +from typing import List + from staking_deposit.utils.crypto import ( HKDF, SHA256, ) from py_ecc.optimized_bls12_381 import curve_order as bls_curve_order -from typing import List -def _flip_bits_256(input: int) -> int: +def _flip_bits_256(value: int) -> int: """ - Flips 256 bits worth of `input`. + Flips 256 bits worth of `value`. """ - return input ^ (2**256 - 1) + return value ^ (2**256 - 1) def _IKM_to_lamport_SK(*, IKM: bytes, salt: bytes) -> List[bytes]: diff --git a/tests/ragger/staking_deposit/utils/crypto.py b/tests/ragger/staking_deposit/utils/crypto.py index 48a9d76..e018d49 100644 --- a/tests/ragger/staking_deposit/utils/crypto.py +++ b/tests/ragger/staking_deposit/utils/crypto.py @@ -32,12 +32,9 @@ def PBKDF2(*, password: bytes, salt: bytes, dklen: int, c: int, prf: str) -> byt if 'sha' not in prf: raise ValueError(f"String 'sha' is not in `prf`({prf})") if 'sha256' in prf and c < 2**18: - ''' - Verify the number of rounds of SHA256-PBKDF2. SHA512 not checked as use in BIP39 - does not require, and therefore doesn't use, safe parameters (c=2048). - - Ref: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki#from-mnemonic-to-seed - ''' + # Verify the number of rounds of SHA256-PBKDF2. SHA512 not checked as use in BIP39 + # does not require, and therefore doesn't use, safe parameters (c=2048). + # Ref: https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki#from-mnemonic-to-seed raise ValueError("The PBKDF2 parameters chosen are not secure.") _hash = _sha256 if 'sha256' in prf else _sha512 res = _PBKDF2(password=password, salt=salt, dkLen=dklen, count=c, hmac_hash_module=_hash) # type: ignore diff --git a/tests/ragger/test_configuration_cmd.py b/tests/ragger/test_configuration_cmd.py index c8a8e95..99e8760 100644 --- a/tests/ragger/test_configuration_cmd.py +++ b/tests/ragger/test_configuration_cmd.py @@ -1,6 +1,7 @@ from pathlib import Path from typing import List import re + from ragger.backend import BackendInterface from ragger.utils.misc import get_current_app_name_and_version diff --git a/tests/ragger/test_erc20information.py b/tests/ragger/test_erc20information.py index 130b3ac..a858f55 100644 --- a/tests/ragger/test_erc20information.py +++ b/tests/ragger/test_erc20information.py @@ -1,10 +1,10 @@ import pytest -from client.client import EthAppClient, StatusWord - from ragger.error import ExceptionRAPDU from ragger.backend import BackendInterface +from client.client import EthAppClient, StatusWord + def test_provide_erc20_token(backend: BackendInterface): diff --git a/tests/ragger/usage.md b/tests/ragger/usage.md index 2a4954d..a7f83e1 100644 --- a/tests/ragger/usage.md +++ b/tests/ragger/usage.md @@ -61,12 +61,13 @@ Or you can refer to the section `Available pytest options` to configure the opti With Ethereum App, it is also possible to load an app (like a _plugin_), and use the `app-ethereum` like a _library_. Such case is tested with application clone, using `ThunderCore`. -This special configuration needs an additional command line parameter `--with_lib_mode`, where only the dedicated tests are selected. +This special configuration needs an additional command line parameter `--with_lib_mode`, +where only the dedicated tests are selected. ## Adding a test -When adding new Module for tests, just be carrefull to declare it correctly in order to be handled following the parameter `--with_lib_mode`. -please refer to `conftest.py`. +When adding new Module for tests, just be carrefull to declare it correctly in order to be handled +following the parameter `--with_lib_mode`. please refer to `conftest.py`. ## Available pytest options