From 02a0f1d5a2912c8511907f00dff6dcb1b2074458 Mon Sep 17 00:00:00 2001 From: grdddj Date: Wed, 2 Aug 2023 12:48:06 +0200 Subject: [PATCH] chore(tests): refactor Ethereum input flows [no changelog] --- tests/device_tests/ethereum/test_signtx.py | 3 - tests/input_flows.py | 122 ++++----------------- tests/input_flows_helpers.py | 78 +++++++++++++ 3 files changed, 98 insertions(+), 105 deletions(-) diff --git a/tests/device_tests/ethereum/test_signtx.py b/tests/device_tests/ethereum/test_signtx.py index fe0186bf87..c38a42e677 100644 --- a/tests/device_tests/ethereum/test_signtx.py +++ b/tests/device_tests/ethereum/test_signtx.py @@ -82,7 +82,6 @@ def _do_test_signtx(client: Client, parameters: dict, result: dict, input_flow=N assert sig_v == result["sig_v"] -@pytest.mark.skip_tr("Info is being shown in all the parametrized cases above") @pytest.mark.skip_t1("T1 does not support input flows") def test_signtx_fee_info(client: Client): input_flow = InputFlowEthereumSignTxShowFeeInfo(client).get() @@ -388,8 +387,6 @@ def input_flow_data_scroll_down(client: Client, cancel: bool = False): def input_flow_data_go_back(client: Client, cancel: bool = False): - if client.features.model == "R": - pytest.skip("Go back not supported for model R") return InputFlowEthereumSignTxDataGoBack(client, cancel).get() diff --git a/tests/input_flows.py b/tests/input_flows.py index d9f3c8b567..09e3975d73 100644 --- a/tests/input_flows.py +++ b/tests/input_flows.py @@ -27,7 +27,7 @@ from .common import ( click_through, read_and_confirm_mnemonic, ) -from .input_flows_helpers import BackupFlow, PinFlow, RecoveryFlow +from .input_flows_helpers import BackupFlow, EthereumFlow, PinFlow, RecoveryFlow B = messages.ButtonRequestType @@ -48,6 +48,7 @@ class InputFlowBase: self.PIN = PinFlow(self.client) self.REC = RecoveryFlow(self.client) self.BAK = BackupFlow(self.client) + self.ETH = EthereumFlow(self.client) def model(self) -> str | None: return self.client.features.model @@ -736,13 +737,8 @@ class InputFlowEthereumSignTxShowFeeInfo(InputFlowBase): super().__init__(client) self.cancel = cancel - def input_flow_tt(self) -> BRGeneratorType: - yield # confirm recipient - self.debug.press_yes() - yield # summary - self.debug.press_info(wait=True) - self.debug.press_no(wait=True) - self.debug.press_yes(wait=True) + def input_flow_common(self) -> BRGeneratorType: + yield from self.ETH.confirm_tx(info=True) class InputFlowEthereumSignTxDataSkip(InputFlowBase): @@ -751,116 +747,38 @@ class InputFlowEthereumSignTxDataSkip(InputFlowBase): self.cancel = cancel def input_flow_common(self) -> BRGeneratorType: - yield # confirm data - self.debug.press_yes() - yield # confirm recipient - self.debug.press_yes() - yield # summary - if self.cancel: - self.debug.press_no() - yield # confirm recipient - self.debug.press_no() - else: - self.debug.press_yes() + yield from self.ETH.confirm_data() + yield from self.ETH.confirm_tx(cancel=self.cancel) class InputFlowEthereumSignTxDataScrollDown(InputFlowBase): - SHOW_ALL = (143, 167) - def __init__(self, client: Client, cancel: bool = False): super().__init__(client) self.cancel = cancel - def input_flow_tt(self) -> BRGeneratorType: - yield # confirm data - self.debug.wait_layout() - self.debug.click(self.SHOW_ALL) - - br = yield # paginated data - assert br.pages is not None - for i in range(br.pages): - self.debug.wait_layout() - if i < br.pages - 1: - self.debug.swipe_up() - - self.debug.press_yes() - yield # confirm data - self.debug.press_yes() - yield # confirm recipient - self.debug.press_yes() - yield # summary + def input_flow_common(self) -> BRGeneratorType: + yield from self.ETH.confirm_data(info=True) + yield from self.ETH.paginate_data() if self.cancel: - self.debug.press_no() - yield # confirm recipient - self.debug.press_no() + yield from self.ETH.confirm_data(cancel=True) else: - self.debug.press_yes(wait=True) - - def input_flow_tr(self) -> BRGeneratorType: - # TODO: fix this for TR and allow for cancelling the data - - yield # confirm address - self.debug.wait_layout() - self.debug.press_yes() - - yield # confirm data - self.debug.press_info() - - br = yield # paginated data - assert br.pages is not None - for _ in range(br.pages): - self.debug.wait_layout() - self.debug.swipe_up() - - yield # confirm data - self.debug.press_yes() - - yield # confirm amount - self.debug.wait_layout() - self.debug.press_yes() - - yield # confirm before send - if self.cancel: - self.debug.press_no() - else: - self.debug.press_yes() + yield from self.ETH.confirm_data() + yield from self.ETH.confirm_tx() class InputFlowEthereumSignTxDataGoBack(InputFlowBase): - SHOW_ALL = (143, 167) - GO_BACK = (16, 220) - def __init__(self, client: Client, cancel: bool = False): super().__init__(client) self.cancel = cancel - def input_flow_tt(self) -> BRGeneratorType: - yield # confirm data - self.debug.wait_layout() - self.debug.click(self.SHOW_ALL) - - br = yield # paginated data - assert br.pages is not None - for i in range(br.pages): - self.debug.wait_layout() - if i == 2: - self.debug.click(self.GO_BACK) - yield # confirm data - self.debug.wait_layout() - if self.cancel: - self.debug.press_no() - else: - self.debug.press_yes() - yield # confirm recipient - self.debug.press_yes() - yield # summary - self.debug.press_yes() - return - - elif i < br.pages - 1: - self.debug.swipe_up() - - # TODO: support this for TR and allow for cancelling the data + def input_flow_common(self) -> BRGeneratorType: + yield from self.ETH.confirm_data(info=True) + yield from self.ETH.paginate_data_go_back() + if self.cancel: + yield from self.ETH.confirm_data(cancel=True) + else: + yield from self.ETH.confirm_data() + yield from self.ETH.confirm_tx() def get_mnemonic_and_confirm_success( diff --git a/tests/input_flows_helpers.py b/tests/input_flows_helpers.py index 52fa35c454..4e189ac95e 100644 --- a/tests/input_flows_helpers.py +++ b/tests/input_flows_helpers.py @@ -247,3 +247,81 @@ class RecoveryFlow: yield self.debug.swipe_up() self.debug.press_yes() + + +class EthereumFlow: + GO_BACK = (16, 220) + + def __init__(self, client: Client): + self.client = client + self.debug = self.client.debug + + def confirm_data(self, info: bool = False, cancel: bool = False) -> BRGeneratorType: + yield + assert self.debug.wait_layout().title() == "CONFIRM DATA" + assert "Size:" in self.debug.wait_layout().text_content() + if info: + self.debug.press_info() + elif cancel: + self.debug.press_no() + else: + self.debug.press_yes() + + def paginate_data(self) -> BRGeneratorType: + br = yield + assert self.debug.wait_layout().title() == "CONFIRM DATA" + assert br.pages is not None + for i in range(br.pages): + self.debug.wait_layout() + if i < br.pages - 1: + self.debug.swipe_up() + self.debug.press_yes() + + def paginate_data_go_back(self) -> BRGeneratorType: + br = yield + assert self.debug.wait_layout().title() == "CONFIRM DATA" + assert br.pages is not None + assert br.pages > 2 + if self.debug.model == "T": + self.debug.swipe_up(wait=True) + self.debug.swipe_up(wait=True) + self.debug.click(self.GO_BACK) + else: + self.debug.press_right() + self.debug.press_right() + self.debug.press_left() + self.debug.press_left() + self.debug.press_left() + + def confirm_tx(self, cancel: bool = False, info: bool = False) -> BRGeneratorType: + yield + assert self.debug.wait_layout().title() == "RECIPIENT" + + if self.debug.model == "T": + if cancel: + self.debug.press_no() + else: + self.debug.press_yes() + yield + assert self.debug.wait_layout().title() == "SUMMARY" + assert "Maximum fee:" in self.debug.wait_layout().text_content() + if info: + self.debug.press_info(wait=True) + assert "Gas limit:" in self.debug.wait_layout().text_content() + assert "Gas price:" in self.debug.wait_layout().text_content() + self.debug.press_no(wait=True) + self.debug.press_yes() + else: + if cancel: + self.debug.press_left() + else: + self.debug.press_right() + assert "Maximum fee:" in self.debug.wait_layout().text_content() + if info: + self.debug.press_right(wait=True) + assert "Gas limit:" in self.debug.wait_layout().text_content() + self.debug.press_right(wait=True) + assert "Gas price:" in self.debug.wait_layout().text_content() + self.debug.press_left(wait=True) + self.debug.press_left(wait=True) + self.debug.press_middle()