diff --git a/tests/buttons.py b/tests/buttons.py index 4b45b069f6..ee759d23ef 100644 --- a/tests/buttons.py +++ b/tests/buttons.py @@ -125,9 +125,6 @@ def ui_no(layout_type: LayoutType) -> Coords: def reset_minus(layout_type: LayoutType) -> Coords: if layout_type is LayoutType.Bolt: return (left(layout_type), grid(display_height(layout_type), 5, 1)) - elif layout_type is LayoutType.Caesar: - # TODO temporary workaround to make the 'set_selection' function work - return (left(layout_type), grid(display_height(layout_type), 5, 1)) elif layout_type is LayoutType.Delizia: return (left(layout_type), grid(display_height(layout_type), 5, 3)) else: @@ -137,9 +134,6 @@ def reset_minus(layout_type: LayoutType) -> Coords: def reset_plus(layout_type: LayoutType) -> Coords: if layout_type is LayoutType.Bolt: return (right(layout_type), grid(display_height(layout_type), 5, 1)) - elif layout_type is LayoutType.Caesar: - # TODO temporary workaround to make the 'set_selection' function work - return (right(layout_type), grid(display_height(layout_type), 5, 1)) elif layout_type is LayoutType.Delizia: return (right(layout_type), grid(display_height(layout_type), 5, 3)) else: diff --git a/tests/click_tests/reset.py b/tests/click_tests/reset.py index b6e3337f83..6b2aec7b54 100644 --- a/tests/click_tests/reset.py +++ b/tests/click_tests/reset.py @@ -63,9 +63,17 @@ def cancel_backup( debug.press_left() -def set_selection(debug: "DebugLink", button: tuple[int, int], diff: int) -> None: +def set_selection(debug: "DebugLink", diff: int) -> None: if debug.layout_type in (LayoutType.Bolt, LayoutType.Delizia): assert "NumberInputDialog" in debug.read_layout().all_components() + + button = ( + buttons.reset_minus(debug.layout_type) + if diff < 0 + else buttons.reset_plus(debug.layout_type) + ) + diff = abs(diff) + for _ in range(diff): debug.click(button) if debug.layout_type is LayoutType.Bolt: @@ -82,8 +90,8 @@ def set_selection(debug: "DebugLink", button: tuple[int, int], diff: int) -> Non debug.press_right() layout = debug.read_layout() assert "NumberInput" in layout.all_components() - if button == buttons.reset_minus(debug.layout_type): - for _ in range(diff): + if diff < 0: + for _ in range(abs(diff)): debug.press_left() else: for _ in range(diff): diff --git a/tests/click_tests/test_repeated_backup.py b/tests/click_tests/test_repeated_backup.py index 9305bc8ed0..3e0ca6946c 100644 --- a/tests/click_tests/test_repeated_backup.py +++ b/tests/click_tests/test_repeated_backup.py @@ -20,7 +20,6 @@ import pytest from trezorlib import device, exceptions, messages -from .. import buttons from ..common import MOCK_GET_ENTROPY from . import recovery, reset from .common import go_next @@ -63,11 +62,11 @@ def test_repeated_backup( # confirm checklist reset.confirm_read(debug) # shares=1 - reset.set_selection(debug, buttons.reset_minus(debug.layout_type), 5 - 1) + reset.set_selection(debug, 1 - 5) # confirm checklist reset.confirm_read(debug) # threshold=1 - reset.set_selection(debug, buttons.reset_plus(debug.layout_type), 0) + reset.set_selection(debug, 0) # confirm checklist reset.confirm_read(debug) # confirm backup warning @@ -129,11 +128,11 @@ def test_repeated_backup( # confirm checklist reset.confirm_read(debug) # shares=3 - reset.set_selection(debug, buttons.reset_minus(debug.layout_type), 5 - 3) + reset.set_selection(debug, 3 - 5) # confirm checklist reset.confirm_read(debug) # threshold=2 - reset.set_selection(debug, buttons.reset_minus(debug.layout_type), 1) + reset.set_selection(debug, 2 - 3) # confirm checklist reset.confirm_read(debug) # confirm backup warning diff --git a/tests/click_tests/test_reset_slip39_advanced.py b/tests/click_tests/test_reset_slip39_advanced.py index f46a277682..42798661ed 100644 --- a/tests/click_tests/test_reset_slip39_advanced.py +++ b/tests/click_tests/test_reset_slip39_advanced.py @@ -20,7 +20,6 @@ import pytest from trezorlib import device, messages -from .. import buttons from ..common import EXTERNAL_ENTROPY, MOCK_GET_ENTROPY, generate_entropy from . import reset @@ -81,14 +80,7 @@ def test_reset_slip39_advanced( reset.confirm_read(debug) # set num of groups - default is 5 - if group_count < 5: - reset.set_selection( - debug, buttons.reset_minus(debug.layout_type), 5 - group_count - ) - else: - reset.set_selection( - debug, buttons.reset_plus(debug.layout_type), group_count - 5 - ) + reset.set_selection(debug, group_count - 5) # confirm checklist # TR.assert_in_multiple( @@ -104,9 +96,9 @@ def test_reset_slip39_advanced( # set group threshold # TODO: could make it general as well if group_count == 2 and group_threshold == 2: - reset.set_selection(debug, buttons.reset_plus(debug.layout_type), 0) + reset.set_selection(debug, 0) elif group_count == 16 and group_threshold == 16: - reset.set_selection(debug, buttons.reset_plus(debug.layout_type), 11) + reset.set_selection(debug, 11) else: raise RuntimeError("not a supported combination") @@ -123,21 +115,14 @@ def test_reset_slip39_advanced( # set share num and threshold for groups for _ in range(group_count): # set num of shares - default is 5 - if share_count < 5: - reset.set_selection( - debug, buttons.reset_minus(debug.layout_type), 5 - share_count - ) - else: - reset.set_selection( - debug, buttons.reset_plus(debug.layout_type), share_count - 5 - ) + reset.set_selection(debug, share_count - 5) # set share threshold # TODO: could make it general as well if share_count == 2 and share_threshold == 2: - reset.set_selection(debug, buttons.reset_plus(debug.layout_type), 0) + reset.set_selection(debug, 0) elif share_count == 16 and share_threshold == 16: - reset.set_selection(debug, buttons.reset_plus(debug.layout_type), 11) + reset.set_selection(debug, 11) else: raise RuntimeError("not a supported combination") diff --git a/tests/click_tests/test_reset_slip39_basic.py b/tests/click_tests/test_reset_slip39_basic.py index 9d17798932..4ddfdd7e12 100644 --- a/tests/click_tests/test_reset_slip39_basic.py +++ b/tests/click_tests/test_reset_slip39_basic.py @@ -20,7 +20,6 @@ import pytest from trezorlib import device, messages -from .. import buttons from ..common import EXTERNAL_ENTROPY, MOCK_GET_ENTROPY, generate_entropy from . import reset @@ -79,14 +78,7 @@ def test_reset_slip39_basic( reset.confirm_read(debug) # set num of shares - default is 5 - if num_of_shares < 5: - reset.set_selection( - debug, buttons.reset_minus(debug.layout_type), 5 - num_of_shares - ) - else: - reset.set_selection( - debug, buttons.reset_plus(debug.layout_type), num_of_shares - 5 - ) + reset.set_selection(debug, num_of_shares - 5) # confirm checklist # TR.assert_in( @@ -97,9 +89,9 @@ def test_reset_slip39_basic( # set threshold # TODO: could make it general as well if num_of_shares == 1 and threshold == 1: - reset.set_selection(debug, buttons.reset_plus(debug.layout_type), 0) + reset.set_selection(debug, 0) elif num_of_shares == 16 and threshold == 16: - reset.set_selection(debug, buttons.reset_plus(debug.layout_type), 11) + reset.set_selection(debug, 11) else: raise RuntimeError("not a supported combination")