Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/LDG-532--nano-app-implement-registerdata-method #49

Merged
merged 3 commits into from
Dec 12, 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
49 changes: 49 additions & 0 deletions tests/application_client/boilerplate_command_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class P1(IntEnum):
P1_INITIAL_TRANSFER_TO_PUBLIC = 0x00
P1_REMAINING_AMOUNT_TRANSFER_TO_PUBLIC = 0x01
P1_PROOF_TRANSFER_TO_PUBLIC = 0x02
# Parameter 1 for register data
P1_REGISTER_DATA_INITIAL = 0x00
P1_REGISTER_DATA_PAYLOAD = 0x01
# Basic P1 for all instructions
P1_NONE = 0x00

Expand Down Expand Up @@ -125,6 +128,7 @@ class Errors(IntEnum):

# pylint: disable=too-many-public-methods
# pylint: disable=too-many-locals
# pylint: disable=too-many-lines
class BoilerplateCommandSender:
def __init__(self, backend: BackendInterface) -> None:
self.backend = backend
Expand Down Expand Up @@ -977,5 +981,50 @@ def update_contract(
) as response:
yield response

@contextmanager
def register_data_part_1(
self,
path: str,
header_and_type: bytes,
data_length: int,
) -> Generator[None, None, None]:
temp_data = pack_derivation_path(path)
temp_data += header_and_type
temp_data += data_length.to_bytes(2, byteorder="big")
with self.backend.exchange_async(
cla=CLA,
ins=InsType.REGISTER_DATA,
p1=P1.P1_REGISTER_DATA_INITIAL,
p2=P2.P2_NONE,
data=temp_data,
) as response:
yield response

@contextmanager
def register_data_part_2(
self,
data: bytes,
) -> Generator[None, None, None]:
data_chunks = split_message(data, MAX_APDU_LEN)
last_chunk = data_chunks.pop()
for chunk in data_chunks:
temp_response = self.backend.exchange(
cla=CLA,
ins=InsType.REGISTER_DATA,
p1=P1.P1_REGISTER_DATA_PAYLOAD,
p2=P2.P2_NONE,
data=chunk,
)
if temp_response.status != 0x9000:
raise ExceptionRAPDU(temp_response.status)
with self.backend.exchange_async(
cla=CLA,
ins=InsType.REGISTER_DATA,
p1=P1.P1_REGISTER_DATA_PAYLOAD,
p2=P2.P2_NONE,
data=last_chunk,
) as response:
yield response

def get_async_response(self) -> Optional[RAPDU]:
return self.backend.last_async_response
Binary file added tests/snapshots/nanosp/test_register_data/00000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanosp/test_register_data/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanosp/test_register_data/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanosp/test_register_data/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanosp/test_register_data/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanosp/test_register_data/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanosp/test_register_data/00006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanosp/test_register_data/00007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanox/test_register_data/00000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanox/test_register_data/00001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanox/test_register_data/00002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanox/test_register_data/00003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanox/test_register_data/00004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanox/test_register_data/00005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanox/test_register_data/00006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/snapshots/nanox/test_register_data/00007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions tests/test_register_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import pytest

from application_client.boilerplate_command_sender import (
BoilerplateCommandSender,
Errors,
)
from application_client.boilerplate_response_unpacker import (
unpack_get_public_key_response,
)
from ragger.bip import calculate_public_key_and_chaincode, CurveChoice
from ragger.error import ExceptionRAPDU
from ragger.navigator import NavInsID, NavIns
from ragger.firmware import Firmware
from utils import navigate_until_text_and_compare, instructions_builder


@pytest.mark.active_test_scope
def test_register_data(
backend, firmware, navigator, test_name, default_screenshot_path
):
client = BoilerplateCommandSender(backend)
path = "m/1105/0/0/0/0/2/0/0"
header_and_type = bytes.fromhex(
"20a845815bd43a1999e90fbf971537a70392eb38f89e6bd32b3dd70e1a9551d7000000000000000a0000000000000064000000290000000063de5da715"
)
data = bytes.fromhex("6474657374")

# Send the first part of the data
with client.register_data_part_1(
path=path,
header_and_type=header_and_type,
data_length=len(data),
):
navigator.navigate_and_compare(
default_screenshot_path,
test_name,
instructions_builder(3, backend),
10,
True,
False,
)
response = client.get_async_response()
print(response.data.hex())
assert response.status == 0x9000
screenshots_so_far = 4
# Send the second part of the data
with client.register_data_part_2(data):
navigator.navigate_and_compare(
default_screenshot_path,
test_name,
instructions_builder(1, backend) + [NavInsID.BOTH_CLICK],
10,
False,
True,
screenshots_so_far,
)
response = client.get_async_response()
print(response.data.hex())
assert response.status == 0x9000
assert response.data == bytes.fromhex(
"a410e856c8942767e5af88c3992013a2e788584d9c69141271400222978b57f5b86c8d3a0127b9d521a00c8e8b68ca7c4937da0f1ace27860765d9b0de4ffe08"
)
Loading