-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_flows_helpers.py
445 lines (397 loc) · 15.8 KB
/
input_flows_helpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
from trezorlib import messages, models
from trezorlib.debuglink import TrezorClientDebugLink as Client
from . import translations as TR
from .common import BRGeneratorType, get_text_possible_pagination
B = messages.ButtonRequestType
class PinFlow:
def __init__(self, client: Client):
self.client = client
self.debug = self.client.debug
def setup_new_pin(
self, pin: str, second_different_pin: str | None = None
) -> BRGeneratorType:
yield # Enter PIN
assert "PinKeyboard" in self.debug.wait_layout().all_components()
self.debug.input(pin)
if self.client.model is models.T2B1:
yield # Reenter PIN
TR.assert_in(
self.debug.wait_layout().text_content(), "pin__reenter_to_confirm"
)
self.debug.press_yes()
yield # Enter PIN again
assert "PinKeyboard" in self.debug.wait_layout().all_components()
if second_different_pin is not None:
self.debug.input(second_different_pin)
else:
self.debug.input(pin)
class BackupFlow:
def __init__(self, client: Client):
self.client = client
self.debug = self.client.debug
def confirm_new_wallet(self) -> BRGeneratorType:
yield
TR.assert_in(self.debug.wait_layout().text_content(), "reset__by_continuing")
if self.client.model is models.T2B1:
self.debug.press_right()
self.debug.press_yes()
class RecoveryFlow:
def __init__(self, client: Client):
self.client = client
self.debug = self.client.debug
def _text_content(self) -> str:
return self.debug.wait_layout().text_content()
def confirm_recovery(self) -> BRGeneratorType:
yield
TR.assert_in(self._text_content(), "reset__by_continuing")
if self.client.model is models.T2B1:
self.debug.press_right()
self.debug.press_yes()
def confirm_dry_run(self) -> BRGeneratorType:
yield
TR.assert_in(self._text_content(), "recovery__check_dry_run")
self.debug.press_yes()
def setup_slip39_recovery(self, num_words: int) -> BRGeneratorType:
if self.client.model is models.T2B1:
yield from self.tr_recovery_homescreen()
yield from self.input_number_of_words(num_words)
yield from self.enter_any_share()
def setup_bip39_recovery(self, num_words: int) -> BRGeneratorType:
if self.client.model is models.T2B1:
yield from self.tr_recovery_homescreen()
yield from self.input_number_of_words(num_words)
yield from self.enter_your_backup()
def tr_recovery_homescreen(self) -> BRGeneratorType:
yield
TR.assert_in(self._text_content(), "recovery__num_of_words")
self.debug.press_yes()
def enter_your_backup(self) -> BRGeneratorType:
yield
TR.assert_in(self._text_content(), "recovery__enter_backup")
is_dry_run = any(
title in self.debug.wait_layout().title().lower()
for title in TR.translate("recovery__title_dry_run", lower=True)
)
if self.client.model is models.T2B1 and not is_dry_run:
# Normal recovery has extra info (not dry run)
self.debug.press_right(wait=True)
self.debug.press_right(wait=True)
self.debug.press_yes()
def enter_any_share(self) -> BRGeneratorType:
yield
TR.assert_in(self._text_content(), "recovery__enter_any_share")
is_dry_run = any(
title in self.debug.wait_layout().title().lower()
for title in TR.translate("recovery__title_dry_run", lower=True)
)
if self.client.model is models.T2B1 and not is_dry_run:
# Normal recovery has extra info (not dry run)
self.debug.press_right(wait=True)
self.debug.press_right(wait=True)
self.debug.press_yes()
def abort_recovery(self, confirm: bool) -> BRGeneratorType:
yield
if self.client.model is models.T2B1:
TR.assert_in(self._text_content(), "recovery__num_of_words")
else:
TR.assert_in(self._text_content(), "recovery__enter_any_share")
self.debug.press_no()
yield
TR.assert_in(self._text_content(), "recovery__wanna_cancel_recovery")
if self.client.model is models.T2B1:
self.debug.press_right()
if confirm:
self.debug.press_yes()
else:
self.debug.press_no()
def input_number_of_words(self, num_words: int) -> BRGeneratorType:
br = yield
assert br.code == B.MnemonicWordCount
if self.client.model is models.T2B1:
TR.assert_in(self.debug.wait_layout().title(), "word_count__title")
else:
TR.assert_in(self._text_content(), "recovery__num_of_words")
self.debug.input(str(num_words))
def warning_invalid_recovery_seed(self) -> BRGeneratorType:
br = yield
assert br.code == B.Warning
TR.assert_in(self._text_content(), "recovery__invalid_wallet_backup_entered")
self.debug.press_yes()
def warning_invalid_recovery_share(self) -> BRGeneratorType:
br = yield
assert br.code == B.Warning
TR.assert_in(self._text_content(), "recovery__invalid_share_entered")
self.debug.press_yes()
def warning_group_threshold_reached(self) -> BRGeneratorType:
br = yield
assert br.code == B.Warning
TR.assert_in(self._text_content(), "recovery__group_threshold_reached")
self.debug.press_yes()
def warning_share_already_entered(self) -> BRGeneratorType:
br = yield
assert br.code == B.Warning
TR.assert_in(self._text_content(), "recovery__share_already_entered")
self.debug.press_yes()
def warning_share_from_another_shamir(self) -> BRGeneratorType:
br = yield
assert br.code == B.Warning
TR.assert_in(self._text_content(), "recovery__share_from_another_shamir")
self.debug.press_yes()
def success_share_group_entered(self) -> BRGeneratorType:
yield
TR.assert_in(self._text_content(), "recovery__you_have_entered")
self.debug.press_yes()
def success_wallet_recovered(self) -> BRGeneratorType:
br = yield
assert br.code == B.Success
TR.assert_in(self._text_content(), "recovery__wallet_recovered")
self.debug.press_yes()
def success_bip39_dry_run_valid(self) -> BRGeneratorType:
br = yield
assert br.code == B.Success
text = get_text_possible_pagination(self.debug, br)
# TODO: make sure the translations fit on one page
if self.client.model not in (models.T2T1, models.T3T1):
TR.assert_in(text, "recovery__dry_run_bip39_valid_match")
self.debug.press_yes()
def success_slip39_dryrun_valid(self) -> BRGeneratorType:
br = yield
assert br.code == B.Success
text = get_text_possible_pagination(self.debug, br)
# TODO: make sure the translations fit on one page
if self.client.model not in (models.T2T1, models.T3T1):
TR.assert_in(text, "recovery__dry_run_slip39_valid_match")
self.debug.press_yes()
def warning_slip39_dryrun_mismatch(self) -> BRGeneratorType:
br = yield
assert br.code == B.Warning
text = get_text_possible_pagination(self.debug, br)
# TODO: make sure the translations fit on one page on TT
if self.client.model not in (models.T2T1, models.T3T1):
TR.assert_in(text, "recovery__dry_run_slip39_valid_mismatch")
self.debug.press_yes()
def warning_bip39_dryrun_mismatch(self) -> BRGeneratorType:
br = yield
assert br.code == B.Warning
text = get_text_possible_pagination(self.debug, br)
# TODO: make sure the translations fit on one page
if self.client.model not in (models.T2T1, models.T3T1):
TR.assert_in(text, "recovery__dry_run_bip39_valid_mismatch")
self.debug.press_yes()
def success_more_shares_needed(
self, count_needed: int | None = None
) -> BRGeneratorType:
br = yield
text = get_text_possible_pagination(self.debug, br)
if count_needed is not None:
assert str(count_needed) in text
self.debug.press_yes()
def input_mnemonic(self, mnemonic: list[str]) -> BRGeneratorType:
br = yield
assert br.code == B.MnemonicInput
assert "MnemonicKeyboard" in self.debug.wait_layout().all_components()
for _, word in enumerate(mnemonic):
self.debug.input(word)
def input_all_slip39_shares(
self,
shares: list[str],
has_groups: bool = False,
click_info: bool = False,
) -> BRGeneratorType:
for index, share in enumerate(shares):
mnemonic = share.split(" ")
yield from self.input_mnemonic(mnemonic)
if index < len(shares) - 1:
if has_groups:
yield from self.success_share_group_entered()
if self.client.model in (models.T2T1, models.T3T1) and click_info:
yield from self.tt_click_info()
yield from self.success_more_shares_needed()
def tt_click_info(
self,
) -> BRGeneratorType:
# Moving through the INFO button
self.debug.press_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
TR.assert_equals(
self.debug.wait_layout().title(), "ethereum__title_confirm_data"
)
if info:
self.debug.press_info()
elif cancel:
self.debug.press_no()
else:
self.debug.press_yes()
def paginate_data(self) -> BRGeneratorType:
br = yield
TR.assert_equals(
self.debug.wait_layout().title(), "ethereum__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
TR.assert_equals(
self.debug.wait_layout().title(), "ethereum__title_confirm_data"
)
assert br.pages is not None
assert br.pages > 2
if self.client.model in (models.T2T1, models.T3T1):
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,
go_back_from_summary: bool = False,
) -> BRGeneratorType:
yield
TR.assert_equals(self.debug.wait_layout().title(), "words__recipient")
if self.client.model in (models.T2T1, models.T3T1):
if cancel:
self.debug.press_no()
else:
self.debug.press_yes()
yield
TR.assert_equals(
self.debug.wait_layout().title(), "words__title_summary"
)
TR.assert_in(
self.debug.wait_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(wait=True)
TR.assert_in(
self.debug.wait_layout().text_content(), "ethereum__gas_limit"
)
TR.assert_in(
self.debug.wait_layout().text_content(), "ethereum__gas_price"
)
self.debug.press_no(wait=True)
self.debug.press_yes()
else:
if cancel:
self.debug.press_left()
else:
self.debug.press_right()
yield
TR.assert_in(
self.debug.wait_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(wait=True)
TR.assert_in(
self.debug.wait_layout().text_content(), "ethereum__gas_limit"
)
self.debug.press_right(wait=True)
TR.assert_in(
self.debug.wait_layout().text_content(), "ethereum__gas_price"
)
self.debug.press_left(wait=True)
self.debug.press_left(wait=True)
self.debug.press_middle()
def confirm_tx_staking(
self,
info: bool = False,
) -> BRGeneratorType:
yield
TR.assert_equals_multiple(
self.debug.wait_layout().title(),
[
"ethereum__staking_stake",
"ethereum__staking_unstake",
"ethereum__staking_claim",
],
)
TR.assert_equals_multiple(
self.debug.wait_layout().text_content(),
[
"ethereum__staking_stake_intro",
"ethereum__staking_unstake_intro",
"ethereum__staking_claim_intro",
],
)
if self.client.model in (models.T2T1, models.T3T1):
# confirm intro
if info:
self.debug.press_info(wait=True)
TR.assert_equals_multiple(
self.debug.wait_layout().title(),
[
"ethereum__staking_stake_address",
"ethereum__staking_claim_address",
],
)
self.debug.press_no(wait=True)
self.debug.press_yes()
yield
# confirm summary
if info:
self.debug.press_info(wait=True)
TR.assert_in(
self.debug.wait_layout().text_content(), "ethereum__gas_limit"
)
TR.assert_in(
self.debug.wait_layout().text_content(), "ethereum__gas_price"
)
self.debug.press_no(wait=True)
self.debug.press_yes()
yield
else:
# confirm intro
if info:
self.debug.press_right(wait=True)
TR.assert_equals_multiple(
self.debug.wait_layout().title(),
[
"ethereum__staking_stake_address",
"ethereum__staking_claim_address",
],
)
self.debug.press_left(wait=True)
self.debug.press_middle()
yield
# confirm summary
if info:
self.debug.press_right(wait=True)
TR.assert_in(
self.debug.wait_layout().text_content(), "ethereum__gas_limit"
)
self.debug.press_right(wait=True)
TR.assert_in(
self.debug.wait_layout().text_content(), "ethereum__gas_price"
)
self.debug.press_left(wait=True)
self.debug.press_left(wait=True)
self.debug.press_middle()
yield