Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

test: add test_public_key_validation #39

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions tests/application_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def condition_folder_name(event_index: int, additional_index: bool, condition_in
return str(event_index) + "_" + str(condition_index)
return str(event_index)


def generic_test_sign(
client: Nearbackend,
chunks: List[Union[bytes, AsyncAPDU]],
Expand All @@ -90,8 +91,8 @@ def generic_test_sign(
if isinstance(chunk_event, NavigableConditions):
for cond_index, condition in enumerate(chunk_event.value):
str_index = condition_folder_name(index, len(chunk_event.value) > 1, cond_index)
condition_folder = (
Path(test_name) / (str_index + "_" + condition.lower().replace(" ", "_"))
condition_folder = Path(test_name) / (
str_index + "_" + condition.lower().replace(" ", "_").replace("!", "_bang")
)
navigator.navigate_until_text_and_compare(
NavInsID.RIGHT_CLICK,
Expand Down
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.
Empty file.
92 changes: 92 additions & 0 deletions tests/test_public_key_validation/test_sign_transaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from application_client.client import (
AsyncAPDU,
SW_OK,
NavigableConditions,
Nearbackend,
FINISH_STUB_APDU,
generic_test_sign,
)
from ragger.backend.interface import RAPDU
from ragger.backend import RaisePolicy
from ragger.navigator import Navigator


def test_sign_wrong_pubkey_transfer(firmware, backend, navigator: Navigator, test_name):
"""
Transaction {
signer_id: AccountId(
"1b11b3b31673033936ad07bddc01f9da27d974811e480fb197c799e23480a489",
),
public_key: ed25519:2pffV8fXgXUyuKdTS8Nqnvbkua16wEtTv8tdWZCpVtat,
nonce: 103595482000005,
receiver_id: AccountId(
"dc7e34eecec3096a4a661e10932834f801149c49dba9b93322f6d9de18047f9c",
),
block_hash: Cb3vKNiF3MUuVoqfjuEFCgSNPT79pbuVfXXd2RxDXc5E,
actions: [
Transfer(
TransferAction {
deposit: 150000000000000000000000,
},
),
],
}
"""
backend.raise_policy = RaisePolicy.RAISE_NOTHING
client = Nearbackend(backend)
chunks = [
AsyncAPDU(
data=bytes.fromhex(
"80028057fa8000002c8000018d8000000080000000800000014000000031623131623362333136373330333339333661643037626464633031663964613237643937343831316534383066623139376337393965323334383061343839001b11b3b31673033936ad07bddc01f9da27d974811e480fb197c799e23480a48985aae733385e00004000000064633765333465656365633330393661346136363165313039333238333466383031313439633439646261396239333332326636643964653138303437663963ac299ac1376e375cd39338d8b29225613ef947424b74a3207c1226863a72583101000000030000c071f0d12b84c31f000000000000"
),
navigable_conditions=NavigableConditions(
value=["Continue to actions", "Error!"],
),
expected_response=RAPDU(
0xB00D,
bytes(),
),
)
]
generic_test_sign(client, chunks, navigator, test_name)

def test_sign_wrong_pubkey_delegate_action_transfer(firmware, backend, navigator: Navigator, test_name):
"""
DelegateAction {
sender_id: AccountId(
"bob.near",
),
receiver_id: AccountId(
"alice.near",
),
actions: [
NonDelegateAction(
Transfer(
TransferAction {
deposit: 150000000000000000000000,
},
),
),
],
nonce: 127127122121,
max_block_height: 100500,
public_key: ed25519:2pffV8fXgXUyuKdTS8Nqnvbkua16wEtTv8tdWZCpVtat,
}
"""
backend.raise_policy = RaisePolicy.RAISE_NOTHING
client = Nearbackend(backend)
chunks = [
AsyncAPDU(
data=bytes.fromhex(
"80088057748000002c8000018d80000000800000008000000108000000626f622e6e6561720a000000616c6963652e6e65617201000000030000c071f0d12b84c31f000000000000c9f05d991d0000009488010000000000001b11b3b31673033936ad07bddc01f9da27d974811e480fb197c799e23480a489"
),
navigable_conditions=NavigableConditions(
value=["Proceed to subactions", "To NEP366 suffix", "Sign", "Error!"],
),
expected_response=RAPDU(
0xB00D,
bytes(),
),
)
]
generic_test_sign(client, chunks, navigator, test_name)
Loading