Skip to content

Commit

Permalink
Merge pull request #26 from trilitech/palmer@functori@test-hwm
Browse files Browse the repository at this point in the history
Tests: add test for hwm behaviour
  • Loading branch information
spalmer25 authored Feb 6, 2024
2 parents 4b04f50 + 31d4c4e commit 5c32ad2
Show file tree
Hide file tree
Showing 34 changed files with 122 additions and 2 deletions.
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.
124 changes: 122 additions & 2 deletions test/python/test_instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def test_setup_app_context(account: Account, tezos_navigator: TezosNavigator) ->
"""Test the SETUP instruction."""
snap_path = Path(f"{account}")

main_chain_id = "NetXH12AexHqTQa"
main_chain_id = "NetXH12AexHqTQa" # Chain = 1
main_hwm = Hwm(1)
test_hwm = Hwm(2)

Expand Down Expand Up @@ -588,7 +588,7 @@ def test_sign_level_authorized(
def test_sign_not_authorized_key(
client: TezosClient,
tezos_navigator: TezosNavigator) -> None:
"""Check that signing with a key different from the authorized key is not authorized.."""
"""Check that signing with a key different from the authorized key is not authorized."""

account_1 = DEFAULT_ACCOUNT
account_2 = DEFAULT_ACCOUNT_2
Expand All @@ -608,6 +608,126 @@ def test_sign_not_authorized_key(
client.sign_message(account_2, attestation)


def test_sign_when_no_chain_setup(
client: TezosClient,
tezos_navigator: TezosNavigator) -> None:
"""Check that signing when no chain has been setup change main HWM."""

account = DEFAULT_ACCOUNT

tezos_navigator.setup_app_context(
account,
DEFAULT_CHAIN_ID, # Chain = 0
main_hwm=Hwm(0),
test_hwm=Hwm(0)
)

attestation = build_attestation(
1, 0,
DEFAULT_CHAIN_ID # Chain = 0
)

client.sign_message(account, attestation)

tezos_navigator.check_app_context(
account,
chain_id=DEFAULT_CHAIN_ID,
main_hwm=Hwm(1, 0),
test_hwm=Hwm(0, 0),
snap_path=Path("sign_1_0")
)

attestation = build_attestation(
2, 0,
"NetXH12AexHqTQa" # Chain = 1
)

client.sign_message(account, attestation)

tezos_navigator.check_app_context(
account,
chain_id=DEFAULT_CHAIN_ID,
main_hwm=Hwm(2, 0),
test_hwm=Hwm(0, 0),
snap_path=Path("sign_2_0")
)

attestation = build_attestation(
2, 0,
"NetXH12Af5mrXhq" # Chain = 2
)

with StatusCode.WRONG_VALUES.expected():
client.sign_message(account, attestation)

tezos_navigator.check_app_context(
account,
chain_id=DEFAULT_CHAIN_ID,
main_hwm=Hwm(2, 0),
test_hwm=Hwm(0, 0),
snap_path=Path("sign_2_0")
)


def test_sign_when_chain_is_setup(
client: TezosClient,
tezos_navigator: TezosNavigator) -> None:
"""Check that signing when chain has been setup change main HWM."""

account = DEFAULT_ACCOUNT
main_chain_id = "NetXH12AexHqTQa" # Chain = 1

tezos_navigator.setup_app_context(
account,
main_chain_id,
main_hwm=Hwm(0),
test_hwm=Hwm(0)
)

attestation = build_attestation(
1, 0,
main_chain_id
)

client.sign_message(account, attestation)

tezos_navigator.check_app_context(
account,
chain_id=main_chain_id,
main_hwm=Hwm(1, 0),
test_hwm=Hwm(0, 0),
)

attestation = build_attestation(
2, 0,
DEFAULT_CHAIN_ID # Chain = 0
)

client.sign_message(account, attestation)

tezos_navigator.check_app_context(
account,
chain_id=main_chain_id,
main_hwm=Hwm(1, 0),
test_hwm=Hwm(2, 0),
)

attestation = build_attestation(
2, 0,
"NetXH12Af5mrXhq" # Chain = 2
)

with StatusCode.WRONG_VALUES.expected():
client.sign_message(account, attestation)

tezos_navigator.check_app_context(
account,
chain_id=main_chain_id,
main_hwm=Hwm(1, 0),
test_hwm=Hwm(2, 0),
)


# Data generated by the old application itself
HMAC_TEST_SET = [
(DEFAULT_ACCOUNT,
Expand Down

0 comments on commit 5c32ad2

Please sign in to comment.