Skip to content

Commit

Permalink
[tests] add tests for bls/tz4
Browse files Browse the repository at this point in the history
  • Loading branch information
spalmer25 committed Oct 24, 2024
1 parent 212dbf4 commit 4591406
Show file tree
Hide file tree
Showing 170 changed files with 128 additions and 17 deletions.
14 changes: 13 additions & 1 deletion test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@
2
)

TZ4_ACCOUNT = Account(
"m/44'/1729'/0'/0'",
SigScheme.BLS,
"BLsk2Q1AdMSKNJbM1fLqHEWgaEDUz2odGrgPuCV1bxtzAedVEC2RSz",
3
)

LONG_TZ1_ACCOUNT = Account(
"m/9'/12'/13'/8'/78'",
SigScheme.ED25519,
Expand All @@ -75,13 +82,18 @@
TZ3_ACCOUNT,
]

ACCOUNTS = TZ1_ACCOUNTS + TZ2_ACCOUNTS + TZ3_ACCOUNTS
TZ4_ACCOUNTS = [
TZ4_ACCOUNT,
]

ACCOUNTS = TZ1_ACCOUNTS + TZ2_ACCOUNTS + TZ3_ACCOUNTS + TZ4_ACCOUNTS

ZEBRA_ACCOUNTS = [
TZ1_ACCOUNT,
TZ2_ACCOUNT,
TZ3_ACCOUNT,
BIP32_TZ1_ACCOUNT,
TZ4_ACCOUNT,
]

EMPTY_PATH = BipPath.from_string("m")
17 changes: 17 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@

"""Pytest configuration file."""

from functools import wraps
import pytest

from ragger.backend import BackendInterface
from ragger.conftest import configuration
from ragger.firmware import Firmware
from ragger.navigator import Navigator
from utils.account import SigScheme
from utils.client import TezosClient
from utils.navigator import TezosNavigator
from common import DEFAULT_SEED
Expand All @@ -44,3 +47,17 @@ def tezos_navigator(
test_name: str) -> TezosNavigator:
"""Get a tezos navigator."""
return TezosNavigator(backend, firmware, client, navigator, golden_run, test_name)

def skip_nanos_bls(func):
"""Allows to skip tests with BLS `account` on NanoS device"""
@wraps(func)
def wrap(*args, **kwargs):
account = kwargs.get("account", None)
firmware = kwargs.get("firmware", None)
if firmware is not None \
and firmware.name == "nanos" \
and account is not None \
and account.sig_scheme == SigScheme.BLS:
pytest.skip("NanoS does not support BLS")
return func(*args, **kwargs)
return wrap
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 43 additions & 7 deletions test/test_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
import hmac
import time

from functools import wraps
import pytest
from conftest import skip_nanos_bls

from ragger.backend import BackendInterface
from ragger.firmware import Firmware
from utils.client import TezosClient, Version, Hwm, StatusCode
from utils.account import Account, PublicKey
from utils.account import Account, PublicKey, SigScheme
from utils.helper import get_current_commit
from utils.message import (
Message,
Expand Down Expand Up @@ -57,6 +59,7 @@
ZEBRA_ACCOUNTS,
)

