Skip to content

Commit

Permalink
chore(tests): refactor Ethereum input flows
Browse files Browse the repository at this point in the history
[no changelog]
  • Loading branch information
grdddj committed Aug 9, 2023
1 parent 4434d09 commit 9117a3d
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 99 deletions.
3 changes: 0 additions & 3 deletions tests/device_tests/ethereum/test_signtx.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,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()
Expand Down Expand Up @@ -387,8 +386,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()


Expand Down
116 changes: 20 additions & 96 deletions tests/input_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
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

Expand All @@ -51,6 +51,7 @@ def __init__(self, client: Client):
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
Expand Down Expand Up @@ -730,13 +731,8 @@ def __init__(self, client: Client, cancel: bool = False):
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):
Expand All @@ -745,110 +741,38 @@ def __init__(self, client: Client, cancel: bool = False):
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
if self.cancel:
self.debug.press_no()
yield # confirm recipient
self.debug.press_no()
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()

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 amount
self.debug.wait_layout()
self.debug.press_yes()

yield # confirm before send
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 from self.ETH.confirm_data(cancel=True)
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(
Expand Down
78 changes: 78 additions & 0 deletions tests/input_flows_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,81 @@ def tt_click_info(
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()

0 comments on commit 9117a3d

Please sign in to comment.