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

Revert "Remove ragger tests" #11

Merged
merged 7 commits into from
Jan 6, 2025
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 8 additions & 1 deletion .github/workflows/build_and_functional_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ jobs:
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_build.yml@v1
with:
upload_app_binaries_artifact: "compiled_app_binaries"
flags: "RELEASE_BUILD=0"
flags: "RELEASE_BUILD=1"

ragger_tests:
name: Run ragger tests using the reusable workflow
needs: build_application
uses: LedgerHQ/ledger-app-workflows/.github/workflows/reusable_ragger_tests.yml@v1
with:
download_app_binaries_artifact: "compiled_app_binaries"

zemu_tests:
name: Run zemu tests
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ GIT_DESCRIBE=$(shell git describe --tags --abbrev=8 --always --long --dirty 2>/d
VERSION_TAG=$(shell echo $(GIT_DESCRIBE) | sed 's/^v//g')
APPVERSION_M=1
APPVERSION_N=3
APPVERSION_P=0
APPVERSION_P=1
APPVERSION=$(APPVERSION_M).$(APPVERSION_N).$(APPVERSION_P)
APPNAME = "Mina"

Expand Down
56 changes: 56 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from ragger.conftest import configuration
from ragger.navigator import NavInsID
import pytest

###########################
### CONFIGURATION START ###
###########################

# You can configure optional parameters by overriding the value of ragger.configuration.OPTIONAL_CONFIGURATION
# Please refer to ragger/conftest/configuration.py for their descriptions and accepted values
configuration.OPTIONAL.BACKEND_SCOPE = "class"

configuration.OPTIONAL.CUSTOM_SEED = "course grief vintage slim tell hospital car maze model style elegant kitchen state purpose matrix gas grid enable frown road goddess glove canyon key"

#########################
### CONFIGURATION END ###
#########################

# Pull all features from the base ragger conftest using the overridden configuration
pytest_plugins = ("ragger.conftest.base_conftest", )

def pytest_addoption(parser):
parser.addoption(
"--all", action="store_true", default=False, help="Run all tests including crypto tests (not for release builds)"
)

def pytest_configure(config):
config.addinivalue_line("markers", "all: only run for not release builds")

def pytest_collection_modifyitems(config, items):
if config.getoption("--all"):
return
skip = pytest.mark.skip(reason="Use --all flag to run")
for item in items:
if "all" in item.keywords:
item.add_marker(skip)

class PreauthNavigator:
def __init__(self, navigator, firmware, default_screenshot_path, test_name):
self.navigator = navigator
self.firmware = firmware
self.default_screenshot_path = default_screenshot_path
self.test_name = test_name

def navigate(self):
if self.firmware.is_nano:
self.navigator.navigate_until_text_and_compare(navigate_instruction=NavInsID.RIGHT_CLICK,
validation_instructions=[NavInsID.BOTH_CLICK],
text="Generate",
path=self.default_screenshot_path,
test_case_name=self.test_name + "_preauth",
screen_change_after_last_instruction=False)

@pytest.fixture(scope="function")
def preauth_navigator(navigator, firmware, default_screenshot_path, test_name) -> PreauthNavigator:
return PreauthNavigator(navigator, firmware, default_screenshot_path, test_name)
79 changes: 79 additions & 0 deletions tests/mina_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python3

from contextlib import contextmanager

from ragger.backend.interface import BackendInterface, RAPDU
import sys
import os

sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../utils/")
import mina_ledger_wallet as mina

class MinaClient:
backend: BackendInterface

def __init__(self, backend):
self._client = backend

@contextmanager
def get_address_async(self, account):
# Create APDU message.
# CLA 0xe0 CLA
# INS 0x02 INS_GET_ADDR
# P1 0x00 UNUSED
# P2 0x00 UNUSED
account = '{:08x}'.format(account)
apduMessage = 'e0020000' + \
'{:02x}'.format(int(len(account)/2)) + account
apdu = bytearray.fromhex(apduMessage)

with self._client.exchange_async_raw(apdu):
yield

@contextmanager
def sign_tx_async(self, tx_type, sender_account, sender_address, receiver, amount, fee, nonce,
valid_until, memo, network_id):
sender_bip44_account = '{:08x}'.format(int(sender_account))
sender_address = sender_address.encode().hex()
receiver = receiver.encode().hex()
amount = '{:016x}'.format(int(amount))
fee = '{:016x}'.format(int(fee))
nonce = '{:08x}'.format(nonce)
valid_until = '{:08x}'.format(valid_until)
memo = memo.ljust(mina.MAX_MEMO_LEN, '\x00')[
:mina.MAX_MEMO_LEN].encode().hex()
tag = '{:02x}'.format(tx_type)
network_id = '{:02x}'.format(network_id)

total_len = len(sender_bip44_account) \
+ len(sender_address) \
+ len(receiver) \
+ len(amount) \
+ len(fee) \
+ len(nonce) \
+ len(valid_until) \
+ len(memo) \
+ len(tag) \
+ len(network_id)

# Create APDU message.
# CLA 0xe0 CLA
# INS 0x03 INS_SIGN_TX
# P1 0x00 UNUSED
# P2 0x00 UNUSED
apduMessage = 'e0030000' + '{:02x}'.format(int(total_len/2)) \
+ sender_bip44_account \
+ sender_address \
+ receiver \
+ amount \
+ fee \
+ nonce \
+ valid_until \
+ memo \
+ tag \
+ network_id

apdu = bytearray.fromhex(apduMessage)

with self._client.exchange_async_raw(apdu):
yield
Loading
Loading