@skip_nanos_bls
@pytest.mark.parametrize("account", [None, *ACCOUNTS])
def test_review_home(account: Optional[Account],
backend: BackendInterface,
Expand Down Expand Up @@ -502,8 +505,10 @@ def test_ledger_screensaver(firmware: Firmware,
assert (res.find("y") != -1), "Ledger screensaver should have activated"


@skip_nanos_bls
@pytest.mark.parametrize("account", ZEBRA_ACCOUNTS)
def test_benchmark_attestation_time(account: Account,
firmware: Firmware,
client: TezosClient,
tezos_navigator: TezosNavigator,
backend_name) -> None:
Expand Down Expand Up @@ -549,8 +554,11 @@ def test_benchmark_attestation_time(account: Account,
)


@skip_nanos_bls
@pytest.mark.parametrize("account", ACCOUNTS)
def test_authorize_baking(account: Account, tezos_navigator: TezosNavigator) -> None:
def test_authorize_baking(account: Account,
firmware: Firmware,
tezos_navigator: TezosNavigator) -> None:
"""Test the AUTHORIZE_BAKING instruction."""
snap_path = Path(f"{account}")

Expand Down Expand Up @@ -599,9 +607,11 @@ def test_deauthorize(firmware: Firmware,
test_hwm=Hwm(0, 0)
)

@skip_nanos_bls
@pytest.mark.parametrize("account", ACCOUNTS)
def test_get_auth_key(
account: Account,
firmware: Firmware,
client: TezosClient,
tezos_navigator: TezosNavigator) -> None:
"""Test the QUERY_AUTH_KEY instruction."""
Expand All @@ -613,9 +623,11 @@ def test_get_auth_key(
assert path == account.path, \
f"Expected {account.path} but got {path}"

@skip_nanos_bls
@pytest.mark.parametrize("account", ACCOUNTS)
def test_get_auth_key_with_curve(
account: Account,
firmware: Firmware,
client: TezosClient,
tezos_navigator: TezosNavigator) -> None:
"""Test the QUERY_AUTH_KEY_WITH_CURVE instruction."""
Expand All @@ -630,8 +642,11 @@ def test_get_auth_key_with_curve(
assert sig_scheme == account.sig_scheme, \
f"Expected {account.sig_scheme.name} but got {sig_scheme.name}"

@skip_nanos_bls
@pytest.mark.parametrize("account", ACCOUNTS)
def test_get_public_key_baking(account: Account, tezos_navigator: TezosNavigator) -> None:
def test_get_public_key_baking(account: Account,
firmware: Firmware,
tezos_navigator: TezosNavigator) -> None:
"""Test the AUTHORIZE_BAKING instruction."""

tezos_navigator.authorize_baking(account)
Expand All @@ -644,8 +659,11 @@ def test_get_public_key_baking(account: Account, tezos_navigator: TezosNavigator
f"Expected public key {account.public_key} but got {public_key}"


@skip_nanos_bls
@pytest.mark.parametrize("account", ACCOUNTS)
def test_get_public_key_silent(account: Account, client: TezosClient) -> None:
def test_get_public_key_silent(account: Account,
firmware: Firmware,
client: TezosClient) -> None:
"""Test the GET_PUBLIC_KEY instruction."""

public_key = client.get_public_key_silent(account)
Expand All @@ -654,8 +672,11 @@ def test_get_public_key_silent(account: Account, client: TezosClient) -> None:
f"Expected public key {account.public_key} but got {public_key}"


@skip_nanos_bls
@pytest.mark.parametrize("account", ACCOUNTS)
def test_get_public_key_prompt(account: Account, tezos_navigator: TezosNavigator) -> None:
def test_get_public_key_prompt(account: Account,
firmware: Firmware,
tezos_navigator: TezosNavigator) -> None:
"""Test the PROMPT_PUBLIC_KEY instruction."""

public_key = tezos_navigator.get_public_key_prompt(account, snap_path=Path(f"{account}"))
Expand All @@ -679,8 +700,11 @@ def test_reset_app_context(tezos_navigator: TezosNavigator) -> None:
)


@skip_nanos_bls
@pytest.mark.parametrize("account", ACCOUNTS)
def test_setup_app_context(account: Account, tezos_navigator: TezosNavigator) -> None:
def test_setup_app_context(account: Account,
firmware: Firmware,
tezos_navigator: TezosNavigator) -> None:
"""Test the SETUP instruction."""
snap_path = Path(f"{account}")

Expand All @@ -707,9 +731,11 @@ def test_setup_app_context(account: Account, tezos_navigator: TezosNavigator) ->
)


@skip_nanos_bls
@pytest.mark.parametrize("account", ACCOUNTS)
def test_get_main_hwm(
account: Account,
firmware: Firmware,
client: TezosClient,
tezos_navigator: TezosNavigator) -> None:
"""Test the QUERY_MAIN_HWM instruction."""
Expand All @@ -731,9 +757,11 @@ def test_get_main_hwm(
f"Expected main hmw {main_hwm} but got {received_main_hwm}"


@skip_nanos_bls
@pytest.mark.parametrize("account", ACCOUNTS)
def test_get_all_hwm(
account: Account,
firmware: Firmware,
client: TezosClient,
tezos_navigator: TezosNavigator) -> None:
"""Test the QUERY_ALL_HWM instruction."""
Expand Down Expand Up @@ -797,6 +825,7 @@ def build_block(level, current_round, chain_id):
)


@skip_nanos_bls
@pytest.mark.parametrize("account", ACCOUNTS)
@pytest.mark.parametrize("with_hash", [False, True])
def test_sign_preattestation(
Expand Down Expand Up @@ -854,6 +883,7 @@ def test_sign_preattestation(
)


@skip_nanos_bls
@pytest.mark.parametrize("account", ACCOUNTS)
@pytest.mark.parametrize("with_hash", [False, True])
def test_sign_attestation(
Expand Down Expand Up @@ -911,6 +941,7 @@ def test_sign_attestation(
)


@skip_nanos_bls
@pytest.mark.parametrize("account", ACCOUNTS)
@pytest.mark.parametrize("with_hash", [False, True])
def test_sign_attestation_dal(
Expand Down Expand Up @@ -968,6 +999,7 @@ def test_sign_attestation_dal(
)


@skip_nanos_bls
@pytest.mark.parametrize("account", ACCOUNTS)
@pytest.mark.parametrize("with_hash", [False, True])
def test_sign_block(
Expand Down Expand Up @@ -1126,11 +1158,13 @@ def test_sign_level_authorized(
client.sign_message(account, message_2)


@skip_nanos_bls
@pytest.mark.parametrize("account", ACCOUNTS)
@pytest.mark.parametrize("with_hash", [False, True])
def test_sign_delegation(
account: Account,
with_hash: bool,
firmware: Firmware,
tezos_navigator: TezosNavigator) -> None:
"""Test the SIGN(_WITH_HASH) instruction on delegation."""
snap_path = Path(f"{account}")
Expand Down Expand Up @@ -1261,11 +1295,13 @@ def test_sign_delegation_constraints(
)


@skip_nanos_bls
@pytest.mark.parametrize("account", ACCOUNTS)
@pytest.mark.parametrize("with_hash", [False, True])
def test_sign_reveal(
account: Account,
with_hash: bool,
firmware: Firmware,
client: TezosClient,
tezos_navigator: TezosNavigator) -> None:
"""Test the SIGN(_WITH_HASH) instruction on reveal."""
Expand Down Expand Up @@ -1778,7 +1814,7 @@ def get_hmac_key(account):
("0123456789abcdef0123456789abcdef0123456789abcdef")
]

# This HMAC test don't pass with tz2 and tz3
# This HMAC test don't pass with tz2, tz3 and tz4
@pytest.mark.parametrize("account", TZ1_ACCOUNTS)
@pytest.mark.parametrize("message_hex", HMAC_TEST_SET)
def test_hmac(
Expand Down
Loading

0 comments on commit 4591406

Please sign in to comment.