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

Update usage of 'scenario_navigator' default parameters #53

Merged
merged 1 commit into from
Jun 10, 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
26 changes: 13 additions & 13 deletions tests/functional_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
from ragger.error import ExceptionRAPDU
from .xrp import XRPClient, Errors
from .utils import DEFAULT_PATH, DEFAULT_BIP32_PATH
from .utils import ROOT_SCREENSHOT_PATH, verify_ecdsa_secp256k1, verify_version
from .utils import verify_ecdsa_secp256k1, verify_version


def test_app_configuration(backend: BackendInterface, firmware: Firmware, navigator: Navigator):
def test_app_configuration(backend: BackendInterface,
firmware: Firmware,
navigator: Navigator,
default_screenshot_path: Path):
xrp = XRPClient(backend, firmware, navigator)
version = xrp.get_configuration()
verify_version(version)
verify_version(default_screenshot_path, version)


def test_sign_too_large(backend: BackendInterface, firmware: Firmware, navigator: Navigator):
Expand Down Expand Up @@ -70,11 +73,10 @@ def test_get_public_key_no_confirm(backend: BackendInterface,
def test_get_public_key_confirm(backend: BackendInterface,
firmware: Firmware,
navigator: Navigator,
scenario_navigator: NavigateWithScenario,
test_name: str):
scenario_navigator: NavigateWithScenario):
xrp = XRPClient(backend, firmware, navigator)
with xrp.get_pubkey_confirm():
scenario_navigator.address_review_approve(ROOT_SCREENSHOT_PATH, test_name)
scenario_navigator.address_review_approve()

# Check the status (Asynchronous)
reply = xrp.get_async_response()
Expand All @@ -84,13 +86,12 @@ def test_get_public_key_confirm(backend: BackendInterface,
def test_get_public_key_reject(backend: BackendInterface,
firmware: Firmware,
navigator: Navigator,
scenario_navigator: NavigateWithScenario,
test_name: str):
scenario_navigator: NavigateWithScenario):
xrp = XRPClient(backend, firmware, navigator)

with pytest.raises(ExceptionRAPDU) as err:
with xrp.get_pubkey_confirm():
scenario_navigator.address_review_reject(ROOT_SCREENSHOT_PATH, test_name)
scenario_navigator.address_review_reject()

# Assert we have received a refusal
assert err.value.status == Errors.SW_WRONG_ADDRESS
Expand All @@ -100,8 +101,7 @@ def test_get_public_key_reject(backend: BackendInterface,
def test_sign_reject(backend: BackendInterface,
firmware: Firmware,
navigator: Navigator,
scenario_navigator: NavigateWithScenario,
test_name: str):
scenario_navigator: NavigateWithScenario):
xrp = XRPClient(backend, firmware, navigator)

# pragma pylint: disable=line-too-long
Expand All @@ -115,7 +115,7 @@ def test_sign_reject(backend: BackendInterface,
# Send the APDU (Asynchronous)
with pytest.raises(ExceptionRAPDU) as err:
with xrp.sign(DEFAULT_BIP32_PATH + message):
scenario_navigator.review_reject(ROOT_SCREENSHOT_PATH, test_name)
scenario_navigator.review_reject()

# Assert we have received a refusal
assert err.value.status == Errors.SW_WRONG_ADDRESS
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_sign_valid_tx(backend: BackendInterface,
else:
text = "^Hold to sign$"
with xrp.sign(DEFAULT_BIP32_PATH + tx):
scenario_navigator.review_approve(ROOT_SCREENSHOT_PATH, snapdir, text)
scenario_navigator.review_approve(test_name=snapdir, custom_screen_text=text)

reply = xrp.get_async_response()
assert reply and reply.status == Errors.SW_SUCCESS
Expand Down
6 changes: 2 additions & 4 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from ragger.bip import calculate_public_key_and_chaincode, CurveChoice


ROOT_SCREENSHOT_PATH = Path(__file__).parent.resolve()
DEFAULT_PATH = "44'/144'/0'/0'/0"
DEFAULT_BIP32_PATH = Bip32Path.build(DEFAULT_PATH)
TX_PREFIX_SINGLE = [0x53, 0x54, 0x58, 0x00]
Expand Down Expand Up @@ -55,12 +54,11 @@ def unpack_get_public_key_response(reply: bytes) -> Tuple[int, str, int, str]:
return key_len, key_data.hex(), len(chain_data), chain_data.hex()


def verify_version(version: str) -> None:
def verify_version(root_path: Path, version: str) -> None:
""" Verify the app version, based on defines in Makefile """

print(f"version: {version}")
parent = Path(ROOT_SCREENSHOT_PATH).parent.resolve()
makefile = f"{parent}/Makefile"
makefile = f"{root_path.parent.resolve()}/Makefile"
print(f"{makefile}")
with open(makefile, "r", encoding="utf-8") as f_p:
lines = f_p.readlines()
Expand Down
Loading