Skip to content

Commit

Permalink
Update ragger tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nroggeman-ledger committed Sep 2, 2024
1 parent c3823f1 commit e331f31
Show file tree
Hide file tree
Showing 59 changed files with 75 additions and 385 deletions.
41 changes: 0 additions & 41 deletions .github/workflows/cflite_cron.yml

This file was deleted.

43 changes: 0 additions & 43 deletions .github/workflows/cflite_pr.yml

This file was deleted.

8 changes: 4 additions & 4 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* Enumeration with expected INS of APDU commands.
*/
typedef enum {
GET_VERSION = 0x03, /// version of the application
GET_APP_NAME = 0x04, /// name of the application
TEST_REVIEW1 = 0x05, ///
TEST_REVIEW2 = 0x06 ///
GET_VERSION = 0x03, /// version of the application
GET_APP_NAME = 0x04, /// name of the application
TEST_REVIEW1 = 0x05, ///
TEST_REVIEW2 = 0x06 ///
} command_e;

4 changes: 2 additions & 2 deletions src/ui/menu.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#pragma once

#ifdef SCREEN_SIZE_NANO
#define LARGE_ICON C_app_nbgl_tests_16px
#define LARGE_ICON C_app_nbgl_tests_16px
#define LARGE_WARNING_ICON C_icon_warning
#else
#define LARGE_ICON C_app_nbgl_tests_64px
#define LARGE_ICON C_app_nbgl_tests_64px
#define LARGE_WARNING_ICON C_Warning_64px
#endif

Expand Down
48 changes: 10 additions & 38 deletions tests/application_client/boilerplate_command_sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from contextlib import contextmanager

from ragger.backend.interface import BackendInterface, RAPDU
from ragger.bip import pack_derivation_path


MAX_APDU_LEN: int = 255

Expand All @@ -27,8 +25,8 @@ class P2(IntEnum):
class InsType(IntEnum):
GET_VERSION = 0x03
GET_APP_NAME = 0x04
GET_PUBLIC_KEY = 0x05
SIGN_TX = 0x06
TEST_REVIEW1 = 0x05
TEST_REVIEW2 = 0x06

class Errors(IntEnum):
SW_DENY = 0x6985
Expand Down Expand Up @@ -79,48 +77,22 @@ def get_app_name(self) -> RAPDU:
p2=P2.P2_LAST,
data=b"")


def get_public_key(self, path: str) -> RAPDU:
return self.backend.exchange(cla=CLA,
ins=InsType.GET_PUBLIC_KEY,
p1=P1.P1_START,
p2=P2.P2_LAST,
data=pack_derivation_path(path))


@contextmanager
def get_public_key_with_confirmation(self, path: str) -> Generator[None, None, None]:
def test_review1(self,) -> Generator[None, None, None]:
with self.backend.exchange_async(cla=CLA,
ins=InsType.GET_PUBLIC_KEY,
p1=P1.P1_CONFIRM,
ins=InsType.TEST_REVIEW1,
p1=P1.P1_START,
p2=P2.P2_LAST,
data=pack_derivation_path(path)) as response:
data=b"") as response:
yield response


@contextmanager
def sign_tx(self, path: str, transaction: bytes) -> Generator[None, None, None]:
self.backend.exchange(cla=CLA,
ins=InsType.SIGN_TX,
p1=P1.P1_START,
p2=P2.P2_MORE,
data=pack_derivation_path(path))
messages = split_message(transaction, MAX_APDU_LEN)
idx: int = P1.P1_START + 1

for msg in messages[:-1]:
self.backend.exchange(cla=CLA,
ins=InsType.SIGN_TX,
p1=idx,
p2=P2.P2_MORE,
data=msg)
idx += 1

def test_review2(self,) -> Generator[None, None, None]:
with self.backend.exchange_async(cla=CLA,
ins=InsType.SIGN_TX,
p1=idx,
ins=InsType.TEST_REVIEW2,
p1=P1.P1_START,
p2=P2.P2_LAST,
data=messages[-1]) as response:
data=b"") as response:
yield response

def get_async_response(self) -> Optional[RAPDU]:
Expand Down
27 changes: 0 additions & 27 deletions tests/application_client/boilerplate_response_unpacker.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,30 +41,3 @@ def unpack_get_app_and_version_response(response: bytes) -> Tuple[str, str]:
assert len(response) == 0

return app_name_raw.decode("ascii"), version_raw.decode("ascii")

# Unpack from response:
# response = pub_key_len (1)
# pub_key (var)
# chain_code_len (1)
# chain_code (var)
def unpack_get_public_key_response(response: bytes) -> Tuple[int, bytes, int, bytes]:
response, pub_key_len, pub_key = pop_size_prefixed_buf_from_buf(response)
response, chain_code_len, chain_code = pop_size_prefixed_buf_from_buf(response)

assert pub_key_len == 65
assert chain_code_len == 32
assert len(response) == 0

