Skip to content

Commit

Permalink
Merge pull request #198 from LedgerHQ/fbe/add_tests_for_rejection
Browse files Browse the repository at this point in the history
Add tests for rejection
  • Loading branch information
fbeutin-ledger authored Jun 24, 2024
2 parents fa14364 + c0cd678 commit f993760
Show file tree
Hide file tree
Showing 101 changed files with 91 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/ui/validate_transaction_bagl.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static void on_accept(__attribute__((unused)) const bagl_element_t *e) {
static void on_reject(__attribute__((unused)) const bagl_element_t *e) {
PRINTF("User refused transaction\n");
reply_error(USER_REFUSED);
G_swap_ctx.state = INITIAL_STATE;
ui_idle();
}

Expand Down
1 change: 1 addition & 0 deletions src/ui/validate_transaction_nbgl.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ static void reject_tx(void) {
PRINTF("User refused transaction\n");
reply_error(USER_REFUSED);
nbgl_useCaseStatus("Transaction\nrejected", false, ui_idle);
G_swap_ctx.state = INITIAL_STATE;
}

// If the user asks for message rejection, ask for confirmation
Expand Down
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
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.
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.
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.
88 changes: 88 additions & 0 deletions test/python/test_rejection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
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):
# Add a "_fund" / "_sell" / "_swap" suffix to the snapshot directory
suffix = "_" + str(subcommand).split('.')[1].split('_')[0].lower()
exchange_navigation_helper.set_test_name_suffix(suffix)

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

# We should have reset the internal context and be ready for a new TX proposal
ex.init_transaction()

0 comments on commit f993760

Please sign in to comment.