diff --git a/test/python/snapshots/nanos/test_sign_when_chain_is_setup/app_context/chain_id.png b/test/python/snapshots/nanos/test_sign_when_chain_is_setup/app_context/chain_id.png new file mode 100644 index 00000000..13fd7604 Binary files /dev/null and b/test/python/snapshots/nanos/test_sign_when_chain_is_setup/app_context/chain_id.png differ diff --git a/test/python/snapshots/nanos/test_sign_when_chain_is_setup/app_context/high_watermark.png b/test/python/snapshots/nanos/test_sign_when_chain_is_setup/app_context/high_watermark.png new file mode 100644 index 00000000..0cccb5b4 Binary files /dev/null and b/test/python/snapshots/nanos/test_sign_when_chain_is_setup/app_context/high_watermark.png differ diff --git a/test/python/snapshots/nanos/test_sign_when_chain_is_setup/app_context/public_key_hash_1.png b/test/python/snapshots/nanos/test_sign_when_chain_is_setup/app_context/public_key_hash_1.png new file mode 100644 index 00000000..50537f75 Binary files /dev/null and b/test/python/snapshots/nanos/test_sign_when_chain_is_setup/app_context/public_key_hash_1.png differ diff --git a/test/python/snapshots/nanos/test_sign_when_chain_is_setup/app_context/public_key_hash_2.png b/test/python/snapshots/nanos/test_sign_when_chain_is_setup/app_context/public_key_hash_2.png new file mode 100644 index 00000000..a30fbd95 Binary files /dev/null and b/test/python/snapshots/nanos/test_sign_when_chain_is_setup/app_context/public_key_hash_2.png differ diff --git a/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_1_0/app_context/chain_id.png b/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_1_0/app_context/chain_id.png new file mode 100644 index 00000000..a13210c5 Binary files /dev/null and b/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_1_0/app_context/chain_id.png differ diff --git a/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_1_0/app_context/high_watermark.png b/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_1_0/app_context/high_watermark.png new file mode 100644 index 00000000..0cccb5b4 Binary files /dev/null and b/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_1_0/app_context/high_watermark.png differ diff --git a/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_1_0/app_context/public_key_hash_1.png b/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_1_0/app_context/public_key_hash_1.png new file mode 100644 index 00000000..50537f75 Binary files /dev/null and b/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_1_0/app_context/public_key_hash_1.png differ diff --git a/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_1_0/app_context/public_key_hash_2.png b/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_1_0/app_context/public_key_hash_2.png new file mode 100644 index 00000000..a30fbd95 Binary files /dev/null and b/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_1_0/app_context/public_key_hash_2.png differ diff --git a/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_2_0/app_context/chain_id.png b/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_2_0/app_context/chain_id.png new file mode 100644 index 00000000..a13210c5 Binary files /dev/null and b/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_2_0/app_context/chain_id.png differ diff --git a/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_2_0/app_context/high_watermark.png b/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_2_0/app_context/high_watermark.png new file mode 100644 index 00000000..b117e76a Binary files /dev/null and b/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_2_0/app_context/high_watermark.png differ diff --git a/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_2_0/app_context/public_key_hash_1.png b/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_2_0/app_context/public_key_hash_1.png new file mode 100644 index 00000000..50537f75 Binary files /dev/null and b/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_2_0/app_context/public_key_hash_1.png differ diff --git a/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_2_0/app_context/public_key_hash_2.png b/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_2_0/app_context/public_key_hash_2.png new file mode 100644 index 00000000..a30fbd95 Binary files /dev/null and b/test/python/snapshots/nanos/test_sign_when_no_chain_setup/sign_2_0/app_context/public_key_hash_2.png differ diff --git a/test/python/snapshots/nanosp/test_sign_when_chain_is_setup/app_context/chain_id.png b/test/python/snapshots/nanosp/test_sign_when_chain_is_setup/app_context/chain_id.png new file mode 100644 index 00000000..8795bcf1 Binary files /dev/null and b/test/python/snapshots/nanosp/test_sign_when_chain_is_setup/app_context/chain_id.png differ diff --git a/test/python/snapshots/nanosp/test_sign_when_chain_is_setup/app_context/high_watermark.png b/test/python/snapshots/nanosp/test_sign_when_chain_is_setup/app_context/high_watermark.png new file mode 100644 index 00000000..a970fc01 Binary files /dev/null and b/test/python/snapshots/nanosp/test_sign_when_chain_is_setup/app_context/high_watermark.png differ diff --git a/test/python/snapshots/nanosp/test_sign_when_chain_is_setup/app_context/public_key_hash.png b/test/python/snapshots/nanosp/test_sign_when_chain_is_setup/app_context/public_key_hash.png new file mode 100644 index 00000000..a2b2f3cf Binary files /dev/null and b/test/python/snapshots/nanosp/test_sign_when_chain_is_setup/app_context/public_key_hash.png differ diff --git a/test/python/snapshots/nanosp/test_sign_when_no_chain_setup/sign_1_0/app_context/chain_id.png b/test/python/snapshots/nanosp/test_sign_when_no_chain_setup/sign_1_0/app_context/chain_id.png new file mode 100644 index 00000000..1dd81a6c Binary files /dev/null and b/test/python/snapshots/nanosp/test_sign_when_no_chain_setup/sign_1_0/app_context/chain_id.png differ diff --git a/test/python/snapshots/nanosp/test_sign_when_no_chain_setup/sign_1_0/app_context/high_watermark.png b/test/python/snapshots/nanosp/test_sign_when_no_chain_setup/sign_1_0/app_context/high_watermark.png new file mode 100644 index 00000000..a970fc01 Binary files /dev/null and b/test/python/snapshots/nanosp/test_sign_when_no_chain_setup/sign_1_0/app_context/high_watermark.png differ diff --git a/test/python/snapshots/nanosp/test_sign_when_no_chain_setup/sign_1_0/app_context/public_key_hash.png b/test/python/snapshots/nanosp/test_sign_when_no_chain_setup/sign_1_0/app_context/public_key_hash.png new file mode 100644 index 00000000..a2b2f3cf Binary files /dev/null and b/test/python/snapshots/nanosp/test_sign_when_no_chain_setup/sign_1_0/app_context/public_key_hash.png differ diff --git a/test/python/snapshots/nanosp/test_sign_when_no_chain_setup/sign_2_0/app_context/chain_id.png b/test/python/snapshots/nanosp/test_sign_when_no_chain_setup/sign_2_0/app_context/chain_id.png new file mode 100644 index 00000000..1dd81a6c Binary files /dev/null and b/test/python/snapshots/nanosp/test_sign_when_no_chain_setup/sign_2_0/app_context/chain_id.png differ diff --git a/test/python/snapshots/nanosp/test_sign_when_no_chain_setup/sign_2_0/app_context/high_watermark.png b/test/python/snapshots/nanosp/test_sign_when_no_chain_setup/sign_2_0/app_context/high_watermark.png new file mode 100644 index 00000000..3a5efb2f Binary files /dev/null and b/test/python/snapshots/nanosp/test_sign_when_no_chain_setup/sign_2_0/app_context/high_watermark.png differ diff --git a/test/python/snapshots/nanosp/test_sign_when_no_chain_setup/sign_2_0/app_context/public_key_hash.png b/test/python/snapshots/nanosp/test_sign_when_no_chain_setup/sign_2_0/app_context/public_key_hash.png new file mode 100644 index 00000000..a2b2f3cf Binary files /dev/null and b/test/python/snapshots/nanosp/test_sign_when_no_chain_setup/sign_2_0/app_context/public_key_hash.png differ diff --git a/test/python/snapshots/nanox/test_sign_when_chain_is_setup/app_context/chain_id.png b/test/python/snapshots/nanox/test_sign_when_chain_is_setup/app_context/chain_id.png new file mode 100644 index 00000000..8795bcf1 Binary files /dev/null and b/test/python/snapshots/nanox/test_sign_when_chain_is_setup/app_context/chain_id.png differ diff --git a/test/python/snapshots/nanox/test_sign_when_chain_is_setup/app_context/high_watermark.png b/test/python/snapshots/nanox/test_sign_when_chain_is_setup/app_context/high_watermark.png new file mode 100644 index 00000000..a970fc01 Binary files /dev/null and b/test/python/snapshots/nanox/test_sign_when_chain_is_setup/app_context/high_watermark.png differ diff --git a/test/python/snapshots/nanox/test_sign_when_chain_is_setup/app_context/public_key_hash.png b/test/python/snapshots/nanox/test_sign_when_chain_is_setup/app_context/public_key_hash.png new file mode 100644 index 00000000..a2b2f3cf Binary files /dev/null and b/test/python/snapshots/nanox/test_sign_when_chain_is_setup/app_context/public_key_hash.png differ diff --git a/test/python/snapshots/nanox/test_sign_when_no_chain_setup/sign_1_0/app_context/chain_id.png b/test/python/snapshots/nanox/test_sign_when_no_chain_setup/sign_1_0/app_context/chain_id.png new file mode 100644 index 00000000..1dd81a6c Binary files /dev/null and b/test/python/snapshots/nanox/test_sign_when_no_chain_setup/sign_1_0/app_context/chain_id.png differ diff --git a/test/python/snapshots/nanox/test_sign_when_no_chain_setup/sign_1_0/app_context/high_watermark.png b/test/python/snapshots/nanox/test_sign_when_no_chain_setup/sign_1_0/app_context/high_watermark.png new file mode 100644 index 00000000..a970fc01 Binary files /dev/null and b/test/python/snapshots/nanox/test_sign_when_no_chain_setup/sign_1_0/app_context/high_watermark.png differ diff --git a/test/python/snapshots/nanox/test_sign_when_no_chain_setup/sign_1_0/app_context/public_key_hash.png b/test/python/snapshots/nanox/test_sign_when_no_chain_setup/sign_1_0/app_context/public_key_hash.png new file mode 100644 index 00000000..a2b2f3cf Binary files /dev/null and b/test/python/snapshots/nanox/test_sign_when_no_chain_setup/sign_1_0/app_context/public_key_hash.png differ diff --git a/test/python/snapshots/nanox/test_sign_when_no_chain_setup/sign_2_0/app_context/chain_id.png b/test/python/snapshots/nanox/test_sign_when_no_chain_setup/sign_2_0/app_context/chain_id.png new file mode 100644 index 00000000..1dd81a6c Binary files /dev/null and b/test/python/snapshots/nanox/test_sign_when_no_chain_setup/sign_2_0/app_context/chain_id.png differ diff --git a/test/python/snapshots/nanox/test_sign_when_no_chain_setup/sign_2_0/app_context/high_watermark.png b/test/python/snapshots/nanox/test_sign_when_no_chain_setup/sign_2_0/app_context/high_watermark.png new file mode 100644 index 00000000..3a5efb2f Binary files /dev/null and b/test/python/snapshots/nanox/test_sign_when_no_chain_setup/sign_2_0/app_context/high_watermark.png differ diff --git a/test/python/snapshots/nanox/test_sign_when_no_chain_setup/sign_2_0/app_context/public_key_hash.png b/test/python/snapshots/nanox/test_sign_when_no_chain_setup/sign_2_0/app_context/public_key_hash.png new file mode 100644 index 00000000..a2b2f3cf Binary files /dev/null and b/test/python/snapshots/nanox/test_sign_when_no_chain_setup/sign_2_0/app_context/public_key_hash.png differ diff --git a/test/python/snapshots/stax/test_sign_when_chain_is_setup/app_context/app_context.png b/test/python/snapshots/stax/test_sign_when_chain_is_setup/app_context/app_context.png new file mode 100644 index 00000000..b6aec4c6 Binary files /dev/null and b/test/python/snapshots/stax/test_sign_when_chain_is_setup/app_context/app_context.png differ diff --git a/test/python/snapshots/stax/test_sign_when_no_chain_setup/sign_1_0/app_context/app_context.png b/test/python/snapshots/stax/test_sign_when_no_chain_setup/sign_1_0/app_context/app_context.png new file mode 100644 index 00000000..6092bfb6 Binary files /dev/null and b/test/python/snapshots/stax/test_sign_when_no_chain_setup/sign_1_0/app_context/app_context.png differ diff --git a/test/python/snapshots/stax/test_sign_when_no_chain_setup/sign_2_0/app_context/app_context.png b/test/python/snapshots/stax/test_sign_when_no_chain_setup/sign_2_0/app_context/app_context.png new file mode 100644 index 00000000..98ad7680 Binary files /dev/null and b/test/python/snapshots/stax/test_sign_when_no_chain_setup/sign_2_0/app_context/app_context.png differ diff --git a/test/python/test_instructions.py b/test/python/test_instructions.py index 50653a95..67fffcaa 100644 --- a/test/python/test_instructions.py +++ b/test/python/test_instructions.py @@ -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) @@ -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 @@ -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,