Files
app-ethereum/tests/ragger/test_get_address.py
defiQUG e941a5d06d
Some checks failed
Build and run functional tests using ragger through reusable workflow / Build application using the reusable workflow (push) Has been cancelled
Build and run functional tests using ragger through reusable workflow / Build Clone app using the reusable workflow (push) Has been cancelled
Check SDK submodule version / Check Ethereum plugin SDK submodule is up-to-date (push) Has been cancelled
CodeQL / Analyse (cpp, $FLEX_SDK) (push) Has been cancelled
CodeQL / Analyse (cpp, $NANOSP_SDK) (push) Has been cancelled
CodeQL / Analyse (cpp, $NANOS_SDK) (push) Has been cancelled
CodeQL / Analyse (cpp, $NANOX_SDK) (push) Has been cancelled
CodeQL / Analyse (cpp, $STAX_SDK) (push) Has been cancelled
Misspellings CI / Check misspellings (push) Has been cancelled
Ensure compliance with Ledger guidelines / Call Ledger guidelines_enforcer (push) Has been cancelled
Code style check / Check linting using the reusable workflow (push) Has been cancelled
Code style check / Check yaml files (push) Has been cancelled
Swap functional tests / job_functional_tests (push) Has been cancelled
Build and run functional tests using ragger through reusable workflow / Run ragger tests using the reusable workflow (push) Has been cancelled
Build and run functional tests using ragger through reusable workflow / Run ragger Clone tests using the reusable workflow (push) Has been cancelled
Added Chain: Defi Oracle Meta - Chain ID 138
- Added new glyph and icon for Chain 138
- Created makefile configuration for Defi Oracle
- Updated network handling in src/network.c
- Modified address retrieval test
2024-08-08 00:04:03 -07:00

83 lines
2.8 KiB
Python

from typing import Optional
import pytest
from py_ecc.bls import G2ProofOfPossession as bls
from staking_deposit.key_handling.key_derivation.path import mnemonic_and_path_to_key
from ragger.bip.seed import SPECULOS_MNEMONIC
from ragger.error import ExceptionRAPDU
from ragger.firmware import Firmware
from ragger.backend import BackendInterface
from ragger.navigator.navigation_scenario import NavigateWithScenario
from ragger.bip import calculate_public_key_and_chaincode, CurveChoice
from client.client import EthAppClient, StatusWord
import client.response_parser as ResponseParser
@pytest.fixture(name="with_chaincode", params=[True, False])
def with_chaincode_fixture(request) -> bool:
return request.param
@pytest.fixture(name="chain", params=[None, 1, 2, 5, 137, 138])
def chain_fixture(request) -> Optional[int]:
return request.param
@pytest.mark.parametrize(
"path, suffix",
[
("m/44'/60'/0'/0/0", "60"),
("m/44'/700'/1'/0/0", "700")
],
)
def test_get_pk_rejected(backend: BackendInterface,
scenario_navigator: NavigateWithScenario,
path,
suffix):
app_client = EthAppClient(backend)
with pytest.raises(ExceptionRAPDU) as e:
with app_client.get_public_addr(bip32_path=path):
scenario_navigator.address_review_reject(test_name=f"get_pk_rejected_{suffix}")
assert e.value.status == StatusWord.CONDITION_NOT_SATISFIED
def test_get_pk(backend: BackendInterface,
scenario_navigator: NavigateWithScenario,
with_chaincode: bool,
chain: Optional[int]):
app_client = EthAppClient(backend)
with app_client.get_public_addr(chaincode=with_chaincode, chain_id=chain):
scenario_navigator.address_review_approve(test_name=f"get_pk_{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
if with_chaincode:
assert chaincode.hex() == ref_chaincode
def test_get_eth2_pk(firmware: Firmware,
backend: BackendInterface,
scenario_navigator: NavigateWithScenario,
test_name: str):
app_client = EthAppClient(backend)
path="m/12381/3600/0/0"
with app_client.get_eth2_public_addr(bip32_path=path):
scenario_navigator.address_review_approve(test_name=test_name)
pk = app_client.response().data
ref_pk = bls.SkToPk(mnemonic_and_path_to_key(SPECULOS_MNEMONIC, path))
if firmware in (Firmware.STAX, Firmware.FLEX):
pk = pk[1:49]
assert pk == ref_pk