return pub_key_len, pub_key, chain_code_len, chain_code

# Unpack from response:
# response = der_sig_len (1)
# der_sig (var)
# v (1)
def unpack_sign_tx_response(response: bytes) -> Tuple[int, bytes, int]:
response, der_sig_len, der_sig = pop_size_prefixed_buf_from_buf(response)
response, v = pop_sized_buf_from_buffer(response, 1)

assert len(response) == 0

return der_sig_len, der_sig, int.from_bytes(v, byteorder='big')
52 changes: 0 additions & 52 deletions tests/application_client/boilerplate_transaction.py

This file was deleted.

Binary file modified tests/snapshots/flex/test_app_mainmenu/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 modified tests/snapshots/flex/test_app_mainmenu/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 modified tests/snapshots/flex/test_app_mainmenu/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 modified tests/snapshots/flex/test_app_mainmenu/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 modified tests/snapshots/flex/test_app_mainmenu/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 modified tests/snapshots/flex/test_app_mainmenu/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 modified tests/snapshots/flex/test_app_mainmenu/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 not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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.
Binary file removed tests/snapshots/flex/test_sign_tx_long_tx/00000.png
Diff not rendered.
Binary file removed tests/snapshots/flex/test_sign_tx_long_tx/00001.png
Diff not rendered.
Diff not rendered.
Binary file removed tests/snapshots/flex/test_sign_tx_long_tx/00004.png
Diff not rendered.
Binary file removed tests/snapshots/flex/test_sign_tx_refused/00000.png
Diff not rendered.
Binary file removed tests/snapshots/flex/test_sign_tx_refused/00001.png
Diff not rendered.
Diff not rendered.
Binary file removed tests/snapshots/flex/test_sign_tx_refused/00005.png
Diff not rendered.
Binary file removed tests/snapshots/flex/test_sign_tx_short_tx/00000.png
Diff not rendered.
Binary file removed tests/snapshots/flex/test_sign_tx_short_tx/00001.png
Diff not rendered.
Diff not rendered.
Binary file removed tests/snapshots/flex/test_sign_tx_short_tx/00003.png
Diff not rendered.
Binary file removed tests/snapshots/flex/test_sign_tx_short_tx/00004.png
Diff not rendered.
11 changes: 0 additions & 11 deletions tests/test_error_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,3 @@ def test_wrong_data_length(backend):
with pytest.raises(ExceptionRAPDU) as e:
backend.exchange_raw(bytes.fromhex("E003000005"))
assert e.value.status == Errors.SW_WRONG_DATA_LENGTH


# Ensure there is no state confusion when trying wrong APDU sequences
def test_invalid_state(backend):
with pytest.raises(ExceptionRAPDU) as e:
backend.exchange(cla=CLA,
ins=InsType.SIGN_TX,
p1=P1.P1_START + 1, # Try to continue a flow instead of start a new one
p2=P2.P2_MORE,
data=b"abcde") # data is not parsed in this case
assert e.value.status == Errors.SW_BAD_STATE
48 changes: 0 additions & 48 deletions tests/test_pubkey_cmd.py

This file was deleted.

29 changes: 29 additions & 0 deletions tests/test_review1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import pytest

from application_client.boilerplate_command_sender import BoilerplateCommandSender, Errors
from ragger.error import ExceptionRAPDU


# In this test we check that the TEST_REVIEW1 replies OK if the user accepts
def test_review1_accepted(backend, scenario_navigator):
client = BoilerplateCommandSender(backend)

with client.test_review1():
scenario_navigator.review_approve()

status = client.get_async_response().status

assert status == 0x9000


# In this test we check that the TEST_REVIEW1 replies an error if the user refuses
def test_review1_refused(backend, scenario_navigator):
client = BoilerplateCommandSender(backend)

with pytest.raises(ExceptionRAPDU) as e:
with client.test_review1():
scenario_navigator.review_reject()

# Assert that we have received a refusal
assert e.value.status == Errors.SW_DENY
assert len(e.value.data) == 0
28 changes: 28 additions & 0 deletions tests/test_review2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pytest

from application_client.boilerplate_command_sender import BoilerplateCommandSender, Errors
from ragger.error import ExceptionRAPDU


# In this test we check that the TEST_REVIEW2 replies OK if the user accepts
def test_review2_accepted(backend, scenario_navigator):
client = BoilerplateCommandSender(backend)
with client.test_review2():
scenario_navigator.address_review_approve()

status = client.get_async_response().status

assert status == 0x9000


# In this test we check that the TEST_REVIEW2 replies an error if the user refuses
def test_review2_refused(backend, scenario_navigator):
client = BoilerplateCommandSender(backend)

with pytest.raises(ExceptionRAPDU) as e:
with client.test_review2():
scenario_navigator.address_review_reject()

# Assert that we have received a refusal
assert e.value.status == Errors.SW_DENY
assert len(e.value.data) == 0
Loading

0 comments on commit e331f31

Please sign in to comment.