diff --git a/common/protob/messages-debug.proto b/common/protob/messages-debug.proto index b308a1f4fd..d660360c24 100644 --- a/common/protob/messages-debug.proto +++ b/common/protob/messages-debug.proto @@ -14,8 +14,17 @@ import "messages-common.proto"; */ message DebugLinkDecision { optional bool yes_no = 1; // true for "Confirm", false for "Cancel" - optional bool up_down = 2; // true for scroll up, false for scroll down + optional DebugSwipeDirection swipe = 2; // swipe direction optional string input = 3; // keyboard input + /** + * Structure representing swipe direction + */ + enum DebugSwipeDirection { + UP = 0; + DOWN = 1; + LEFT = 2; + RIGHT = 3; + } } /** diff --git a/core/src/apps/debug/__init__.py b/core/src/apps/debug/__init__.py index 84bd2faaf1..b0b1aa4769 100644 --- a/core/src/apps/debug/__init__.py +++ b/core/src/apps/debug/__init__.py @@ -5,7 +5,7 @@ if not __debug__: if __debug__: from trezor import config, log, loop, utils - from trezor.messages import MessageType + from trezor.messages import MessageType, DebugSwipeDirection from trezor.wire import register if False: @@ -33,15 +33,19 @@ if __debug__: while True: msg = await debuglink_decision_chan.take() - if msg.yes_no is not None: await confirm_chan.put( confirm.CONFIRMED if msg.yes_no else confirm.CANCELLED ) - if msg.up_down is not None: - await swipe_chan.put( - swipe.SWIPE_DOWN if msg.up_down else swipe.SWIPE_UP - ) + if msg.swipe is not None: + if msg.swipe == DebugSwipeDirection.UP: + await swipe_chan.put(swipe.SWIPE_UP) + elif msg.swipe == DebugSwipeDirection.DOWN: + await swipe_chan.put(swipe.SWIPE_DOWN) + elif msg.swipe == DebugSwipeDirection.LEFT: + await swipe_chan.put(swipe.SWIPE_LEFT) + elif msg.swipe == DebugSwipeDirection.RIGHT: + await swipe_chan.put(swipe.SWIPE_RIGHT) if msg.input is not None: await input_chan.put(msg.input) diff --git a/core/src/trezor/messages/DebugLinkDecision.py b/core/src/trezor/messages/DebugLinkDecision.py index 3ee43101ff..0f7a09a943 100644 --- a/core/src/trezor/messages/DebugLinkDecision.py +++ b/core/src/trezor/messages/DebugLinkDecision.py @@ -6,8 +6,10 @@ if __debug__: try: from typing import Dict, List, Optional from typing_extensions import Literal # noqa: F401 + EnumTypeDebugSwipeDirection = Literal[0, 1, 2, 3] except ImportError: Dict, List, Optional = None, None, None # type: ignore + EnumTypeDebugSwipeDirection = None # type: ignore class DebugLinkDecision(p.MessageType): @@ -16,17 +18,17 @@ class DebugLinkDecision(p.MessageType): def __init__( self, yes_no: bool = None, - up_down: bool = None, + swipe: EnumTypeDebugSwipeDirection = None, input: str = None, ) -> None: self.yes_no = yes_no - self.up_down = up_down + self.swipe = swipe self.input = input @classmethod def get_fields(cls) -> Dict: return { 1: ('yes_no', p.BoolType, 0), - 2: ('up_down', p.BoolType, 0), + 2: ('swipe', p.EnumType("DebugSwipeDirection", (0, 1, 2, 3)), 0), 3: ('input', p.UnicodeType, 0), } diff --git a/core/src/trezor/messages/DebugSwipeDirection.py b/core/src/trezor/messages/DebugSwipeDirection.py new file mode 100644 index 0000000000..23d6f9f998 --- /dev/null +++ b/core/src/trezor/messages/DebugSwipeDirection.py @@ -0,0 +1,6 @@ +# Automatically generated by pb2py +# fmt: off +UP = 0 +DOWN = 1 +LEFT = 2 +RIGHT = 3 diff --git a/python/src/trezorlib/debuglink.py b/python/src/trezorlib/debuglink.py index ad3ab511b8..300256b983 100644 --- a/python/src/trezorlib/debuglink.py +++ b/python/src/trezorlib/debuglink.py @@ -91,7 +91,7 @@ class DebugLink: if args != 1: raise ValueError("Invalid input - must use one of word, button, swipe") - decision = proto.DebugLinkDecision(yes_no=button, up_down=swipe, input=word) + decision = proto.DebugLinkDecision(yes_no=button, swipe=swipe, input=word) self._call(decision, nowait=True) def press_yes(self): @@ -101,10 +101,16 @@ class DebugLink: self.input(button=False) def swipe_up(self): - self.input(swipe=True) + self.input(swipe=proto.DebugSwipeDirection.UP) def swipe_down(self): - self.input(swipe=False) + self.input(swipe=proto.DebugSwipeDirection.DOWN) + + def swipe_right(self): + self.input(swipe=proto.DebugSwipeDirection.RIGHT) + + def swipe_left(self): + self.input(swipe=proto.DebugSwipeDirection.LEFT) def stop(self): self._call(proto.DebugLinkStop(), nowait=True) diff --git a/python/src/trezorlib/messages/DebugLinkDecision.py b/python/src/trezorlib/messages/DebugLinkDecision.py index cf68770a1e..bd3e1a5e7d 100644 --- a/python/src/trezorlib/messages/DebugLinkDecision.py +++ b/python/src/trezorlib/messages/DebugLinkDecision.py @@ -6,8 +6,10 @@ if __debug__: try: from typing import Dict, List, Optional from typing_extensions import Literal # noqa: F401 + EnumTypeDebugSwipeDirection = Literal[0, 1, 2, 3] except ImportError: Dict, List, Optional = None, None, None # type: ignore + EnumTypeDebugSwipeDirection = None # type: ignore class DebugLinkDecision(p.MessageType): @@ -16,17 +18,17 @@ class DebugLinkDecision(p.MessageType): def __init__( self, yes_no: bool = None, - up_down: bool = None, + swipe: EnumTypeDebugSwipeDirection = None, input: str = None, ) -> None: self.yes_no = yes_no - self.up_down = up_down + self.swipe = swipe self.input = input @classmethod def get_fields(cls) -> Dict: return { 1: ('yes_no', p.BoolType, 0), - 2: ('up_down', p.BoolType, 0), + 2: ('swipe', p.EnumType("DebugSwipeDirection", (0, 1, 2, 3)), 0), 3: ('input', p.UnicodeType, 0), } diff --git a/python/src/trezorlib/messages/DebugSwipeDirection.py b/python/src/trezorlib/messages/DebugSwipeDirection.py new file mode 100644 index 0000000000..23d6f9f998 --- /dev/null +++ b/python/src/trezorlib/messages/DebugSwipeDirection.py @@ -0,0 +1,6 @@ +# Automatically generated by pb2py +# fmt: off +UP = 0 +DOWN = 1 +LEFT = 2 +RIGHT = 3 diff --git a/python/src/trezorlib/messages/__init__.py b/python/src/trezorlib/messages/__init__.py index 5864f401b4..85fa35eabb 100644 --- a/python/src/trezorlib/messages/__init__.py +++ b/python/src/trezorlib/messages/__init__.py @@ -262,6 +262,7 @@ from . import BinanceOrderType from . import BinanceTimeInForce from . import ButtonRequestType from . import Capability +from . import DebugSwipeDirection from . import FailureType from . import InputScriptType from . import LiskTransactionType diff --git a/tests/common.py b/tests/common.py index 55be4ad928..821d494fe7 100644 --- a/tests/common.py +++ b/tests/common.py @@ -149,7 +149,7 @@ def read_and_confirm_mnemonic(debug, words): while True: mnemonic.extend(debug.read_reset_word().split()) if len(mnemonic) < words: - debug.swipe_down() + debug.swipe_up() else: # last page is confirmation debug.press_yes() diff --git a/tests/device_tests/test_msg_cardano_sign_transaction.py b/tests/device_tests/test_msg_cardano_sign_transaction.py index 9909c8c4b1..a730c776e0 100644 --- a/tests/device_tests/test_msg_cardano_sign_transaction.py +++ b/tests/device_tests/test_msg_cardano_sign_transaction.py @@ -191,10 +191,10 @@ def test_cardano_sign_tx( def input_flow(): yield - client.debug.swipe_down() + client.debug.swipe_up() client.debug.press_yes() yield - client.debug.swipe_down() + client.debug.swipe_up() client.debug.press_yes() with client: diff --git a/tests/device_tests/test_msg_cardano_sign_tx_slip39_basic.py b/tests/device_tests/test_msg_cardano_sign_tx_slip39_basic.py index 5ba782ada0..79aca76bf5 100644 --- a/tests/device_tests/test_msg_cardano_sign_tx_slip39_basic.py +++ b/tests/device_tests/test_msg_cardano_sign_tx_slip39_basic.py @@ -134,10 +134,10 @@ def test_cardano_sign_tx( def input_flow(): yield - client.debug.swipe_down() + client.debug.swipe_up() client.debug.press_yes() yield - client.debug.swipe_down() + client.debug.swipe_up() client.debug.press_yes() client.set_passphrase("TREZOR") diff --git a/tests/device_tests/test_msg_eos_signtx.py b/tests/device_tests/test_msg_eos_signtx.py index 77f9a52897..b9b8340f10 100644 --- a/tests/device_tests/test_msg_eos_signtx.py +++ b/tests/device_tests/test_msg_eos_signtx.py @@ -40,7 +40,7 @@ class TestMsgEosSignTx: # swipe through pages yield for _ in range(pages - 1): - debug.swipe_down() + debug.swipe_up() # confirm last page debug.press_yes() @@ -654,14 +654,14 @@ class TestMsgEosSignTx: # swipe through new account yield for _ in range(5): - client.debug.swipe_down() + client.debug.swipe_up() # confirm new account client.debug.press_yes() # swipe through buyrambytes yield - client.debug.swipe_down() + client.debug.swipe_up() # confirm buyrambytes client.debug.press_yes() @@ -669,7 +669,7 @@ class TestMsgEosSignTx: # swipe through delegatebw yield for _ in range(2): - client.debug.swipe_down() + client.debug.swipe_up() # confirm delegatebw client.debug.press_yes() @@ -721,14 +721,14 @@ class TestMsgEosSignTx: # swipe through setcode yield - client.debug.swipe_down() + client.debug.swipe_up() # confirm setcode client.debug.press_yes() # swipe through setabi yield - client.debug.swipe_down() + client.debug.swipe_up() # confirm setabi client.debug.press_yes() diff --git a/tests/device_tests/test_msg_nem_signtx_mosaics_t2.py b/tests/device_tests/test_msg_nem_signtx_mosaics_t2.py index 3cc41d0831..55befcb519 100644 --- a/tests/device_tests/test_msg_nem_signtx_mosaics_t2.py +++ b/tests/device_tests/test_msg_nem_signtx_mosaics_t2.py @@ -174,7 +174,7 @@ class TestMsgNEMSignTxMosaics: # Swipe and confirm yield for _ in range(num_of_swipes): - client.debug.swipe_down() + client.debug.swipe_up() client.debug.press_yes() # Confirm Action diff --git a/tests/device_tests/test_msg_tezos_sign_tx.py b/tests/device_tests/test_msg_tezos_sign_tx.py index ce29fd6ee5..610986434a 100644 --- a/tests/device_tests/test_msg_tezos_sign_tx.py +++ b/tests/device_tests/test_msg_tezos_sign_tx.py @@ -190,7 +190,7 @@ class TestMsgTezosSignTx: def input_flow(self, debug, num_pages): yield for _ in range(num_pages - 1): - debug.swipe_down() + debug.swipe_up() debug.press_yes() def test_tezos_sign_tx_proposal(self, client):