1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 04:18:10 +00:00

chore(tests): refactor Ethereum input flows

[no changelog]
This commit is contained in:
grdddj 2023-08-02 12:48:06 +02:00 committed by Jiří Musil
parent 8956350aca
commit 02a0f1d5a2
3 changed files with 98 additions and 105 deletions

View File

@ -82,7 +82,6 @@ def _do_test_signtx(client: Client, parameters: dict, result: dict, input_flow=N
assert sig_v == result["sig_v"] 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") @pytest.mark.skip_t1("T1 does not support input flows")
def test_signtx_fee_info(client: Client): def test_signtx_fee_info(client: Client):
input_flow = InputFlowEthereumSignTxShowFeeInfo(client).get() 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): 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() return InputFlowEthereumSignTxDataGoBack(client, cancel).get()

View File

@ -27,7 +27,7 @@ from .common import (
click_through, click_through,
read_and_confirm_mnemonic, read_and_confirm_mnemonic,
) )
from .input_flows_helpers import BackupFlow, PinFlow, RecoveryFlow from .input_flows_helpers import BackupFlow, EthereumFlow, PinFlow, RecoveryFlow
B = messages.ButtonRequestType B = messages.ButtonRequestType
@ -48,6 +48,7 @@ class InputFlowBase:
self.PIN = PinFlow(self.client) self.PIN = PinFlow(self.client)
self.REC = RecoveryFlow(self.client) self.REC = RecoveryFlow(self.client)
self.BAK = BackupFlow(self.client) self.BAK = BackupFlow(self.client)
self.ETH = EthereumFlow(self.client)
def model(self) -> str | None: def model(self) -> str | None:
return self.client.features.model return self.client.features.model
@ -736,13 +737,8 @@ class InputFlowEthereumSignTxShowFeeInfo(InputFlowBase):
super().__init__(client) super().__init__(client)
self.cancel = cancel self.cancel = cancel
def input_flow_tt(self) -> BRGeneratorType: def input_flow_common(self) -> BRGeneratorType:
yield # confirm recipient yield from self.ETH.confirm_tx(info=True)
self.debug.press_yes()
yield # summary
self.debug.press_info(wait=True)
self.debug.press_no(wait=True)
self.debug.press_yes(wait=True)
class InputFlowEthereumSignTxDataSkip(InputFlowBase): class InputFlowEthereumSignTxDataSkip(InputFlowBase):
@ -751,116 +747,38 @@ class InputFlowEthereumSignTxDataSkip(InputFlowBase):
self.cancel = cancel self.cancel = cancel
def input_flow_common(self) -> BRGeneratorType: def input_flow_common(self) -> BRGeneratorType:
yield # confirm data yield from self.ETH.confirm_data()
self.debug.press_yes() yield from self.ETH.confirm_tx(cancel=self.cancel)
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()
class InputFlowEthereumSignTxDataScrollDown(InputFlowBase): class InputFlowEthereumSignTxDataScrollDown(InputFlowBase):
SHOW_ALL = (143, 167)
def __init__(self, client: Client, cancel: bool = False): def __init__(self, client: Client, cancel: bool = False):
super().__init__(client) super().__init__(client)
self.cancel = cancel self.cancel = cancel
def input_flow_tt(self) -> BRGeneratorType: def input_flow_common(self) -> BRGeneratorType:
yield # confirm data yield from self.ETH.confirm_data(info=True)
self.debug.wait_layout() yield from self.ETH.paginate_data()
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
if self.cancel: if self.cancel:
self.debug.press_no() yield from self.ETH.confirm_data(cancel=True)
yield # confirm recipient
self.debug.press_no()
else: else:
self.debug.press_yes(wait=True) yield from self.ETH.confirm_data()
yield from self.ETH.confirm_tx()
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()
class InputFlowEthereumSignTxDataGoBack(InputFlowBase): class InputFlowEthereumSignTxDataGoBack(InputFlowBase):
SHOW_ALL = (143, 167)
GO_BACK = (16, 220)
def __init__(self, client: Client, cancel: bool = False): def __init__(self, client: Client, cancel: bool = False):
super().__init__(client) super().__init__(client)
self.cancel = cancel self.cancel = cancel
def input_flow_tt(self) -> BRGeneratorType: def input_flow_common(self) -> BRGeneratorType:
yield # confirm data yield from self.ETH.confirm_data(info=True)
self.debug.wait_layout() yield from self.ETH.paginate_data_go_back()
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: if self.cancel:
self.debug.press_no() yield from self.ETH.confirm_data(cancel=True)
else: else:
self.debug.press_yes() yield from self.ETH.confirm_data()
yield # confirm recipient yield from self.ETH.confirm_tx()
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 get_mnemonic_and_confirm_success( def get_mnemonic_and_confirm_success(

View File

@ -247,3 +247,81 @@ class RecoveryFlow:
yield yield
self.debug.swipe_up() self.debug.swipe_up()
self.debug.press_yes() 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()