1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-15 12:08:59 +00:00

fix(core): patch over problems with confirm_blob_pagination

This commit is contained in:
matejcik 2024-11-11 13:40:25 +01:00 committed by matejcik
parent 8fb41ee290
commit 3769024920
5 changed files with 123 additions and 145 deletions

View File

@ -5,7 +5,7 @@ from trezor import TR, ui, utils
from trezor.enums import ButtonRequestType
from trezor.wire import ActionCancelled
from ..common import draw_simple, interact, raise_if_not_confirmed, with_info
from ..common import draw_simple, interact, raise_if_not_confirmed
if TYPE_CHECKING:
from typing import Awaitable, Iterable, NoReturn, Sequence
@ -562,31 +562,16 @@ def confirm_blob_with_optional_pagination(
br_code: ButtonRequestType = BR_CODE_OTHER,
chunkify: bool = False,
) -> Awaitable[None]:
main_layout = trezorui2.confirm_blob(
title=title,
data=data,
description=None,
return confirm_blob(
br_name,
title,
data,
subtitle=subtitle,
verb=verb,
verb_cancel="",
verb_info=TR.buttons__view_all_data,
info=True,
hold=False,
br_code=br_code,
chunkify=chunkify,
prompt_screen=False,
page_limit=1,
)
info_layout = trezorui2.confirm_blob(
title=title,
description=None,
data=data,
verb=verb,
verb_cancel="<",
hold=False,
chunkify=chunkify,
)
return with_info(
main_layout, info_layout, br_name, br_code, repeat_button_request=True
ask_pagination=True,
)
@ -723,7 +708,7 @@ def confirm_properties(
) -> Awaitable[None]:
from ubinascii import hexlify
def handle_bytes(prop: PropertyType):
def handle_bytes(prop: PropertyType) -> tuple[str | None, str | None, bool]:
key, value = prop
if isinstance(value, (bytes, bytearray, memoryview)):
return (key, hexlify(value).decode(), True)
@ -731,7 +716,7 @@ def confirm_properties(
# When there is not space in the text, taking it as data
# to not include hyphens
is_data = value and " " not in value
return (key, value, is_data)
return (key, value, bool(is_data))
return raise_if_not_confirmed(
trezorui2.confirm_properties(

View File

@ -514,7 +514,7 @@ async def should_show_more(
raise ActionCancelled
async def confirm_blob_with_optional_pagination(
def confirm_blob_with_optional_pagination(
br_name: str,
title: str,
data: bytes | str,
@ -523,21 +523,19 @@ async def confirm_blob_with_optional_pagination(
verb_cancel: str | None = None,
br_code: ButtonRequestType = BR_CODE_OTHER,
chunkify: bool = False,
):
) -> Awaitable[None]:
verb = verb or TR.buttons__confirm # def_arg
layout = trezorui2.confirm_blob(
title=title,
description=None,
data=data,
verb=verb,
verb_cancel=verb_cancel,
verb_cancel=None,
chunkify=chunkify,
)
if layout.page_count() > 1:
return await _confirm_ask_pagination(
br_name, title, data, subtitle or "", br_code
)
return _confirm_ask_pagination(br_name, title, data, subtitle or "", br_code)
else:
return raise_if_not_confirmed(layout, br_name, br_code)
@ -570,7 +568,11 @@ async def _confirm_ask_pagination(
):
return
await interact(confirm_more_layout, br_name, br_code, raise_on_cancel=None)
result = await interact(
confirm_more_layout, br_name, br_code, raise_on_cancel=None
)
if result is CONFIRMED:
return
assert False

View File

@ -1196,12 +1196,6 @@ class InputFlowEthereumSignTxDataScrollDown(InputFlowBase):
yield from self.ETH.confirm_data(info=True)
yield from self.ETH.paginate_data()
if self.debug.layout_type is LayoutType.TR:
self.debug.press_right()
else:
self.debug.click(buttons.OK)
yield from self.ETH.confirm_tx()

View File

@ -365,11 +365,15 @@ class EthereumFlow:
assert br.name == "confirm_data"
assert br.pages is not None
TR.assert_equals(self.debug.read_layout().title(), "ethereum__title_input_data")
for i in range(br.pages):
for _ in range(br.pages):
self.debug.read_layout()
if i < br.pages - 1:
go_next(self.debug)
self.debug.press_yes()
go_next(self.debug)
self.debug.read_layout()
if self.debug.layout_type is LayoutType.TR:
# TR is going back to the "show more" screen here
assert (yield).name == "confirm_data"
self.debug.press_yes()
def paginate_data_go_back(self) -> BRGeneratorType:
br = yield
@ -390,116 +394,109 @@ class EthereumFlow:
else:
raise ValueError(f"Unknown layout: {self.client.layout_type}")
def _confirm_tx_tt(
self, cancel: bool, info: bool, go_back_from_summary: bool
) -> BRGeneratorType:
assert (yield).name == "confirm_ethereum_tx"
TR.assert_equals(self.debug.read_layout().title(), "words__address")
if cancel:
self.debug.press_no()
return
self.debug.press_yes()
assert (yield).name == "confirm_ethereum_tx"
TR.assert_equals(self.debug.read_layout().title(), "words__title_summary")
TR.assert_in(self.debug.read_layout().text_content(), "send__maximum_fee")
if go_back_from_summary:
self.debug.press_no()
assert (yield).name == "confirm_ethereum_tx"
self.debug.press_yes()
assert (yield).name == "confirm_ethereum_tx"
if info:
self.debug.press_info()
TR.assert_in(self.debug.read_layout().text_content(), "ethereum__gas_limit")
TR.assert_in(self.debug.read_layout().text_content(), "ethereum__gas_price")
self.debug.press_no()
self.debug.press_yes()
assert (yield).name == "confirm_ethereum_tx"
def _confirm_tx_tr(
self, cancel: bool, info: bool, go_back_from_summary: bool
) -> BRGeneratorType:
assert (yield).name == "confirm_ethereum_tx"
TR.assert_in_multiple(
self.debug.read_layout().title(),
["ethereum__interaction_contract", "words__recipient"],
)
if cancel:
self.debug.press_left()
return
self.debug.press_right()
assert (yield).name == "confirm_ethereum_tx"
TR.assert_in(self.debug.read_layout().text_content(), "send__maximum_fee")
if go_back_from_summary:
self.debug.press_left()
assert (yield).name == "confirm_ethereum_tx"
self.debug.press_right()
assert (yield).name == "confirm_ethereum_tx"
if info:
self.debug.press_right()
TR.assert_in(self.debug.read_layout().text_content(), "ethereum__gas_limit")
self.debug.press_right()
TR.assert_in(self.debug.read_layout().text_content(), "ethereum__gas_price")
self.debug.press_left()
self.debug.press_left()
self.debug.press_middle()
assert (yield).name == "confirm_ethereum_tx"
def _confirm_tx_mercury(
self, cancel: bool, info: bool, go_back_from_summary: bool
) -> BRGeneratorType:
assert (yield).name == "confirm_output"
title = self.debug.read_layout().title()
TR.assert_in(title, "words__address")
TR.assert_in(title, "words__recipient")
if cancel:
self.debug.press_no()
return
self.debug.swipe_up()
assert (yield).name == "confirm_total"
layout = self.debug.read_layout()
TR.assert_equals(layout.title(), "words__title_summary")
TR.assert_in(layout.text_content(), "send__maximum_fee")
if go_back_from_summary:
self.debug.press_no()
assert (yield).name == "confirm_ethereum_tx"
self.debug.press_yes()
assert (yield).name == "confirm_ethereum_tx"
if info:
self.debug.click(buttons.CORNER_BUTTON)
self.debug.synchronize_at("VerticalMenu")
self.debug.click(buttons.VERTICAL_MENU[0])
text = self.debug.read_layout().text_content()
TR.assert_in(text, "ethereum__gas_limit")
TR.assert_in(text, "ethereum__gas_price")
self.debug.click(buttons.CORNER_BUTTON)
self.debug.click(buttons.CORNER_BUTTON)
self.debug.swipe_up()
self.debug.read_layout()
self.debug.click(buttons.TAP_TO_CONFIRM)
assert (yield).name == "confirm_ethereum_tx"
def confirm_tx(
self,
cancel: bool = False,
info: bool = False,
go_back_from_summary: bool = False,
) -> BRGeneratorType:
yield
if self.client.layout_type is LayoutType.TT:
TR.assert_equals(self.debug.read_layout().title(), "words__address")
if cancel:
self.debug.press_no()
else:
self.debug.press_yes()
yield
TR.assert_equals(
self.debug.read_layout().title(), "words__title_summary"
)
TR.assert_in(
self.debug.read_layout().text_content(), "send__maximum_fee"
)
if go_back_from_summary:
self.debug.press_no()
yield
self.debug.press_yes()
yield
if info:
self.debug.press_info()
TR.assert_in(
self.debug.read_layout().text_content(), "ethereum__gas_limit"
)
TR.assert_in(
self.debug.read_layout().text_content(), "ethereum__gas_price"
)
self.debug.press_no()
self.debug.press_yes()
yield
yield from self._confirm_tx_tt(cancel, info, go_back_from_summary)
elif self.client.layout_type is LayoutType.TR:
TR.assert_in_multiple(
self.debug.read_layout().title(),
["ethereum__interaction_contract", "words__recipient"],
)
if cancel:
self.debug.press_left()
else:
self.debug.press_right()
yield
TR.assert_in(
self.debug.read_layout().text_content(), "send__maximum_fee"
)
if go_back_from_summary:
self.debug.press_left()
yield
self.debug.press_right()
yield
if info:
self.debug.press_right()
TR.assert_in(
self.debug.read_layout().text_content(), "ethereum__gas_limit"
)
self.debug.press_right()
TR.assert_in(
self.debug.read_layout().text_content(), "ethereum__gas_price"
)
self.debug.press_left()
self.debug.press_left()
self.debug.press_middle()
yield
yield from self._confirm_tx_tr(cancel, info, go_back_from_summary)
elif self.client.layout_type is LayoutType.Mercury:
TR.assert_equals(
self.debug.read_layout().title().split("\n")[0], "words__address"
)
TR.assert_equals(
self.debug.read_layout().title().split("\n")[1], "words__recipient"
)
if cancel:
self.debug.press_no()
else:
self.debug.swipe_up()
yield
TR.assert_equals(
self.debug.read_layout().title(), "words__title_summary"
)
TR.assert_in(
self.debug.read_layout().text_content(), "send__maximum_fee"
)
if go_back_from_summary:
self.debug.press_no()
yield
self.debug.press_yes()
yield
if info:
self.debug.click(buttons.CORNER_BUTTON)
self.debug.synchronize_at("VerticalMenu")
self.debug.click(buttons.VERTICAL_MENU[0])
TR.assert_in(
self.debug.read_layout().text_content(), "ethereum__gas_limit"
)
TR.assert_in(
self.debug.read_layout().text_content(), "ethereum__gas_price"
)
self.debug.click(buttons.CORNER_BUTTON)
self.debug.click(buttons.CORNER_BUTTON)
self.debug.swipe_up()
self.debug.read_layout()
self.debug.click(buttons.TAP_TO_CONFIRM)
yield
yield from self._confirm_tx_mercury(cancel, info, go_back_from_summary)
else:
raise ValueError("Unknown model!")

View File

@ -4884,7 +4884,7 @@
"T2T1_en_ethereum-test_signtx.py::test_signtx[True-nodata_2_bigvalue]": "476c3f407ad07d647c9beaec9f76ff465a5c57d864aa63c272645c510f749348",
"T2T1_en_ethereum-test_signtx.py::test_signtx[True-wanchain]": "dfff960ef77cfbf7f6a83fd2abb772d89bbcd56d9304e943948116f4db49c5aa",
"T2T1_en_ethereum-test_signtx.py::test_signtx_data_pagination[input_flow_data_go_back]": "6aee3ea9f58ffb9efd3994e48e6edf99066d01ada5157807689b20d23c72686d",
"T2T1_en_ethereum-test_signtx.py::test_signtx_data_pagination[input_flow_data_scroll_down]": "b94ff28c5d7d0fa65abed4657edf5e72690f98d01ebf6d30f1fd21165801f816",
"T2T1_en_ethereum-test_signtx.py::test_signtx_data_pagination[input_flow_data_scroll_down]": "79a9a11a2c923e42c77f9b292ed3fdf0f7377d95e172d70cdb17807fec3fa515",
"T2T1_en_ethereum-test_signtx.py::test_signtx_data_pagination[input_flow_data_skip]": "886f38b28513e50050de6fa8cbad14a78d153cb9cae53efdeda322b88924dc24",
"T2T1_en_ethereum-test_signtx.py::test_signtx_eip1559[False-Ledger Live legacy path]": "1e45b9431ebda309c36978c7cd2843322b79af9462883be27785e0d85d1e39d7",
"T2T1_en_ethereum-test_signtx.py::test_signtx_eip1559[False-data_1]": "e91605bf24835692c5dedbce0d43c37713ef518b6e6160785cfcd33d65f5fb1b",
@ -13643,8 +13643,8 @@
"T3B1_en_ethereum-test_signtx.py::test_signtx[True-nodata_1]": "36fce50aada88147e459c1146ab07e37c99d561ed80964ce3bb2990751006ece",
"T3B1_en_ethereum-test_signtx.py::test_signtx[True-nodata_2_bigvalue]": "caa1f21ba4bf3d4b4ddb14498c10fb8dc9d442da1ca3e00149fecab618de61f1",
"T3B1_en_ethereum-test_signtx.py::test_signtx[True-wanchain]": "5340bc0b5683e6f1eaac6e8686c78b50ea85d9b24694a4df49ca700a6efd5fae",
"T3B1_en_ethereum-test_signtx.py::test_signtx_data_pagination[input_flow_data_go_back]": "5dda8c0f2c6ac2b5685f817a6d0f9fdbcfaa23080f0add1e91875d63c5e4f576",
"T3B1_en_ethereum-test_signtx.py::test_signtx_data_pagination[input_flow_data_scroll_down]": "5dda8c0f2c6ac2b5685f817a6d0f9fdbcfaa23080f0add1e91875d63c5e4f576",
"T3B1_en_ethereum-test_signtx.py::test_signtx_data_pagination[input_flow_data_go_back]": "122e9b2e4186fb6a745f86046f35203981be785b08a6937f44370d711536f0e8",
"T3B1_en_ethereum-test_signtx.py::test_signtx_data_pagination[input_flow_data_scroll_down]": "10b5b7141e4c74d1a63dd1029ddc36e3e19b242cce91dd7afab372052b5bd12c",
"T3B1_en_ethereum-test_signtx.py::test_signtx_data_pagination[input_flow_data_skip]": "a5682749e87ba3709f09a5e69c7c8b4d1169285049302dfc6509668483c3bac6",
"T3B1_en_ethereum-test_signtx.py::test_signtx_eip1559[False-Ledger Live legacy path]": "af789f0a99836d3931ef2dd27007aea257079afe2196e3f30cf841577b51db2f",
"T3B1_en_ethereum-test_signtx.py::test_signtx_eip1559[False-data_1]": "bef3d6f8cea104eae0674ee054939c995d519746d1390bfa640206f7d1ab2bab",