1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-14 03:30:02 +00:00

tests: update cardano tests

[no changelog]
This commit is contained in:
M1nd3r 2024-10-04 17:56:36 +02:00
parent c3e38d612c
commit 1d9f410a07
4 changed files with 40 additions and 44 deletions

View File

@ -22,7 +22,7 @@ from trezorlib.cardano import (
get_public_key,
parse_optional_bytes,
)
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.debuglink import SessionDebugWrapper as Session
from trezorlib.messages import CardanoAddressType, CardanoDerivationType
from trezorlib.tools import parse_path
@ -48,15 +48,15 @@ pytestmark = [
"cardano/get_base_address.derivations.json",
)
@pytest.mark.parametrize("chunkify", (True, False))
def test_cardano_get_address(client: Client, chunkify: bool, parameters, result):
client.init_device(new_session=True, derive_cardano=True)
def test_cardano_get_address(session: Session, chunkify: bool, parameters, result):
# session.init_device(new_session=True, derive_cardano=True)
derivation_type = CardanoDerivationType.__members__[
parameters.get("derivation_type", "ICARUS_TREZOR")
]
address = get_address(
client,
session,
address_parameters=create_address_parameters(
address_type=getattr(
CardanoAddressType, parameters["address_type"].upper()
@ -94,17 +94,17 @@ def test_cardano_get_address(client: Client, chunkify: bool, parameters, result)
"cardano/get_public_key.slip39.json",
"cardano/get_public_key.derivations.json",
)
def test_cardano_get_public_key(client: Client, parameters, result):
with client:
IF = InputFlowShowXpubQRCode(client, passphrase=bool(client.ui.passphrase))
def test_cardano_get_public_key(session: Session, parameters, result):
with session, session.client as client:
IF = InputFlowShowXpubQRCode(client, passphrase=False)
client.set_input_flow(IF.get())
client.init_device(new_session=True, derive_cardano=True)
# session.init_device(new_session=True, derive_cardano=True)
derivation_type = CardanoDerivationType.__members__[
parameters.get("derivation_type", "ICARUS_TREZOR")
]
key = get_public_key(
client, parse_path(parameters["path"]), derivation_type, show_display=True
session, parse_path(parameters["path"]), derivation_type, show_display=True
)
assert key.node.public_key.hex() == result["public_key"]

View File

@ -17,7 +17,7 @@
import pytest
from trezorlib.cardano import get_public_key
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.debuglink import SessionDebugWrapper as Session
from trezorlib.exceptions import TrezorFailure
from trezorlib.messages import CardanoDerivationType as D
from trezorlib.tools import parse_path
@ -26,35 +26,32 @@ from ...common import MNEMONIC_SLIP39_BASIC_20_3of6
pytestmark = [
pytest.mark.altcoin,
pytest.mark.cardano,
pytest.mark.skip_t1b1,
]
ADDRESS_N = parse_path("m/1852h/1815h/0h")
def test_bad_session(client: Client):
client.init_device(new_session=True)
def test_bad_session(session: Session):
with pytest.raises(TrezorFailure, match="not enabled"):
get_public_key(client, ADDRESS_N, derivation_type=D.ICARUS)
client.init_device(new_session=True, derive_cardano=False)
with pytest.raises(TrezorFailure, match="not enabled"):
get_public_key(client, ADDRESS_N, derivation_type=D.ICARUS)
get_public_key(session, ADDRESS_N, derivation_type=D.ICARUS)
def test_ledger_available_always(client: Client):
client.init_device(new_session=True, derive_cardano=False)
get_public_key(client, ADDRESS_N, derivation_type=D.LEDGER)
def test_ledger_available_without_cardano(session: Session):
# session.init_device(new_session=True, derive_cardano=False)
get_public_key(session, ADDRESS_N, derivation_type=D.LEDGER)
client.init_device(new_session=True, derive_cardano=True)
get_public_key(client, ADDRESS_N, derivation_type=D.LEDGER)
@pytest.mark.cardano
def test_ledger_available_with_cardano(session: Session):
# session.init_device(new_session=True, derive_cardano=True)
get_public_key(session, ADDRESS_N, derivation_type=D.LEDGER)
@pytest.mark.setup_client(mnemonic=MNEMONIC_SLIP39_BASIC_20_3of6)
@pytest.mark.parametrize("derivation_type", D) # try ALL derivation types
def test_derivation_irrelevant_on_slip39(client: Client, derivation_type):
client.init_device(new_session=True, derive_cardano=False)
pubkey = get_public_key(client, ADDRESS_N, derivation_type=D.ICARUS)
test_pubkey = get_public_key(client, ADDRESS_N, derivation_type=derivation_type)
def test_derivation_irrelevant_on_slip39(session: Session, derivation_type):
# session.init_device(new_session=True, derive_cardano=False)
pubkey = get_public_key(session, ADDRESS_N, derivation_type=D.ICARUS)
test_pubkey = get_public_key(session, ADDRESS_N, derivation_type=derivation_type)
assert pubkey == test_pubkey

View File

@ -18,7 +18,7 @@ import pytest
from trezorlib import messages
from trezorlib.cardano import get_native_script_hash, parse_native_script
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.debuglink import SessionDebugWrapper as Session
from ...common import parametrize_using_common_fixtures
@ -32,11 +32,9 @@ pytestmark = [
@parametrize_using_common_fixtures(
"cardano/get_native_script_hash.json",
)
def test_cardano_get_native_script_hash(client: Client, parameters, result):
client.init_device(new_session=True, derive_cardano=True)
def test_cardano_get_native_script_hash(session: Session, parameters, result):
native_script_hash = get_native_script_hash(
client,
session,
native_script=parse_native_script(parameters["native_script"]),
display_format=messages.CardanoNativeScriptHashDisplayFormat.__members__[
parameters["display_format"]

View File

@ -17,6 +17,7 @@
import pytest
from trezorlib import cardano, device, messages, models
from trezorlib.debuglink import SessionDebugWrapper as Session
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.exceptions import TrezorFailure
@ -53,9 +54,9 @@ def show_details_input_flow(client: Client):
"cardano/sign_tx.plutus.json",
"cardano/sign_tx.slip39.json",
)
def test_cardano_sign_tx(client: Client, parameters, result):
def test_cardano_sign_tx(session: Session, parameters, result):
response = call_sign_tx(
client,
session,
parameters,
input_flow=lambda client: InputFlowConfirmAllWarnings(client).get(),
)
@ -64,8 +65,8 @@ def test_cardano_sign_tx(client: Client, parameters, result):
@pytest.mark.skip_t3t1(reason="Not yet implemented in new UI")
@parametrize_using_common_fixtures("cardano/sign_tx.show_details.json")
def test_cardano_sign_tx_show_details(client: Client, parameters, result):
response = call_sign_tx(client, parameters, show_details_input_flow, chunkify=True)
def test_cardano_sign_tx_show_details(session: Session, parameters, result):
response = call_sign_tx(session, parameters, show_details_input_flow, chunkify=True)
assert response == _transform_expected_result(result)
@ -75,13 +76,13 @@ def test_cardano_sign_tx_show_details(client: Client, parameters, result):
"cardano/sign_tx.multisig.failed.json",
"cardano/sign_tx.plutus.failed.json",
)
def test_cardano_sign_tx_failed(client: Client, parameters, result):
def test_cardano_sign_tx_failed(session: Session, parameters, result):
with pytest.raises(TrezorFailure, match=result["error_message"]):
call_sign_tx(client, parameters, None)
call_sign_tx(session, parameters, None)
def call_sign_tx(client: Client, parameters, input_flow=None, chunkify: bool = False):
client.init_device(new_session=True, derive_cardano=True)
def call_sign_tx(session: Session, parameters, input_flow=None, chunkify: bool = False):
# session.init_device(new_session=True, derive_cardano=True)
signing_mode = messages.CardanoTxSigningMode.__members__[parameters["signing_mode"]]
inputs = [cardano.parse_input(i) for i in parameters["inputs"]]
@ -112,18 +113,18 @@ def call_sign_tx(client: Client, parameters, input_flow=None, chunkify: bool = F
if parameters.get("security_checks") == "prompt":
device.apply_settings(
client, safety_checks=messages.SafetyCheckLevel.PromptTemporarily
session, safety_checks=messages.SafetyCheckLevel.PromptTemporarily
)
else:
device.apply_settings(client, safety_checks=messages.SafetyCheckLevel.Strict)
device.apply_settings(session, safety_checks=messages.SafetyCheckLevel.Strict)
with client:
with session.client as client:
if input_flow is not None:
client.watch_layout()
client.set_input_flow(input_flow(client))
return cardano.sign_tx(
client=client,
session=session,
signing_mode=signing_mode,
inputs=inputs,
outputs=outputs,