Fix pylint issues
This commit is contained in:
@@ -1,22 +1,23 @@
|
||||
import fnmatch
|
||||
import os
|
||||
import pytest
|
||||
import time
|
||||
from configparser import ConfigParser
|
||||
from functools import partial
|
||||
from pathlib import Path
|
||||
from ragger.backend import BackendInterface
|
||||
from ragger.firmware import Firmware
|
||||
from ragger.navigator import Navigator, NavInsID
|
||||
import json
|
||||
from typing import Optional
|
||||
from constants import ROOT_SNAPSHOT_PATH
|
||||
import pytest
|
||||
|
||||
import ledger_app_clients.ethereum.response_parser as ResponseParser
|
||||
from ledger_app_clients.ethereum.client import EthAppClient
|
||||
from ledger_app_clients.ethereum.eip712 import InputData
|
||||
from ledger_app_clients.ethereum.settings import SettingID, settings_toggle
|
||||
|
||||
from ragger.backend import BackendInterface
|
||||
from ragger.firmware import Firmware
|
||||
from ragger.navigator import Navigator, NavInsID
|
||||
from constants import ROOT_SNAPSHOT_PATH
|
||||
|
||||
|
||||
class SnapshotsConfig:
|
||||
test_name: str
|
||||
@@ -32,7 +33,7 @@ snaps_config: Optional[SnapshotsConfig] = None
|
||||
|
||||
|
||||
def eip712_json_path() -> str:
|
||||
return "%s/eip712_input_files" % (os.path.dirname(__file__))
|
||||
return f"{os.path.dirname(__file__)}/eip712_input_files"
|
||||
|
||||
|
||||
def input_files() -> list[str]:
|
||||
@@ -43,18 +44,18 @@ def input_files() -> list[str]:
|
||||
return sorted(files)
|
||||
|
||||
|
||||
@pytest.fixture(params=input_files())
|
||||
def input_file(request) -> str:
|
||||
@pytest.fixture(name="input_file", params=input_files())
|
||||
def input_file_fixture(request) -> str:
|
||||
return Path(request.param)
|
||||
|
||||
|
||||
@pytest.fixture(params=[True, False])
|
||||
def verbose(request) -> bool:
|
||||
@pytest.fixture(name="verbose", params=[True, False])
|
||||
def verbose_fixture(request) -> bool:
|
||||
return request.param
|
||||
|
||||
|
||||
@pytest.fixture(params=[False, True])
|
||||
def filtering(request) -> bool:
|
||||
@pytest.fixture(name="filtering", params=[False, True])
|
||||
def filtering_fixture(request) -> bool:
|
||||
return request.param
|
||||
|
||||
|
||||
@@ -66,7 +67,7 @@ def test_eip712_legacy(firmware: Firmware,
|
||||
BIP32_PATH,
|
||||
bytes.fromhex('6137beb405d9ff777172aa879e33edb34a1460e701802746c5ef96e741710e59'),
|
||||
bytes.fromhex('eb4221181ff3f1a83ea7313993ca9218496e424604ba9492bb4052c03d5c3df8')):
|
||||
moves = list()
|
||||
moves = []
|
||||
if firmware.device.startswith("nano"):
|
||||
moves += [NavInsID.RIGHT_CLICK]
|
||||
if firmware.device == "nanos":
|
||||
@@ -87,14 +88,14 @@ def test_eip712_legacy(firmware: Firmware,
|
||||
assert s == bytes.fromhex("52d8ba9153de9255da220ffd36762c0b027701a3b5110f0a765f94b16a9dfb55")
|
||||
|
||||
|
||||
def autonext(fw: Firmware, nav: Navigator):
|
||||
moves = list()
|
||||
if fw.device.startswith("nano"):
|
||||
def autonext(firmware: Firmware, navigator: Navigator):
|
||||
moves = []
|
||||
if firmware.device.startswith("nano"):
|
||||
moves = [NavInsID.RIGHT_CLICK]
|
||||
else:
|
||||
moves = [NavInsID.USE_CASE_REVIEW_TAP]
|
||||
if snaps_config is not None:
|
||||
nav.navigate_and_compare(ROOT_SNAPSHOT_PATH,
|
||||
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
|
||||
snaps_config.test_name,
|
||||
moves,
|
||||
screen_change_before_first_instruction=False,
|
||||
@@ -102,13 +103,13 @@ def autonext(fw: Firmware, nav: Navigator):
|
||||
snap_start_idx=snaps_config.idx)
|
||||
snaps_config.idx += 1
|
||||
else:
|
||||
nav.navigate(moves,
|
||||
navigator.navigate(moves,
|
||||
screen_change_before_first_instruction=False,
|
||||
screen_change_after_last_instruction=False)
|
||||
|
||||
|
||||
def eip712_new_common(fw: Firmware,
|
||||
nav: Navigator,
|
||||
def eip712_new_common(firmware: Firmware,
|
||||
navigator: Navigator,
|
||||
app_client: EthAppClient,
|
||||
json_data: dict,
|
||||
filters: Optional[dict],
|
||||
@@ -116,10 +117,10 @@ def eip712_new_common(fw: Firmware,
|
||||
assert InputData.process_data(app_client,
|
||||
json_data,
|
||||
filters,
|
||||
partial(autonext, fw, nav))
|
||||
partial(autonext, firmware, navigator))
|
||||
with app_client.eip712_sign_new(BIP32_PATH):
|
||||
moves = list()
|
||||
if fw.device.startswith("nano"):
|
||||
moves = []
|
||||
if firmware.device.startswith("nano"):
|
||||
# need to skip the message hash
|
||||
if not verbose and filters is None:
|
||||
moves = [NavInsID.RIGHT_CLICK] * 2
|
||||
@@ -131,13 +132,13 @@ def eip712_new_common(fw: Firmware,
|
||||
moves += [NavInsID.USE_CASE_REVIEW_TAP]
|
||||
moves += [NavInsID.USE_CASE_REVIEW_CONFIRM]
|
||||
if snaps_config is not None:
|
||||
nav.navigate_and_compare(ROOT_SNAPSHOT_PATH,
|
||||
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
|
||||
snaps_config.test_name,
|
||||
moves,
|
||||
snap_start_idx=snaps_config.idx)
|
||||
snaps_config.idx += 1
|
||||
else:
|
||||
nav.navigate(moves)
|
||||
navigator.navigate(moves)
|
||||
return ResponseParser.signature(app_client.response().data)
|
||||
|
||||
|
||||
@@ -151,16 +152,16 @@ def test_eip712_new(firmware: Firmware,
|
||||
if firmware.device == "nanos":
|
||||
pytest.skip("Not supported on LNS")
|
||||
else:
|
||||
test_path = "%s/%s" % (input_file.parent, "-".join(input_file.stem.split("-")[:-1]))
|
||||
conf_file = "%s.ini" % (test_path)
|
||||
test_path = f"{input_file.parent}/{'-'.join(input_file.stem.split('-')[:-1])}"
|
||||
conf_file = f"{test_path}.ini"
|
||||
|
||||
filters = None
|
||||
if filtering:
|
||||
try:
|
||||
with open("%s-filter.json" % (test_path)) as f:
|
||||
with open(f"{test_path}-filter.json", encoding="utf-8") as f:
|
||||
filters = json.load(f)
|
||||
except (IOError, json.decoder.JSONDecodeError) as e:
|
||||
pytest.skip("Filter file error: %s" % (e.strerror))
|
||||
pytest.skip(f"Filter file error: {e.strerror}")
|
||||
|
||||
config = ConfigParser()
|
||||
config.read(conf_file)
|
||||
@@ -174,7 +175,7 @@ def test_eip712_new(firmware: Firmware,
|
||||
if verbose:
|
||||
settings_toggle(firmware, navigator, [SettingID.VERBOSE_EIP712])
|
||||
|
||||
with open(input_file) as file:
|
||||
with open(input_file, encoding="utf-8") as file:
|
||||
v, r, s = eip712_new_common(firmware,
|
||||
navigator,
|
||||
app_client,
|
||||
@@ -201,7 +202,7 @@ def test_eip712_address_substitution(firmware: Firmware,
|
||||
if verbose:
|
||||
test_name += "_verbose"
|
||||
snaps_config = SnapshotsConfig(test_name)
|
||||
with open("%s/address_substitution.json" % (eip712_json_path())) as file:
|
||||
with open(f"{eip712_json_path()}/address_substitution.json", encoding="utf-8") as file:
|
||||
data = json.load(file)
|
||||
|
||||
app_client.provide_token_metadata("DAI",
|
||||
|
||||
Reference in New Issue
Block a user