mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-06 18:26:11 +00:00
refactor(tests): refactor reset set selection function
This commit is contained in:
parent
ea142bbdba
commit
0ebb6612b0
@ -125,9 +125,6 @@ def ui_no(layout_type: LayoutType) -> Coords:
|
|||||||
def reset_minus(layout_type: LayoutType) -> Coords:
|
def reset_minus(layout_type: LayoutType) -> Coords:
|
||||||
if layout_type is LayoutType.Bolt:
|
if layout_type is LayoutType.Bolt:
|
||||||
return (left(layout_type), grid(display_height(layout_type), 5, 1))
|
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:
|
elif layout_type is LayoutType.Delizia:
|
||||||
return (left(layout_type), grid(display_height(layout_type), 5, 3))
|
return (left(layout_type), grid(display_height(layout_type), 5, 3))
|
||||||
else:
|
else:
|
||||||
@ -137,9 +134,6 @@ def reset_minus(layout_type: LayoutType) -> Coords:
|
|||||||
def reset_plus(layout_type: LayoutType) -> Coords:
|
def reset_plus(layout_type: LayoutType) -> Coords:
|
||||||
if layout_type is LayoutType.Bolt:
|
if layout_type is LayoutType.Bolt:
|
||||||
return (right(layout_type), grid(display_height(layout_type), 5, 1))
|
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:
|
elif layout_type is LayoutType.Delizia:
|
||||||
return (right(layout_type), grid(display_height(layout_type), 5, 3))
|
return (right(layout_type), grid(display_height(layout_type), 5, 3))
|
||||||
else:
|
else:
|
||||||
|
@ -63,9 +63,17 @@ def cancel_backup(
|
|||||||
debug.press_left()
|
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):
|
if debug.layout_type in (LayoutType.Bolt, LayoutType.Delizia):
|
||||||
assert "NumberInputDialog" in debug.read_layout().all_components()
|
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):
|
for _ in range(diff):
|
||||||
debug.click(button)
|
debug.click(button)
|
||||||
if debug.layout_type is LayoutType.Bolt:
|
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()
|
debug.press_right()
|
||||||
layout = debug.read_layout()
|
layout = debug.read_layout()
|
||||||
assert "NumberInput" in layout.all_components()
|
assert "NumberInput" in layout.all_components()
|
||||||
if button == buttons.reset_minus(debug.layout_type):
|
if diff < 0:
|
||||||
for _ in range(diff):
|
for _ in range(abs(diff)):
|
||||||
debug.press_left()
|
debug.press_left()
|
||||||
else:
|
else:
|
||||||
for _ in range(diff):
|
for _ in range(diff):
|
||||||
|
@ -20,7 +20,6 @@ import pytest
|
|||||||
|
|
||||||
from trezorlib import device, exceptions, messages
|
from trezorlib import device, exceptions, messages
|
||||||
|
|
||||||
from .. import buttons
|
|
||||||
from ..common import MOCK_GET_ENTROPY
|
from ..common import MOCK_GET_ENTROPY
|
||||||
from . import recovery, reset
|
from . import recovery, reset
|
||||||
from .common import go_next
|
from .common import go_next
|
||||||
@ -63,11 +62,11 @@ def test_repeated_backup(
|
|||||||
# confirm checklist
|
# confirm checklist
|
||||||
reset.confirm_read(debug)
|
reset.confirm_read(debug)
|
||||||
# shares=1
|
# shares=1
|
||||||
reset.set_selection(debug, buttons.reset_minus(debug.layout_type), 5 - 1)
|
reset.set_selection(debug, 1 - 5)
|
||||||
# confirm checklist
|
# confirm checklist
|
||||||
reset.confirm_read(debug)
|
reset.confirm_read(debug)
|
||||||
# threshold=1
|
# threshold=1
|
||||||
reset.set_selection(debug, buttons.reset_plus(debug.layout_type), 0)
|
reset.set_selection(debug, 0)
|
||||||
# confirm checklist
|
# confirm checklist
|
||||||
reset.confirm_read(debug)
|
reset.confirm_read(debug)
|
||||||
# confirm backup warning
|
# confirm backup warning
|
||||||
@ -129,11 +128,11 @@ def test_repeated_backup(
|
|||||||
# confirm checklist
|
# confirm checklist
|
||||||
reset.confirm_read(debug)
|
reset.confirm_read(debug)
|
||||||
# shares=3
|
# shares=3
|
||||||
reset.set_selection(debug, buttons.reset_minus(debug.layout_type), 5 - 3)
|
reset.set_selection(debug, 3 - 5)
|
||||||
# confirm checklist
|
# confirm checklist
|
||||||
reset.confirm_read(debug)
|
reset.confirm_read(debug)
|
||||||
# threshold=2
|
# threshold=2
|
||||||
reset.set_selection(debug, buttons.reset_minus(debug.layout_type), 1)
|
reset.set_selection(debug, 2 - 3)
|
||||||
# confirm checklist
|
# confirm checklist
|
||||||
reset.confirm_read(debug)
|
reset.confirm_read(debug)
|
||||||
# confirm backup warning
|
# confirm backup warning
|
||||||
|
@ -20,7 +20,6 @@ import pytest
|
|||||||
|
|
||||||
from trezorlib import device, messages
|
from trezorlib import device, messages
|
||||||
|
|
||||||
from .. import buttons
|
|
||||||
from ..common import EXTERNAL_ENTROPY, MOCK_GET_ENTROPY, generate_entropy
|
from ..common import EXTERNAL_ENTROPY, MOCK_GET_ENTROPY, generate_entropy
|
||||||
from . import reset
|
from . import reset
|
||||||
|
|
||||||
@ -81,14 +80,7 @@ def test_reset_slip39_advanced(
|
|||||||
reset.confirm_read(debug)
|
reset.confirm_read(debug)
|
||||||
|
|
||||||
# set num of groups - default is 5
|
# set num of groups - default is 5
|
||||||
if group_count < 5:
|
reset.set_selection(debug, 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
|
|
||||||
)
|
|
||||||
|
|
||||||
# confirm checklist
|
# confirm checklist
|
||||||
# TR.assert_in_multiple(
|
# TR.assert_in_multiple(
|
||||||
@ -104,9 +96,9 @@ def test_reset_slip39_advanced(
|
|||||||
# set group threshold
|
# set group threshold
|
||||||
# TODO: could make it general as well
|
# TODO: could make it general as well
|
||||||
if group_count == 2 and group_threshold == 2:
|
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:
|
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:
|
else:
|
||||||
raise RuntimeError("not a supported combination")
|
raise RuntimeError("not a supported combination")
|
||||||
|
|
||||||
@ -123,21 +115,14 @@ def test_reset_slip39_advanced(
|
|||||||
# set share num and threshold for groups
|
# set share num and threshold for groups
|
||||||
for _ in range(group_count):
|
for _ in range(group_count):
|
||||||
# set num of shares - default is 5
|
# set num of shares - default is 5
|
||||||
if share_count < 5:
|
reset.set_selection(debug, 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
|
|
||||||
)
|
|
||||||
|
|
||||||
# set share threshold
|
# set share threshold
|
||||||
# TODO: could make it general as well
|
# TODO: could make it general as well
|
||||||
if share_count == 2 and share_threshold == 2:
|
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:
|
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:
|
else:
|
||||||
raise RuntimeError("not a supported combination")
|
raise RuntimeError("not a supported combination")
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ import pytest
|
|||||||
|
|
||||||
from trezorlib import device, messages
|
from trezorlib import device, messages
|
||||||
|
|
||||||
from .. import buttons
|
|
||||||
from ..common import EXTERNAL_ENTROPY, MOCK_GET_ENTROPY, generate_entropy
|
from ..common import EXTERNAL_ENTROPY, MOCK_GET_ENTROPY, generate_entropy
|
||||||
from . import reset
|
from . import reset
|
||||||
|
|
||||||
@ -79,14 +78,7 @@ def test_reset_slip39_basic(
|
|||||||
reset.confirm_read(debug)
|
reset.confirm_read(debug)
|
||||||
|
|
||||||
# set num of shares - default is 5
|
# set num of shares - default is 5
|
||||||
if num_of_shares < 5:
|
reset.set_selection(debug, 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
|
|
||||||
)
|
|
||||||
|
|
||||||
# confirm checklist
|
# confirm checklist
|
||||||
# TR.assert_in(
|
# TR.assert_in(
|
||||||
@ -97,9 +89,9 @@ def test_reset_slip39_basic(
|
|||||||
# set threshold
|
# set threshold
|
||||||
# TODO: could make it general as well
|
# TODO: could make it general as well
|
||||||
if num_of_shares == 1 and threshold == 1:
|
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:
|
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:
|
else:
|
||||||
raise RuntimeError("not a supported combination")
|
raise RuntimeError("not a supported combination")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user