forked from trezor/trezor-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
input_flows.py
2329 lines (1900 loc) · 76.4 KB
/
input_flows.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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""
Central place for defining all input flows for the device tests.
Each model has potentially its own input flow, and in most cases
we need to distinguish between them. Doing it at one place
offers a better overview of the differences and makes it easier
to maintain. The whole `device_tests` folder can then focus
only on the actual tests and data-assertions, not on the lower-level
input flow details.
"""
from __future__ import annotations
import time
from typing import Callable, Generator
from trezorlib import messages
from trezorlib.debuglink import DebugLink, LayoutContent, LayoutType
from trezorlib.debuglink import TrezorClientDebugLink as Client
from trezorlib.debuglink import multipage_content
from . import buttons
from . import translations as TR
from .common import (
BRGeneratorType,
check_pin_backoff_time,
click_info_button_mercury,
click_info_button_tt,
click_through,
get_text_possible_pagination,
read_and_confirm_mnemonic,
swipe_if_necessary,
)
from .input_flows_helpers import BackupFlow, EthereumFlow, PinFlow, RecoveryFlow
B = messages.ButtonRequestType
class InputFlowBase:
def __init__(self, client: Client):
self.client = client
self.debug: DebugLink = client.debug
self.PIN = PinFlow(self.client)
self.REC = RecoveryFlow(self.client)
self.BAK = BackupFlow(self.client)
self.ETH = EthereumFlow(self.client)
def get(self) -> Callable[[], BRGeneratorType]:
self.client.watch_layout(True)
# There could be one common input flow for all models
if hasattr(self, "input_flow_common"):
return getattr(self, "input_flow_common")
elif self.client.layout_type is LayoutType.TT:
return self.input_flow_tt
elif self.client.layout_type is LayoutType.TR:
return self.input_flow_tr
elif self.client.layout_type is LayoutType.Mercury:
return self.input_flow_t3t1
else:
raise ValueError("Unknown model")
def input_flow_tt(self) -> BRGeneratorType:
"""Special for TT"""
raise NotImplementedError
def input_flow_tr(self) -> BRGeneratorType:
"""Special for TR"""
raise NotImplementedError
def input_flow_t3t1(self) -> BRGeneratorType:
"""Special for T3T1"""
raise NotImplementedError
def text_content(self) -> str:
return self.debug.wait_layout().text_content()
def main_component(self) -> str:
return self.debug.wait_layout().main_component()
def all_components(self) -> list[str]:
return self.debug.wait_layout().all_components()
def title(self) -> str:
return self.debug.wait_layout().title()
class InputFlowSetupDevicePINWIpeCode(InputFlowBase):
def __init__(self, client: Client, pin: str, wipe_code: str):
super().__init__(client)
self.pin = pin
self.wipe_code = wipe_code
def input_flow_common(self) -> BRGeneratorType:
yield # do you want to set/change the wipe code?
self.debug.press_yes()
if self.client.layout_type is LayoutType.TR:
yield from swipe_if_necessary(self.debug) # wipe code info
self.debug.press_yes()
yield # enter current pin
self.debug.input(self.pin)
yield # enter new wipe code
self.debug.input(self.wipe_code)
yield # enter new wipe code again
self.debug.input(self.wipe_code)
yield # success
self.debug.press_yes()
class InputFlowNewCodeMismatch(InputFlowBase):
def __init__(
self,
client: Client,
first_code: str,
second_code: str,
):
super().__init__(client)
self.first_code = first_code
self.second_code = second_code
def input_flow_common(self) -> BRGeneratorType:
yield # do you want to set/change the pin/wipe code?
self.debug.press_yes()
if self.client.layout_type is LayoutType.TR:
yield from swipe_if_necessary(self.debug) # code info
self.debug.press_yes()
def input_two_different_pins() -> BRGeneratorType:
yield from self.PIN.setup_new_pin(self.first_code, self.second_code)
yield from input_two_different_pins()
yield # PIN mismatch
self.debug.press_yes() # try again
yield from input_two_different_pins()
yield # PIN mismatch
self.debug.press_yes() # try again
yield # PIN entry again
self.debug.press_no() # cancel
class InputFlowCodeChangeFail(InputFlowBase):
def __init__(
self, client: Client, current_pin: str, new_pin_1: str, new_pin_2: str
):
super().__init__(client)
self.current_pin = current_pin
self.new_pin_1 = new_pin_1
self.new_pin_2 = new_pin_2
def input_flow_common(self) -> BRGeneratorType:
yield # do you want to change pin?
self.debug.press_yes()
yield # enter current pin
self.debug.input(self.current_pin)
yield from self.PIN.setup_new_pin(self.new_pin_1, self.new_pin_2)
yield # PIN mismatch
self.debug.press_yes() # try again
# failed retry
yield # enter current pin again
self.client.cancel()
class InputFlowWrongPIN(InputFlowBase):
def __init__(self, client: Client, wrong_pin: str):
super().__init__(client)
self.wrong_pin = wrong_pin
def input_flow_common(self) -> BRGeneratorType:
yield # do you want to change pin?
self.debug.press_yes()
yield # enter wrong current pin
self.debug.input(self.wrong_pin)
yield
self.debug.press_no()
class InputFlowPINBackoff(InputFlowBase):
def __init__(self, client: Client, wrong_pin: str, good_pin: str):
super().__init__(client)
self.wrong_pin = wrong_pin
self.good_pin = good_pin
def input_flow_common(self) -> BRGeneratorType:
"""Inputting some bad PINs and finally the correct one"""
yield # PIN entry
for attempt in range(3):
start = time.time()
self.debug.input(self.wrong_pin)
yield # PIN entry
check_pin_backoff_time(attempt, start)
self.debug.input(self.good_pin)
class InputFlowSignMessagePagination(InputFlowBase):
def __init__(self, client: Client):
super().__init__(client)
self.message_read = ""
def input_flow_tt(self) -> BRGeneratorType:
# collect screen contents into `message_read`.
# Using a helper debuglink function to assemble the final text.
layouts: list[LayoutContent] = []
br = yield # confirm address
self.debug.wait_layout()
self.debug.press_yes()
br = yield
assert br.pages is not None
for i in range(br.pages):
layout = self.debug.wait_layout()
layouts.append(layout)
if i < br.pages - 1:
self.debug.swipe_up()
self.message_read = multipage_content(layouts)
self.debug.press_yes()
def input_flow_tr(self) -> BRGeneratorType:
# confirm address
yield
self.debug.press_yes()
# press info
yield
self.debug.press_right()
# paginate through the whole message
br = yield
# TODO: try load the message_read the same way as in model T
if br.pages is not None:
for i in range(br.pages):
if i < br.pages - 1:
self.debug.swipe_up()
self.debug.press_yes()
# confirm message
yield
self.debug.press_yes()
def input_flow_t3t1(self) -> BRGeneratorType:
# collect screen contents into `message_read`.
# Using a helper debuglink function to assemble the final text.
layouts: list[LayoutContent] = []
br = yield # confirm address
self.debug.wait_layout()
self.debug.press_yes()
br = yield
# assert br.pages is not None
for i in range(br.pages or 1):
layout = self.debug.wait_layout()
layouts.append(layout)
if br.pages and i < br.pages - 1:
self.debug.swipe_up()
self.message_read = multipage_content(layouts)
self.debug.press_yes()
class InputFlowSignMessageInfo(InputFlowBase):
def __init__(self, client: Client):
super().__init__(client)
def input_flow_tt(self) -> BRGeneratorType:
yield
# show address/message info
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.press_no(wait=True)
self.debug.synchronize_at("IconDialog")
# address mismatch?
self.debug.press_no()
yield
self.debug.press_yes()
yield
self.debug.press_no()
yield
self.debug.press_no(wait=True)
self.debug.press_yes(wait=True)
def input_flow_t3t1(self) -> BRGeneratorType:
yield
# show address/message info
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.press_no(wait=True)
self.debug.synchronize_at("IconDialog")
# address mismatch?
self.debug.press_no()
yield
self.debug.press_yes()
yield
self.debug.press_no()
yield
self.debug.press_no(wait=True)
self.debug.press_yes(wait=True)
class InputFlowShowAddressQRCode(InputFlowBase):
def __init__(self, client: Client):
super().__init__(client)
def input_flow_tt(self) -> BRGeneratorType:
yield
self.debug.click(buttons.CORNER_BUTTON, wait=True)
# synchronize; TODO get rid of this once we have single-global-layout
self.debug.synchronize_at("SimplePage")
self.debug.swipe_left(wait=True)
self.debug.swipe_right(wait=True)
self.debug.swipe_left(wait=True)
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.press_no(wait=True)
self.debug.press_no(wait=True)
self.debug.press_yes()
def input_flow_tr(self) -> BRGeneratorType:
# Find out the page-length of the address
br = yield
if br.pages is not None:
address_swipes = br.pages - 1
else:
address_swipes = 0
for _ in range(address_swipes):
self.debug.press_right()
# Go into details
self.debug.press_right()
# Go through details and back
self.debug.press_right()
self.debug.press_left()
self.debug.press_left()
# Confirm
for _ in range(address_swipes):
self.debug.press_right()
self.debug.press_middle()
def input_flow_t3t1(self) -> BRGeneratorType:
yield
self.debug.click(buttons.CORNER_BUTTON, wait=True)
# synchronize; TODO get rid of this once we have single-global-layout
self.debug.synchronize_at("VerticalMenu")
# menu
self.debug.click(buttons.VERTICAL_MENU[0], wait=True)
self.debug.synchronize_at("Qr")
# qr code
self.debug.click(buttons.CORNER_BUTTON, wait=True)
# menu
self.debug.click(buttons.VERTICAL_MENU[1], wait=True)
# address details
self.debug.click(buttons.CORNER_BUTTON, wait=True)
# menu
self.debug.click(buttons.VERTICAL_MENU[2], wait=True)
# cancel
self.debug.swipe_up(wait=True)
# really cancel
self.debug.click(buttons.CORNER_BUTTON, wait=True)
# menu
layout = self.debug.click(buttons.CORNER_BUTTON, wait=True)
while "PromptScreen" not in layout.all_components():
layout = self.debug.swipe_up(wait=True)
self.debug.synchronize_at("PromptScreen")
# tap to confirm
self.debug.click(buttons.TAP_TO_CONFIRM)
class InputFlowShowAddressQRCodeCancel(InputFlowBase):
def __init__(self, client: Client):
super().__init__(client)
def input_flow_tt(self) -> BRGeneratorType:
yield
self.debug.click(buttons.CORNER_BUTTON, wait=True)
# synchronize; TODO get rid of this once we have single-global-layout
self.debug.synchronize_at("SimplePage")
self.debug.swipe_left(wait=True)
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.press_no(wait=True)
self.debug.press_yes()
def input_flow_tr(self) -> BRGeneratorType:
yield
# Go into details
self.debug.press_right()
# Go through details and back
self.debug.press_right()
self.debug.press_left()
self.debug.press_left()
# Cancel
self.debug.press_left(wait=True)
# Confirm address mismatch
# Clicking right twice, as some languages can have two pages
self.debug.press_right()
self.debug.press_right()
def input_flow_t3t1(self) -> BRGeneratorType:
yield
self.debug.click(buttons.CORNER_BUTTON, wait=True)
# synchronize; TODO get rid of this once we have single-global-layout
self.debug.synchronize_at("VerticalMenu")
# menu
self.debug.click(buttons.VERTICAL_MENU[0], wait=True)
self.debug.synchronize_at("Qr")
# qr code
self.debug.click(buttons.CORNER_BUTTON, wait=True)
# menu
self.debug.click(buttons.VERTICAL_MENU[1], wait=True)
# address details
self.debug.click(buttons.CORNER_BUTTON, wait=True)
# menu
self.debug.click(buttons.VERTICAL_MENU[2], wait=True)
# cancel
self.debug.swipe_up(wait=True)
self.debug.synchronize_at("PromptScreen")
# really cancel
self.debug.click(buttons.TAP_TO_CONFIRM, wait=True)
class InputFlowShowMultisigXPUBs(InputFlowBase):
def __init__(self, client: Client, address: str, xpubs: list[str], index: int):
super().__init__(client)
self.address = address
self.xpubs = xpubs
self.index = index
def input_flow_tt(self) -> BRGeneratorType:
yield # multisig address warning
self.debug.press_yes()
yield # show address
layout = self.debug.wait_layout()
TR.assert_in(layout.title(), "address__title_receive_address")
assert "(MULTISIG)" in layout.title()
assert layout.text_content().replace(" ", "") == self.address
self.debug.click(buttons.CORNER_BUTTON)
assert "Qr" in self.all_components()
layout = self.debug.swipe_left(wait=True)
# address details
assert "Multisig 2 of 3" in layout.screen_content()
TR.assert_in(layout.screen_content(), "address_details__derivation_path")
# Three xpub pages with the same testing logic
for xpub_num in range(3):
expected_title = f"MULTISIG XPUB #{xpub_num + 1}"
layout = self.debug.swipe_left(wait=True)
assert expected_title in layout.title()
content = layout.text_content().replace(" ", "")
assert self.xpubs[xpub_num] in content
self.debug.click(buttons.CORNER_BUTTON, wait=True)
# show address
self.debug.press_no(wait=True)
# address mismatch
self.debug.press_no(wait=True)
# show address
self.debug.press_yes()
def input_flow_tr(self) -> BRGeneratorType:
yield # multisig address warning
self.debug.press_middle()
yield # show address
layout = self.debug.wait_layout()
TR.assert_in(layout.title(), "address__title_receive_address")
assert "(MULTISIG)" in layout.title()
assert layout.text_content().replace(" ", "") == self.address
self.debug.press_right()
assert "Qr" in self.all_components()
layout = self.debug.press_right(wait=True)
# address details
# TODO: locate it more precisely
assert "Multisig 2 of 3" in layout.json_str
# Three xpub pages with the same testing logic
for xpub_num in range(3):
expected_title = f"MULTISIG XPUB #{xpub_num + 1}"
layout = self.debug.press_right(wait=True)
assert expected_title in layout.title()
xpub_part_1 = layout.text_content().replace(" ", "")
# Press "SHOW MORE"
layout = self.debug.press_middle(wait=True)
xpub_part_2 = layout.text_content().replace(" ", "")
# Go back
self.debug.press_left(wait=True)
assert self.xpubs[xpub_num] == xpub_part_1 + xpub_part_2
for _ in range(5):
self.debug.press_left()
# show address
self.debug.press_left()
# address mismatch
self.debug.press_left()
# show address
self.debug.press_middle()
def input_flow_t3t1(self) -> BRGeneratorType:
yield # multisig address warning
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.synchronize_at("VerticalMenu")
self.debug.click(buttons.VERTICAL_MENU[1])
yield # show address
layout = self.debug.wait_layout()
TR.assert_in(layout.title(), "address__title_receive_address")
assert layout.text_content().replace(" ", "") == self.address
self.debug.click(buttons.CORNER_BUTTON, wait=True)
assert "VerticalMenu" in self.all_components()
# menu
self.debug.click(buttons.VERTICAL_MENU[0], wait=True)
self.debug.synchronize_at("Qr")
# qr code
assert "Qr" in self.all_components()
self.debug.click(buttons.CORNER_BUTTON, wait=True)
# menu
assert "VerticalMenu" in self.all_components()
self.debug.click(buttons.VERTICAL_MENU[1], wait=True)
layout = self.debug.synchronize_at("AddressDetails")
# address details
assert "Multisig 2 of 3" in layout.screen_content()
TR.assert_in(layout.screen_content(), "address_details__derivation_path")
# three xpub pages with the same testing logic
for _xpub_num in range(3):
layout = self.debug.swipe_left(wait=True)
layout = self.debug.swipe_left(wait=True)
self.debug.click(buttons.CORNER_BUTTON, wait=True)
layout = self.debug.synchronize_at("VerticalMenu")
# menu
self.debug.click(buttons.VERTICAL_MENU[2], wait=True)
# cancel
self.debug.swipe_up(wait=True)
# really cancel
self.debug.click(buttons.CORNER_BUTTON, wait=True)
layout = self.debug.synchronize_at("VerticalMenu")
# menu
self.debug.click(buttons.CORNER_BUTTON, wait=True)
layout = self.debug.synchronize_at("Paragraphs")
# address
while "PromptScreen" not in layout.all_components():
layout = self.debug.swipe_up(wait=True)
self.debug.synchronize_at("PromptScreen")
# tap to confirm
self.debug.press_yes()
class InputFlowShowXpubQRCode(InputFlowBase):
def __init__(self, client: Client, passphrase: bool = False):
super().__init__(client)
self.passphrase = passphrase
def input_flow_tt(self) -> BRGeneratorType:
if self.passphrase:
yield
self.debug.press_yes()
yield
self.debug.press_yes()
br = yield
layout = self.debug.wait_layout()
if "coinjoin" in layout.title().lower() or br.code == B.UnknownDerivationPath:
self.debug.press_yes()
br = yield
self.debug.click(buttons.CORNER_BUTTON, wait=True)
# synchronize; TODO get rid of this once we have single-global-layout
self.debug.synchronize_at("SimplePage")
self.debug.swipe_left(wait=True)
self.debug.swipe_right(wait=True)
self.debug.swipe_left(wait=True)
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.press_no(wait=True)
self.debug.press_no(wait=True)
for _ in range(br.pages - 1):
self.debug.swipe_up(wait=True)
self.debug.press_yes()
def input_flow_tr(self) -> BRGeneratorType:
if self.passphrase:
yield
self.debug.press_right()
yield
self.debug.press_right()
br = yield
layout = self.debug.wait_layout()
if "coinjoin" in layout.title().lower() or br.code == B.UnknownDerivationPath:
self.debug.press_yes()
br = yield
# Go into details
self.debug.press_right(wait=True)
# Go through details and back
self.debug.press_right(wait=True)
self.debug.press_right(wait=True)
self.debug.press_right(wait=True)
self.debug.press_left(wait=True)
self.debug.press_left(wait=True)
assert br.pages is not None
for _ in range(br.pages - 1):
self.debug.press_right()
# Confirm
self.debug.press_middle()
def input_flow_t3t1(self) -> BRGeneratorType:
if self.passphrase:
yield
self.debug.press_yes()
yield
self.debug.press_yes()
br = yield
layout = self.debug.wait_layout()
if "coinjoin" in layout.title().lower() or br.code == B.UnknownDerivationPath:
self.debug.press_yes()
br = yield
layout = self.debug.wait_layout()
assert layout.title() in TR.translate("address__public_key") + ["XPUB"]
self.debug.click(buttons.CORNER_BUTTON, wait=True)
assert "VerticalMenu" in self.all_components()
# menu
self.debug.click(buttons.VERTICAL_MENU[0], wait=True)
self.debug.synchronize_at("Qr")
# qr code
assert "Qr" in self.all_components()
self.debug.click(buttons.CORNER_BUTTON, wait=True)
# menu
assert "VerticalMenu" in self.all_components()
self.debug.click(buttons.VERTICAL_MENU[1], wait=True)
layout = self.debug.synchronize_at("AddressDetails")
# address details
TR.assert_in(layout.screen_content(), "address_details__derivation_path")
self.debug.click(buttons.CORNER_BUTTON, wait=True)
layout = self.debug.synchronize_at("VerticalMenu")
# menu
self.debug.click(buttons.VERTICAL_MENU[2], wait=True)
# cancel
self.debug.swipe_up(wait=True)
# really cancel
self.debug.click(buttons.CORNER_BUTTON, wait=True)
layout = self.debug.synchronize_at("VerticalMenu")
# menu
self.debug.click(buttons.CORNER_BUTTON, wait=True)
layout = self.debug.synchronize_at("Paragraphs")
# address
while "PromptScreen" not in layout.all_components():
layout = self.debug.swipe_up(wait=True)
self.debug.synchronize_at("PromptScreen")
# tap to confirm
self.debug.press_yes()
class InputFlowPaymentRequestDetails(InputFlowBase):
def __init__(self, client: Client, outputs: list[messages.TxOutputType]):
super().__init__(client)
self.outputs = outputs
def input_flow_tt(self) -> BRGeneratorType:
yield # request to see details
self.debug.wait_layout()
self.debug.press_info()
yield # confirm first output
assert self.outputs[0].address[:16] in self.text_content() # type: ignore
self.debug.press_yes()
yield # confirm first output
self.debug.wait_layout()
self.debug.press_yes()
yield # confirm second output
assert self.outputs[1].address[:16] in self.text_content() # type: ignore
self.debug.press_yes()
yield # confirm second output
self.debug.wait_layout()
self.debug.press_yes()
yield # confirm transaction
self.debug.press_yes()
yield # confirm transaction
self.debug.press_yes()
def input_flow_t3t1(self) -> BRGeneratorType:
yield # request to see details
self.debug.wait_layout()
self.debug.press_info()
yield # confirm first output
assert self.outputs[0].address[:16] in self.text_content() # type: ignore
self.debug.swipe_up()
yield # confirm first output
self.debug.wait_layout()
self.debug.swipe_up()
yield # confirm second output
assert self.outputs[1].address[:16] in self.text_content() # type: ignore
self.debug.swipe_up()
yield # confirm second output
self.debug.wait_layout()
self.debug.swipe_up()
yield # confirm transaction
self.debug.swipe_up()
self.debug.press_yes()
class InputFlowSignTxHighFee(InputFlowBase):
def __init__(self, client: Client):
super().__init__(client)
self.finished = False
def go_through_all_screens(self, screens: list[B]) -> BRGeneratorType:
for expected in screens:
br = yield
assert br.code == expected
self.debug.press_yes()
self.finished = True
def input_flow_tt(self) -> BRGeneratorType:
screens = [
B.ConfirmOutput,
B.ConfirmOutput,
B.FeeOverThreshold,
B.SignTx,
]
yield from self.go_through_all_screens(screens)
def input_flow_tr(self) -> BRGeneratorType:
screens = [
B.ConfirmOutput,
B.ConfirmOutput,
B.FeeOverThreshold,
B.SignTx,
]
yield from self.go_through_all_screens(screens)
def input_flow_t3t1(self) -> BRGeneratorType:
screens = [
B.ConfirmOutput,
B.ConfirmOutput,
B.FeeOverThreshold,
B.SignTx,
]
for expected in screens:
br = yield
assert br.code == expected
self.debug.swipe_up()
if br.code == B.SignTx:
self.debug.press_yes()
self.finished = True
def sign_tx_go_to_info(client: Client) -> Generator[None, None, str]:
yield # confirm output
client.debug.wait_layout()
client.debug.press_yes()
yield # confirm output
client.debug.wait_layout()
client.debug.press_yes()
yield # confirm transaction
client.debug.wait_layout()
client.debug.press_info()
layout = client.debug.wait_layout()
content = layout.text_content()
client.debug.click(buttons.CORNER_BUTTON, wait=True)
return content
def sign_tx_go_to_info_t3t1(
client: Client, multi_account: bool = False
) -> Generator[None, None, str]:
yield # confirm output
client.debug.wait_layout()
client.debug.swipe_up()
yield # confirm output
client.debug.wait_layout()
client.debug.swipe_up()
if multi_account:
yield
client.debug.wait_layout()
client.debug.swipe_up()
yield # confirm transaction
client.debug.wait_layout()
client.debug.click(buttons.CORNER_BUTTON)
client.debug.synchronize_at("VerticalMenu")
client.debug.click(buttons.VERTICAL_MENU[0])
layout = client.debug.wait_layout()
content = layout.text_content()
client.debug.click(buttons.CORNER_BUTTON)
client.debug.synchronize_at("VerticalMenu")
client.debug.click(buttons.VERTICAL_MENU[1])
layout = client.debug.wait_layout()
content += " " + layout.text_content()
client.debug.click(buttons.CORNER_BUTTON)
client.debug.click(buttons.CORNER_BUTTON, wait=True)
return content
def sign_tx_go_to_info_tr(
client: Client,
) -> Generator[None, None, str]:
yield # confirm address
client.debug.wait_layout()
client.debug.press_yes() # CONTINUE
yield # confirm amount
client.debug.wait_layout()
client.debug.press_yes() # CONFIRM
screen_texts: list[str] = []
yield # confirm total
layout = client.debug.wait_layout()
if "multiple accounts" in layout.text_content().lower():
client.debug.press_middle()
yield
layout = client.debug.press_right(wait=True)
screen_texts.append(layout.text_content())
layout = client.debug.press_right(wait=True)
screen_texts.append(layout.text_content())
client.debug.press_left()
client.debug.press_left()
return "\n".join(screen_texts)
class InputFlowSignTxInformation(InputFlowBase):
def __init__(self, client: Client):
super().__init__(client)
def assert_content(self, content: str, title_path: str) -> None:
TR.assert_in(content, title_path)
assert "Legacy #6" in content
TR.assert_in(content, "confirm_total__fee_rate")
assert "71.56 sat" in content
def input_flow_tt(self) -> BRGeneratorType:
content = yield from sign_tx_go_to_info(self.client)
self.assert_content(content, "confirm_total__sending_from_account")
self.debug.press_yes()
def input_flow_tr(self) -> BRGeneratorType:
content = yield from sign_tx_go_to_info_tr(self.client)
print("content", content)
self.assert_content(content, "confirm_total__title_sending_from")
self.debug.press_yes()
def input_flow_t3t1(self) -> BRGeneratorType:
content = yield from sign_tx_go_to_info_t3t1(self.client)
self.assert_content(content, "confirm_total__sending_from_account")
self.debug.swipe_up()
self.debug.press_yes()
class InputFlowSignTxInformationMixed(InputFlowBase):
def __init__(self, client: Client):
super().__init__(client)
def assert_content(self, content: str, title_path: str) -> None:
TR.assert_in(content, title_path)
TR.assert_in(content, "bitcoin__multiple_accounts")
TR.assert_in(content, "confirm_total__fee_rate")
assert "18.33 sat" in content
def input_flow_tt(self) -> BRGeneratorType:
# multiple accounts warning
yield
self.debug.press_yes()
content = yield from sign_tx_go_to_info(self.client)
self.assert_content(content, "confirm_total__sending_from_account")
self.debug.press_yes()
def input_flow_tr(self) -> BRGeneratorType:
# multiple accounts warning
yield
self.debug.press_yes()
content = yield from sign_tx_go_to_info_tr(self.client)
self.assert_content(content, "confirm_total__title_sending_from")
self.debug.press_yes()
def input_flow_t3t1(self) -> BRGeneratorType:
content = yield from sign_tx_go_to_info_t3t1(self.client, multi_account=True)
self.assert_content(content, "confirm_total__sending_from_account")
self.debug.swipe_up()
self.debug.press_yes()
class InputFlowSignTxInformationCancel(InputFlowBase):
def __init__(self, client: Client):
super().__init__(client)
def input_flow_tt(self) -> BRGeneratorType:
yield from sign_tx_go_to_info(self.client)
self.debug.press_no()
def input_flow_tr(self) -> BRGeneratorType:
yield from sign_tx_go_to_info_tr(self.client)
self.debug.press_left()
def input_flow_t3t1(self) -> BRGeneratorType:
yield from sign_tx_go_to_info_t3t1(self.client)
self.debug.click(buttons.CORNER_BUTTON)
self.debug.click(buttons.VERTICAL_MENU[2])
self.debug.synchronize_at("PromptScreen")
self.debug.click(buttons.TAP_TO_CONFIRM)
class InputFlowSignTxInformationReplacement(InputFlowBase):
def __init__(self, client: Client):
super().__init__(client)
def input_flow_tt(self) -> BRGeneratorType:
yield # confirm txid
self.debug.press_yes()
yield # confirm address
self.debug.press_yes()
# go back to address
self.debug.press_no()
# confirm address
self.debug.press_yes()
yield # confirm amount
self.debug.press_yes()
yield # transaction summary, press info
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.click(buttons.CORNER_BUTTON, wait=True)
self.debug.press_yes()
def input_flow_tr(self) -> BRGeneratorType:
yield # confirm txid
self.debug.press_right()
self.debug.press_right()
yield # confirm address
self.debug.press_right()
self.debug.press_right()
self.debug.press_right()
yield # confirm amount
self.debug.press_right()
self.debug.press_right()
self.debug.press_right()
yield
def input_flow_t3t1(self) -> BRGeneratorType:
yield # confirm txid
self.debug.press_yes()
yield # confirm address
self.debug.press_yes()
# go back to address
self.debug.press_no()
# confirm address
self.debug.press_yes()
yield # confirm amount
self.debug.press_yes()
yield # transaction summary, press info
self.debug.click(buttons.CORNER_BUTTON, wait=True)