Skip to content

Commit

Permalink
Remove other OCR workarounds that are no longer necessary
Browse files Browse the repository at this point in the history
Also reverts 50487ed.
  • Loading branch information
bigspider committed Oct 6, 2023
1 parent 896f0dc commit 22b6fed
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 41 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 @@ -28,7 +28,7 @@
]
},
{
"regexp": "[S]?ign",
"regexp": "Sign",
"conditions": [
[ "seen", false ]
],
Expand All @@ -39,7 +39,7 @@
]
},
{
"regexp": "[S]?ign",
"regexp": "Sign",
"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 @@ -9,7 +9,7 @@
]
},
{
"regexp": "[S]?ign|Path|Message hash|Approve",
"regexp": "Sign|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": "[S]?pend from|Wallet name|Review|Amount|Address|Confirm|Fees",
"regexp": "Spend from|Wallet name|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 @@ -8,7 +8,7 @@
]
},
{
"regexp": "[S]?pend from|Wallet name|There are|Reject if you['-]re|Review|Amount|Address|Confirm|Fees",
"regexp": "Spend from|Wallet name|There are|Reject if you['-]re|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 @@ -35,7 +35,7 @@
]
},
{
"regexp": "Unverified|Update|or third party|[S]?pend from|Wallet name|Review|Amount|Address|Confirm|Fees",
"regexp": "Unverified|Update|or third party|Spend from|Wallet name|Review|Amount|Address|Confirm|Fees",
"actions": [
["button", 2, true],
["button", 2, false]
Expand Down
11 changes: 0 additions & 11 deletions tests/caveats.txt

This file was deleted.

19 changes: 6 additions & 13 deletions tests/test_sign_psbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@


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 @@ -128,7 +126,7 @@ def parse_signing_events(events: List[dict]) -> dict:
if len(ret["addresses"]) == 0:
ret["addresses"].append("")

ret["addresses"][-1] += ev["text"].strip().replace("O", "0") # OCR misreads O for 0
ret["addresses"][-1] += ev["text"].strip()

elif next_step.startswith("Fees"):
ret["fees"] += ev["text"].strip()
Expand Down Expand Up @@ -648,18 +646,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)) or
(parsed_events["fees"] == format_amount(CURRENCY_TICKER_ALT, fees_amount)))
assert parsed_events["fees"] == format_amount(CURRENCY_TICKER, 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)) or
(parsed_events["amounts"][shown_out_idx] == format_amount(CURRENCY_TICKER_ALT, out_amt)))
assert parsed_events["amounts"][shown_out_idx] == format_amount(CURRENCY_TICKER, out_amt)

out_addr = Script(psbt.tx.vout[out_idx].scriptPubKey).address(
network=NETWORKS["test"]).replace('O', '0') # OCR misreads O for 0
out_addr = Script(psbt.tx.vout[out_idx].scriptPubKey).address(network=NETWORKS["test"])
assert parsed_events["addresses"][shown_out_idx] == out_addr

shown_out_idx += 1
Expand Down Expand Up @@ -706,12 +701,10 @@ 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)) or
(parsed_events["fees"] == format_amount(CURRENCY_TICKER_ALT, fees_amount)))
assert parsed_events["fees"] == format_amount(CURRENCY_TICKER, fees_amount)

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


@pytest.mark.timeout(0) # disable timeout
Expand Down
16 changes: 5 additions & 11 deletions tests/test_sign_psbt_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@


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 @@ -133,7 +131,7 @@ def parse_signing_events(events: List[dict]) -> dict:
if len(ret["addresses"]) == 0:
ret["addresses"].append("")

ret["addresses"][-1] += ev["text"].strip().replace("O", "0") # OCR misreads O for 0
ret["addresses"][-1] += ev["text"].strip()

elif next_step.startswith("Fees"):
ret["fees"] += ev["text"]
Expand Down Expand Up @@ -420,15 +418,13 @@ def test_sign_psbt_singlesig_wpkh_4to3_v1(client: Client, comm: SpeculosClient,

parsed_events = parse_signing_events(all_events)

assert ((parsed_events["fees"] == format_amount(CURRENCY_TICKER, fees_amount)) or
(parsed_events["fees"] == format_amount(CURRENCY_TICKER_ALT, fees_amount)))
assert parsed_events["fees"] == format_amount(CURRENCY_TICKER, 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)) or
(parsed_events["amounts"][shown_out_idx] == format_amount(CURRENCY_TICKER_ALT, out_amt)))
assert parsed_events["amounts"][shown_out_idx] == format_amount(CURRENCY_TICKER, 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 @@ -479,12 +475,10 @@ def test_sign_psbt_singlesig_large_amount_v1(client: Client, comm: SpeculosClien

parsed_events = parse_signing_events(all_events)

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

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


@pytest.mark.timeout(0) # disable timeout
Expand Down

0 comments on commit 22b6fed

Please sign in to comment.