Fix pylint issues
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from ragger.conftest import configuration
|
||||
#from ragger.conftest import configuration
|
||||
|
||||
# Pull all features from the base ragger conftest using the overridden configuration
|
||||
pytest_plugins = ("ragger.conftest.base_conftest", )
|
||||
|
||||
@@ -2,4 +2,4 @@ from pathlib import Path
|
||||
import os
|
||||
|
||||
ROOT_SNAPSHOT_PATH = Path(__file__).parent
|
||||
ABIS_FOLDER = "%s/abis" % (os.path.dirname(__file__))
|
||||
ABIS_FOLDER = f"{os.path.dirname(__file__)}/abis"
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import json
|
||||
import pytest
|
||||
from web3 import Web3
|
||||
|
||||
from ledger_app_clients.ethereum.client import EthAppClient, StatusWord
|
||||
from ragger.backend import BackendInterface
|
||||
from ragger.firmware import Firmware
|
||||
from ragger.navigator import Navigator, NavInsID
|
||||
from ragger.error import ExceptionRAPDU
|
||||
from ledger_app_clients.ethereum.client import EthAppClient, StatusWord
|
||||
from web3 import Web3
|
||||
|
||||
from constants import ROOT_SNAPSHOT_PATH, ABIS_FOLDER
|
||||
|
||||
|
||||
@@ -16,7 +18,7 @@ def test_blind_sign(firmware: Firmware,
|
||||
navigator: Navigator):
|
||||
app_client = EthAppClient(backend)
|
||||
|
||||
with open("%s/erc20.json" % (ABIS_FOLDER)) as file:
|
||||
with open(f"{ABIS_FOLDER}/erc20.json", encoding="utf-8") as file:
|
||||
contract = Web3().eth.contract(
|
||||
abi=json.load(file),
|
||||
address=None
|
||||
@@ -41,7 +43,7 @@ def test_blind_sign(firmware: Firmware,
|
||||
pass
|
||||
assert e.value.status == StatusWord.INVALID_DATA
|
||||
|
||||
moves = list()
|
||||
moves = []
|
||||
if firmware.device.startswith("nano"):
|
||||
if firmware.device == "nanos":
|
||||
moves += [NavInsID.RIGHT_CLICK]
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import pytest
|
||||
from ragger.backend import BackendInterface
|
||||
from ragger.firmware import Firmware
|
||||
from ragger.error import ExceptionRAPDU
|
||||
from ragger.navigator import Navigator, NavInsID
|
||||
from constants import ROOT_SNAPSHOT_PATH
|
||||
from web3 import Web3
|
||||
|
||||
import ledger_app_clients.ethereum.response_parser as ResponseParser
|
||||
from ledger_app_clients.ethereum.client import EthAppClient, StatusWord
|
||||
from ledger_app_clients.ethereum.settings import SettingID, settings_toggle
|
||||
from ragger.backend import BackendInterface
|
||||
from ragger.firmware import Firmware
|
||||
from ragger.error import ExceptionRAPDU
|
||||
from ragger.navigator import Navigator, NavInsID
|
||||
|
||||
from web3 import Web3
|
||||
from constants import ROOT_SNAPSHOT_PATH
|
||||
|
||||
|
||||
# Values used across all tests
|
||||
@@ -25,13 +25,14 @@ GAS_LIMIT = 21000
|
||||
AMOUNT = 1.22
|
||||
|
||||
|
||||
@pytest.fixture(params=[False, True])
|
||||
def verbose(request) -> bool:
|
||||
@pytest.fixture(name="verbose", params=[False, True])
|
||||
def verbose_fixture(request) -> bool:
|
||||
return request.param
|
||||
|
||||
|
||||
def common(app_client: EthAppClient) -> int:
|
||||
if app_client._client.firmware.device == "nanos":
|
||||
def common(firmware: Firmware, app_client: EthAppClient) -> int:
|
||||
|
||||
if firmware.device == "nanos":
|
||||
pytest.skip("Not supported on LNS")
|
||||
challenge = app_client.get_challenge()
|
||||
return ResponseParser.challenge(challenge.data)
|
||||
@@ -40,10 +41,9 @@ def common(app_client: EthAppClient) -> int:
|
||||
def test_send_fund(firmware: Firmware,
|
||||
backend: BackendInterface,
|
||||
navigator: Navigator,
|
||||
test_name: str,
|
||||
verbose: bool):
|
||||
app_client = EthAppClient(backend)
|
||||
challenge = common(app_client)
|
||||
challenge = common(firmware, app_client)
|
||||
|
||||
if verbose:
|
||||
settings_toggle(firmware, navigator, [SettingID.VERBOSE_ENS])
|
||||
@@ -59,7 +59,7 @@ def test_send_fund(firmware: Firmware,
|
||||
"value": Web3.to_wei(AMOUNT, "ether"),
|
||||
"chainId": CHAIN_ID
|
||||
}):
|
||||
moves = list()
|
||||
moves = []
|
||||
if firmware.device.startswith("nano"):
|
||||
moves += [NavInsID.RIGHT_CLICK] * 4
|
||||
if verbose:
|
||||
@@ -75,11 +75,9 @@ def test_send_fund(firmware: Firmware,
|
||||
moves)
|
||||
|
||||
|
||||
def test_send_fund_wrong_challenge(firmware: Firmware,
|
||||
backend: BackendInterface,
|
||||
navigator: Navigator):
|
||||
def test_send_fund_wrong_challenge(firmware: Firmware, backend: BackendInterface):
|
||||
app_client = EthAppClient(backend)
|
||||
challenge = common(app_client)
|
||||
challenge = common(firmware, app_client)
|
||||
|
||||
with pytest.raises(ExceptionRAPDU) as e:
|
||||
app_client.provide_domain_name(~challenge & 0xffffffff, NAME, ADDR)
|
||||
@@ -88,10 +86,9 @@ def test_send_fund_wrong_challenge(firmware: Firmware,
|
||||
|
||||
def test_send_fund_wrong_addr(firmware: Firmware,
|
||||
backend: BackendInterface,
|
||||
navigator: Navigator,
|
||||
test_name: str):
|
||||
navigator: Navigator):
|
||||
app_client = EthAppClient(backend)
|
||||
challenge = common(app_client)
|
||||
challenge = common(firmware, app_client)
|
||||
|
||||
app_client.provide_domain_name(challenge, NAME, ADDR)
|
||||
|
||||
@@ -107,7 +104,7 @@ def test_send_fund_wrong_addr(firmware: Firmware,
|
||||
"value": Web3.to_wei(AMOUNT, "ether"),
|
||||
"chainId": CHAIN_ID
|
||||
}):
|
||||
moves = list()
|
||||
moves = []
|
||||
if firmware.device.startswith("nano"):
|
||||
moves += [NavInsID.RIGHT_CLICK] * 4
|
||||
moves += [NavInsID.BOTH_CLICK]
|
||||
@@ -121,10 +118,9 @@ def test_send_fund_wrong_addr(firmware: Firmware,
|
||||
|
||||
def test_send_fund_non_mainnet(firmware: Firmware,
|
||||
backend: BackendInterface,
|
||||
navigator: Navigator,
|
||||
test_name: str):
|
||||
navigator: Navigator):
|
||||
app_client = EthAppClient(backend)
|
||||
challenge = common(app_client)
|
||||
challenge = common(firmware, app_client)
|
||||
|
||||
app_client.provide_domain_name(challenge, NAME, ADDR)
|
||||
|
||||
@@ -137,7 +133,7 @@ def test_send_fund_non_mainnet(firmware: Firmware,
|
||||
"value": Web3.to_wei(AMOUNT, "ether"),
|
||||
"chainId": 5
|
||||
}):
|
||||
moves = list()
|
||||
moves = []
|
||||
if firmware.device.startswith("nano"):
|
||||
moves += [NavInsID.RIGHT_CLICK] * 5
|
||||
moves += [NavInsID.BOTH_CLICK]
|
||||
@@ -151,10 +147,9 @@ def test_send_fund_non_mainnet(firmware: Firmware,
|
||||
|
||||
def test_send_fund_unknown_chain(firmware: Firmware,
|
||||
backend: BackendInterface,
|
||||
navigator: Navigator,
|
||||
test_name: str):
|
||||
navigator: Navigator):
|
||||
app_client = EthAppClient(backend)
|
||||
challenge = common(app_client)
|
||||
challenge = common(firmware, app_client)
|
||||
|
||||
app_client.provide_domain_name(challenge, NAME, ADDR)
|
||||
|
||||
@@ -167,7 +162,7 @@ def test_send_fund_unknown_chain(firmware: Firmware,
|
||||
"value": Web3.to_wei(AMOUNT, "ether"),
|
||||
"chainId": 9
|
||||
}):
|
||||
moves = list()
|
||||
moves = []
|
||||
if firmware.device.startswith("nano"):
|
||||
moves += [NavInsID.RIGHT_CLICK] * 5
|
||||
moves += [NavInsID.BOTH_CLICK]
|
||||
@@ -179,44 +174,36 @@ def test_send_fund_unknown_chain(firmware: Firmware,
|
||||
moves)
|
||||
|
||||
|
||||
def test_send_fund_domain_too_long(firmware: Firmware,
|
||||
backend: BackendInterface,
|
||||
navigator: Navigator):
|
||||
def test_send_fund_domain_too_long(firmware: Firmware, backend: BackendInterface):
|
||||
app_client = EthAppClient(backend)
|
||||
challenge = common(app_client)
|
||||
challenge = common(firmware, app_client)
|
||||
|
||||
with pytest.raises(ExceptionRAPDU) as e:
|
||||
app_client.provide_domain_name(challenge, "ledger" + "0"*25 + ".eth", ADDR)
|
||||
assert e.value.status == StatusWord.INVALID_DATA
|
||||
|
||||
|
||||
def test_send_fund_domain_invalid_character(firmware: Firmware,
|
||||
backend: BackendInterface,
|
||||
navigator: Navigator):
|
||||
def test_send_fund_domain_invalid_character(firmware: Firmware, backend: BackendInterface):
|
||||
app_client = EthAppClient(backend)
|
||||
challenge = common(app_client)
|
||||
challenge = common(firmware, app_client)
|
||||
|
||||
with pytest.raises(ExceptionRAPDU) as e:
|
||||
app_client.provide_domain_name(challenge, "l\xe8dger.eth", ADDR)
|
||||
assert e.value.status == StatusWord.INVALID_DATA
|
||||
|
||||
|
||||
def test_send_fund_uppercase(firmware: Firmware,
|
||||
backend: BackendInterface,
|
||||
navigator: Navigator):
|
||||
def test_send_fund_uppercase(firmware: Firmware, backend: BackendInterface):
|
||||
app_client = EthAppClient(backend)
|
||||
challenge = common(app_client)
|
||||
challenge = common(firmware, app_client)
|
||||
|
||||
with pytest.raises(ExceptionRAPDU) as e:
|
||||
app_client.provide_domain_name(challenge, NAME.upper(), ADDR)
|
||||
assert e.value.status == StatusWord.INVALID_DATA
|
||||
|
||||
|
||||
def test_send_fund_domain_non_ens(firmware: Firmware,
|
||||
backend: BackendInterface,
|
||||
navigator: Navigator):
|
||||
def test_send_fund_domain_non_ens(firmware: Firmware, backend: BackendInterface):
|
||||
app_client = EthAppClient(backend)
|
||||
challenge = common(app_client)
|
||||
challenge = common(firmware, app_client)
|
||||
|
||||
with pytest.raises(ExceptionRAPDU) as e:
|
||||
app_client.provide_domain_name(challenge, "ledger.hte", ADDR)
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -1,30 +1,32 @@
|
||||
import pytest
|
||||
from typing import Optional
|
||||
import pytest
|
||||
|
||||
from ledger_app_clients.ethereum.client import EthAppClient, StatusWord
|
||||
import ledger_app_clients.ethereum.response_parser as ResponseParser
|
||||
|
||||
from ragger.error import ExceptionRAPDU
|
||||
from ragger.firmware import Firmware
|
||||
from ragger.backend import BackendInterface
|
||||
from ragger.navigator import Navigator, NavInsID
|
||||
from ledger_app_clients.ethereum.client import EthAppClient, StatusWord
|
||||
import ledger_app_clients.ethereum.response_parser as ResponseParser
|
||||
from ragger.bip import calculate_public_key_and_chaincode, CurveChoice
|
||||
|
||||
from constants import ROOT_SNAPSHOT_PATH
|
||||
|
||||
|
||||
@pytest.fixture(params=[True, False])
|
||||
def with_chaincode(request) -> bool:
|
||||
@pytest.fixture(name="with_chaincode", params=[True, False])
|
||||
def with_chaincode_fixture(request) -> bool:
|
||||
return request.param
|
||||
|
||||
|
||||
@pytest.fixture(params=[None, 1, 2, 5, 137])
|
||||
def chain(request) -> Optional[int]:
|
||||
@pytest.fixture(name="chain", params=[None, 1, 2, 5, 137])
|
||||
def chain_fixture(request) -> Optional[int]:
|
||||
return request.param
|
||||
|
||||
|
||||
def get_moves(firmware: Firmware,
|
||||
navigator: BackendInterface,
|
||||
chain: Optional[int] = None,
|
||||
reject: bool = False):
|
||||
moves = list()
|
||||
moves = []
|
||||
|
||||
if firmware.is_nano:
|
||||
moves += [NavInsID.RIGHT_CLICK]
|
||||
@@ -56,7 +58,7 @@ def test_get_pk_rejected(firmware: Firmware,
|
||||
with app_client.get_public_addr():
|
||||
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
|
||||
"get_pk_rejected",
|
||||
get_moves(firmware, navigator, reject=True))
|
||||
get_moves(firmware, reject=True))
|
||||
assert e.value.status == StatusWord.CONDITION_NOT_SATISFIED
|
||||
|
||||
|
||||
@@ -69,9 +71,9 @@ def test_get_pk(firmware: Firmware,
|
||||
|
||||
with app_client.get_public_addr(chaincode=with_chaincode, chain_id=chain):
|
||||
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
|
||||
"get_pk_%s" % (chain),
|
||||
get_moves(firmware, navigator, chain=chain))
|
||||
pk, addr, chaincode = ResponseParser.pk_addr(app_client.response().data, with_chaincode)
|
||||
f"get_pk_{chain}",
|
||||
get_moves(firmware, chain=chain))
|
||||
pk, _, chaincode = ResponseParser.pk_addr(app_client.response().data, with_chaincode)
|
||||
ref_pk, ref_chaincode = calculate_public_key_and_chaincode(curve=CurveChoice.Secp256k1,
|
||||
path="m/44'/60'/0'/0/0")
|
||||
assert pk.hex() == ref_pk
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
from typing import Callable, Optional, Any
|
||||
import json
|
||||
import pytest
|
||||
from typing import Optional, Any
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
|
||||
from web3 import Web3
|
||||
|
||||
from ledger_app_clients.ethereum.client import EthAppClient, StatusWord
|
||||
import ledger_app_clients.ethereum.response_parser as ResponseParser
|
||||
from ledger_app_clients.ethereum.utils import get_selector_from_data, recover_transaction
|
||||
|
||||
from ragger.error import ExceptionRAPDU
|
||||
from ragger.firmware import Firmware
|
||||
from ragger.backend import BackendInterface
|
||||
from ragger.navigator import Navigator, NavInsID
|
||||
from ledger_app_clients.ethereum.client import EthAppClient, StatusWord
|
||||
import ledger_app_clients.ethereum.response_parser as ResponseParser
|
||||
from ledger_app_clients.ethereum.utils import get_selector_from_data, recover_transaction
|
||||
from web3 import Web3
|
||||
import json
|
||||
|
||||
from constants import ROOT_SNAPSHOT_PATH, ABIS_FOLDER
|
||||
|
||||
|
||||
@@ -52,7 +54,7 @@ def common_nav_nft(is_nano: bool,
|
||||
nano_steps: int,
|
||||
stax_steps: int,
|
||||
reject: bool) -> list[NavInsID]:
|
||||
moves = list()
|
||||
moves = []
|
||||
if is_nano:
|
||||
moves += [NavInsID.RIGHT_CLICK] * nano_steps
|
||||
if reject:
|
||||
@@ -71,23 +73,23 @@ def common_nav_nft(is_nano: bool,
|
||||
|
||||
|
||||
def snapshot_test_name(nft_type: str, fn: str, chain_id: int, reject: bool) -> str:
|
||||
name = "%s_%s_%s" % (nft_type, fn, str(chain_id))
|
||||
name = f"{nft_type}_{fn}_{str(chain_id)}"
|
||||
if reject:
|
||||
name += "-rejected"
|
||||
return name
|
||||
|
||||
|
||||
def common_test_nft(fw: Firmware,
|
||||
back: BackendInterface,
|
||||
nav: Navigator,
|
||||
def common_test_nft(firmware: Firmware,
|
||||
backend: BackendInterface,
|
||||
navigator: Navigator,
|
||||
collec: NFTCollection,
|
||||
action: Action,
|
||||
reject: bool,
|
||||
plugin_name: str):
|
||||
global DEVICE_ADDR
|
||||
app_client = EthAppClient(back)
|
||||
app_client = EthAppClient(backend)
|
||||
|
||||
if app_client._client.firmware.name == "nanos":
|
||||
if firmware.device == "nanos":
|
||||
pytest.skip("Not supported on LNS")
|
||||
|
||||
if DEVICE_ADDR is None: # to only have to request it once
|
||||
@@ -111,12 +113,12 @@ def common_test_nft(fw: Firmware,
|
||||
"data": data,
|
||||
}
|
||||
with app_client.sign(BIP32_PATH, tx_params):
|
||||
nav.navigate_and_compare(ROOT_SNAPSHOT_PATH,
|
||||
navigator.navigate_and_compare(ROOT_SNAPSHOT_PATH,
|
||||
snapshot_test_name(plugin_name.lower(),
|
||||
action.fn_name,
|
||||
collec.chain_id,
|
||||
reject),
|
||||
action.nav_fn(fw.is_nano,
|
||||
action.nav_fn(firmware.is_nano,
|
||||
collec.chain_id,
|
||||
reject))
|
||||
# verify signature
|
||||
@@ -126,13 +128,13 @@ def common_test_nft(fw: Firmware,
|
||||
|
||||
|
||||
def common_test_nft_reject(test_fn: Callable,
|
||||
fw: Firmware,
|
||||
back: BackendInterface,
|
||||
nav: Navigator,
|
||||
firmware: Firmware,
|
||||
backend: BackendInterface,
|
||||
navigator: Navigator,
|
||||
collec: NFTCollection,
|
||||
action: Action):
|
||||
with pytest.raises(ExceptionRAPDU) as e:
|
||||
test_fn(fw, back, nav, collec, action, True)
|
||||
test_fn(firmware, backend, navigator, collec, action, True)
|
||||
assert e.value.status == StatusWord.CONDITION_NOT_SATISFIED
|
||||
|
||||
# ERC-721
|
||||
@@ -140,13 +142,13 @@ def common_test_nft_reject(test_fn: Callable,
|
||||
|
||||
ERC721_PLUGIN = "ERC721"
|
||||
|
||||
with open("%s/erc721.json" % (ABIS_FOLDER)) as file:
|
||||
with open(f"{ABIS_FOLDER}/erc721.json", encoding="utf-8") as file:
|
||||
contract_erc721 = Web3().eth.contract(
|
||||
abi=json.load(file),
|
||||
address=bytes(20)
|
||||
)
|
||||
|
||||
# ui nav functions
|
||||
# ui navigator functions
|
||||
|
||||
def nav_erc721_transfer_from(is_nano: bool,
|
||||
chain_id: int,
|
||||
@@ -212,13 +214,13 @@ actions_721 = [
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture(params=collecs_721)
|
||||
def collec_721(request) -> NFTCollection:
|
||||
@pytest.fixture(name="collec_721", params=collecs_721)
|
||||
def collec_721_fixture(request) -> NFTCollection:
|
||||
return request.param
|
||||
|
||||
|
||||
@pytest.fixture(params=actions_721)
|
||||
def action_721(request) -> Action:
|
||||
@pytest.fixture(name="action_721", params=actions_721)
|
||||
def action_721_fixture(request) -> Action:
|
||||
return request.param
|
||||
|
||||
|
||||
@@ -252,14 +254,14 @@ def test_erc721_reject(firmware: Firmware,
|
||||
|
||||
ERC1155_PLUGIN = "ERC1155"
|
||||
|
||||
with open("%s/erc1155.json" % (ABIS_FOLDER)) as file:
|
||||
with open(f"{ABIS_FOLDER}/erc1155.json", encoding="utf-8") as file:
|
||||
contract_erc1155 = Web3().eth.contract(
|
||||
abi=json.load(file),
|
||||
address=bytes(20)
|
||||
)
|
||||
|
||||
|
||||
# ui nav functions
|
||||
# ui navigator functions
|
||||
|
||||
def nav_erc1155_safe_transfer_from(is_nano: bool,
|
||||
chain_id: int,
|
||||
@@ -323,13 +325,13 @@ actions_1155 = [
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture(params=collecs_1155)
|
||||
def collec_1155(request) -> bool:
|
||||
@pytest.fixture(name="collec_1155", params=collecs_1155)
|
||||
def collec_1155_fixture(request) -> bool:
|
||||
return request.param
|
||||
|
||||
|
||||
@pytest.fixture(params=actions_1155)
|
||||
def action_1155(request) -> Action:
|
||||
@pytest.fixture(name="action_1155", params=actions_1155)
|
||||
def action_1155_fixture(request) -> Action:
|
||||
return request.param
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
from ragger.backend import BackendInterface
|
||||
from ragger.firmware import Firmware
|
||||
from ragger.navigator import Navigator, NavInsID
|
||||
from web3 import Web3
|
||||
|
||||
from ledger_app_clients.ethereum.client import EthAppClient
|
||||
import ledger_app_clients.ethereum.response_parser as ResponseParser
|
||||
from ledger_app_clients.ethereum.utils import recover_transaction
|
||||
from web3 import Web3
|
||||
|
||||
from ragger.backend import BackendInterface
|
||||
from ragger.firmware import Firmware
|
||||
from ragger.navigator import Navigator, NavInsID
|
||||
|
||||
|
||||
# Values used across all tests
|
||||
@@ -17,18 +19,18 @@ GAS_LIMIT = 21000
|
||||
AMOUNT = 1.22
|
||||
|
||||
|
||||
def common(fw: Firmware,
|
||||
back: BackendInterface,
|
||||
nav: Navigator,
|
||||
def common(firmware: Firmware,
|
||||
backend: BackendInterface,
|
||||
navigator: Navigator,
|
||||
tx_params: dict):
|
||||
app_client = EthAppClient(back)
|
||||
app_client = EthAppClient(backend)
|
||||
|
||||
with app_client.get_public_addr(display=False):
|
||||
pass
|
||||
_, DEVICE_ADDR, _ = ResponseParser.pk_addr(app_client.response().data)
|
||||
|
||||
with app_client.sign(BIP32_PATH, tx_params):
|
||||
if fw.device.startswith("nano"):
|
||||
if firmware.device.startswith("nano"):
|
||||
next_action = NavInsID.RIGHT_CLICK
|
||||
confirm_action = NavInsID.BOTH_CLICK
|
||||
end_text = "Accept"
|
||||
@@ -36,7 +38,7 @@ def common(fw: Firmware,
|
||||
next_action = NavInsID.USE_CASE_REVIEW_TAP
|
||||
confirm_action = NavInsID.USE_CASE_REVIEW_CONFIRM
|
||||
end_text = "Sign"
|
||||
nav.navigate_until_text(next_action, [confirm_action], end_text)
|
||||
navigator.navigate_until_text(next_action, [confirm_action], end_text)
|
||||
|
||||
# verify signature
|
||||
vrs = ResponseParser.signature(app_client.response().data)
|
||||
|
||||
Reference in New Issue
Block a user