Skip to content

Commit

Permalink
Add tests for TX rejection
Browse files Browse the repository at this point in the history
  • Loading branch information
fbeutin-ledger committed Jun 24, 2024
1 parent 8c5a519 commit ee8a29d
Show file tree
Hide file tree
Showing 37 changed files with 82 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/python/apps/exchange_navigation_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def _navigate_and_compare(self, accept: bool):
# Don't try to assert the "Processing" spinner on stax
screen_change_after_last_instruction = False
else:
validation_instructions = [NavInsID.USE_CASE_REVIEW_REJECT, NavInsID.USE_CASE_CHOICE_CONFIRM]
validation_instructions = [NavInsID.USE_CASE_REVIEW_REJECT, NavInsID.USE_CASE_CHOICE_CONFIRM, NavInsID.USE_CASE_STATUS_DISMISS]

self._navigator.navigate_until_text_and_compare(navigate_instruction=navigate_instruction,
validation_instructions=validation_instructions,
Expand Down
Binary file added test/python/snapshots/nanos/test_rejection/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 test/python/snapshots/nanos/test_rejection/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 test/python/snapshots/nanos/test_rejection/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 test/python/snapshots/nanos/test_rejection/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 test/python/snapshots/nanos/test_rejection/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 test/python/snapshots/nanos/test_rejection/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 test/python/snapshots/nanos/test_rejection/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 test/python/snapshots/nanos/test_rejection/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 test/python/snapshots/nanos/test_rejection/00008.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 test/python/snapshots/nanos/test_rejection/00009.png
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.
Binary file added test/python/snapshots/nanox/test_rejection/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 test/python/snapshots/nanox/test_rejection/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 test/python/snapshots/nanox/test_rejection/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 test/python/snapshots/nanox/test_rejection/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 test/python/snapshots/nanox/test_rejection/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 test/python/snapshots/nanox/test_rejection/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 test/python/snapshots/nanox/test_rejection/00006.png
Binary file added test/python/snapshots/nanox/test_rejection/00007.png
Binary file added test/python/snapshots/nanox/test_rejection/00008.png
81 changes: 81 additions & 0 deletions test/python/test_rejection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import pytest

from ragger.utils import RAPDU, prefix_with_len, create_currency_config
from ragger.error import ExceptionRAPDU

from .apps.exchange import ExchangeClient, Rate, SubCommand, Errors, Command, P2_EXTEND, P2_MORE, EXCHANGE_CLASS
from .apps.exchange_transaction_builder import get_partner_curve, LEGACY_SUBCOMMANDS, ALL_SUBCOMMANDS, NEW_SUBCOMMANDS, get_credentials, craft_and_sign_tx
from .apps.signing_authority import SigningAuthority, LEDGER_SIGNER
from .apps import cal as cal
from .apps.ethereum import ETC_PACKED_DERIVATION_PATH

CURRENCY_FROM = cal.ETH_CURRENCY_CONFIGURATION
CURRENCY_TO = cal.BTC_CURRENCY_CONFIGURATION

# Some valid infos for TX. Content is irrelevant for the test

SWAP_TX_INFOS = {
"payin_address": b"0xd692Cb1346262F584D17B4B470954501f6715a82",
"payin_extra_id": b"",
"refund_address": b"0xDad77910DbDFdE764fC21FCD4E74D71bBACA6D8D",
"refund_extra_id": b"",
"payout_address": b"bc1qqtl9jlrwcr3fsfcjj2du7pu6fcgaxl5dsw2vyg",
"payout_extra_id": b"",
"currency_from": CURRENCY_FROM.ticker,
"currency_to": CURRENCY_TO.ticker,
"amount_to_provider": bytes.fromhex("013fc3a717fb5000"),
"amount_to_wallet": b"\x0b\xeb\xc2\x00",
}
FUND_TX_INFOS = {
"user_id": "John Wick",
"account_name": "Remember Daisy",
"in_currency": CURRENCY_FROM.ticker,
"in_amount": b"\032\200\250]$T\000",
"in_address": "0x252fb4acbe0de4f0bd2409a5ed59a71e4ef1d2bc"
}
SELL_TX_INFOS = {
"trader_email": "[email protected]",
"out_currency": "USD",
"out_amount": {"coefficient": b"\x01", "exponent": 3},
"in_currency": CURRENCY_FROM.ticker,
"in_amount": b"\032\200\250]$T\000",
"in_address": "0x252fb4acbe0de4f0bd2409a5ed59a71e4ef1d2bc"
}
TX_INFOS = {
SubCommand.SWAP_NG: SWAP_TX_INFOS,
SubCommand.FUND_NG: FUND_TX_INFOS,
SubCommand.SELL_NG: SELL_TX_INFOS,
}
FEES = 100

class TestRejection:
@pytest.mark.parametrize("subcommand", NEW_SUBCOMMANDS)
def test_rejection(self, backend, exchange_navigation_helper, subcommand):
ex = ExchangeClient(backend, Rate.FIXED, subcommand)
partner = SigningAuthority(curve=get_partner_curve(subcommand), name="Name")
transaction_id = ex.init_transaction().data
credentials = get_credentials(subcommand, partner)
ex.set_partner_key(credentials)
ex.check_partner_key(LEDGER_SIGNER.sign(credentials))
tx, tx_signature = craft_and_sign_tx(subcommand, TX_INFOS[subcommand], transaction_id, FEES, partner)
ex.process_transaction(tx)
ex.check_transaction_signature(tx_signature)

from_configuration = CURRENCY_FROM.get_conf_for_ticker()

if subcommand == SubCommand.SWAP_NG:
to_configuration = CURRENCY_TO.get_conf_for_ticker()
ex.check_payout_address(to_configuration)

# Request the final address check and UI approval request on the device
ex.check_refund_address_no_display(from_configuration)
with pytest.raises(ExceptionRAPDU) as e:
with ex.prompt_ui_display():
exchange_navigation_helper.simple_reject()
assert e.value.status == Errors.USER_REFUSED
else:
ex.check_asset_in_no_display(from_configuration)
with pytest.raises(ExceptionRAPDU) as e:
with ex.prompt_ui_display():
exchange_navigation_helper.simple_reject()
assert e.value.status == Errors.USER_REFUSED

0 comments on commit ee8a29d

Please sign in to comment.