Skip to content

Commit

Permalink
Tests: workaround to fix speculos OCR for NanoX/SP
Browse files Browse the repository at this point in the history
  • Loading branch information
sgliner-ledger committed Jun 8, 2022
1 parent ae75c70 commit 50487ed
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions tests/automations/sign_message_accept.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
]
},
{
"regexp": "Sign",
"regexp": "[S]?ign",
"conditions": [
[ "seen", false ]
],
Expand All @@ -20,7 +20,7 @@
]
},
{
"regexp": "Sign",
"regexp": "[S]?ign",
"conditions": [
[ "seen", true ]
],
Expand Down
2 changes: 1 addition & 1 deletion tests/automations/sign_message_reject.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": 1,
"rules": [
{
"regexp": "Sign|Path|Message hash|Approve",
"regexp": "[S]?ign|Path|Message hash|Approve",
"actions": [
["button", 2, true],
["button", 2, false]
Expand Down
2 changes: 1 addition & 1 deletion tests/automations/sign_with_wallet_accept.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": 1,
"rules": [
{
"regexp": "Spend from|Review|Amount|Address|Confirm|Fees",
"regexp": "[S]?pend from|Review|Amount|Address|Confirm|Fees",
"actions": [
["button", 2, true],
["button", 2, false]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"version": 1,
"rules": [
{
"regexp": "Spend from|There are|Reject if you're|Review|Amount|Address|Confirm|Fees",
"regexp": "[S]?pend from|There are|Reject if you're|Review|Amount|Address|Confirm|Fees",
"actions": [
["button", 2, true],
["button", 2, false]
Expand Down
14 changes: 10 additions & 4 deletions tests/test_sign_psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@


CURRENCY_TICKER = "TEST"
# For nano X/S+ OCR used in speculos misreads 'S'. See caveats.txt
CURRENCY_TICKER_ALT = "TET"


def format_amount(ticker: str, amount: int) -> str:
Expand Down Expand Up @@ -427,13 +429,15 @@ def test_sign_psbt_singlesig_wpkh_4to3(client: Client, comm: SpeculosClient, is_

parsed_events = parse_signing_events(all_events)

assert(parsed_events["fees"] == format_amount(CURRENCY_TICKER, fees_amount))
assert((parsed_events["fees"] == format_amount(CURRENCY_TICKER, fees_amount)) or
(parsed_events["fees"] == format_amount(CURRENCY_TICKER_ALT, fees_amount)))

shown_out_idx = 0
for out_idx in range(n_outs):
if out_idx != change_index:
out_amt = psbt.tx.vout[out_idx].nValue
assert parsed_events["amounts"][shown_out_idx] == format_amount(CURRENCY_TICKER, out_amt)
assert((parsed_events["amounts"][shown_out_idx] == format_amount(CURRENCY_TICKER, out_amt)) or
(parsed_events["amounts"][shown_out_idx] == format_amount(CURRENCY_TICKER_ALT, out_amt)))

out_addr = Script(psbt.tx.vout[out_idx].scriptPubKey).address(network=NETWORKS["test"])
assert parsed_events["addresses"][shown_out_idx] == out_addr
Expand Down Expand Up @@ -478,10 +482,12 @@ def test_sign_psbt_singlesig_large_amount(client: Client, comm: SpeculosClient,

parsed_events = parse_signing_events(all_events)

assert(parsed_events["fees"] == format_amount(CURRENCY_TICKER, fees_amount))
assert((parsed_events["fees"] == format_amount(CURRENCY_TICKER, fees_amount)) or
(parsed_events["fees"] == format_amount(CURRENCY_TICKER_ALT, fees_amount)))

out_amt = psbt.tx.vout[0].nValue
assert parsed_events["amounts"][0] == format_amount(CURRENCY_TICKER, out_amt)
assert((parsed_events["amounts"][0] == format_amount(CURRENCY_TICKER, out_amt)) or
(parsed_events["amounts"][0] == format_amount(CURRENCY_TICKER_ALT, out_amt)))


@has_automation("automations/sign_with_default_wallet_accept.json")
Expand Down

0 comments on commit 50487ed

Please sign in to comment.