Skip to content

Commit 3d3a27e

Browse files
committed
test: add tests for Stackbit 1248 vertical input
1 parent 3ce0241 commit 3d3a27e

2 files changed

Lines changed: 113 additions & 10 deletions

File tree

tests/pages/test_login.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,8 @@ def test_load_12w_from_1248(m5stickv, mocker, mocker_printer):
13961396
from krux.input import BUTTON_ENTER, BUTTON_PAGE, BUTTON_PAGE_PREV
13971397

13981398
BTN_SEQUENCE = (
1399-
(
1399+
[BUTTON_ENTER] # Select "Standard" from Standard/Vertical submenu
1400+
+ (
14001401
[BUTTON_ENTER] # 1 press select first column num 1
14011402
+ [BUTTON_PAGE_PREV] # 1 press to change to "Go"
14021403
+ [BUTTON_ENTER] # 1 press to select Go

tests/pages/test_stackbit.py

Lines changed: 111 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,7 @@ def test_export_mnemonic_stackbit_standard_amigo(mocker, amigo, tdata):
7272

7373

7474
def test_export_mnemonic_stackbit_vertical(mocker, amigo, tdata):
75-
"""Grouped layout on Amigo: 2 words/group, 4 words/page, 6 pages for 24-word mnemonic.
76-
77-
Amigo uses FONT_WIDTH=12, so 3 words/group would overflow the word name text.
78-
The layout auto-selects 2 words/group → 4 words/page → 6 pages.
79-
"""
75+
"""Grouped layout on Amigo: 2 words/group, 4 words/page, 6 pages for 24-word mnemonic."""
8076
from krux.pages.home_pages.mnemonic_backup import MnemonicsView
8177
from krux.wallet import Wallet
8278
from krux.input import BUTTON_ENTER, BUTTON_PAGE
@@ -113,10 +109,7 @@ def test_export_mnemonic_stackbit_vertical(mocker, amigo, tdata):
113109

114110

115111
def test_export_mnemonic_stackbit_vertical_compact(mocker, m5stickv, tdata):
116-
"""Dense layout on M5StickV: 6 words per page, 4 pages for 24-word mnemonic.
117-
118-
2 words side-by-side × 3 rows, no word names or BIP39 codes.
119-
"""
112+
"""Dense layout on M5StickV: 6 words per page, 4 pages for 24-word mnemonic."""
120113
from krux.pages.home_pages.mnemonic_backup import MnemonicsView
121114
from krux.wallet import Wallet
122115
from krux.input import BUTTON_ENTER, BUTTON_PAGE
@@ -236,6 +229,115 @@ def test_esc_entering_stackbit(amigo, mocker):
236229
assert words == None
237230

238231

232+
def test_load_key_from_1248_standard(m5stickv, mocker):
233+
"""Selecting Standard in the 1248 submenu calls _load_key_from_1248_standard."""
234+
from krux.pages.mnemonic_loader import MnemonicLoader
235+
from krux.pages import MENU_CONTINUE
236+
from krux.input import BUTTON_ENTER, BUTTON_PAGE
237+
238+
BTN_SEQUENCE = [
239+
BUTTON_ENTER, # Select "Standard"
240+
# _load_key_from_1248_standard is patched, returns immediately
241+
*([BUTTON_PAGE] * 2), # Go to "Back" in submenu
242+
BUTTON_ENTER, # Select "Back"
243+
]
244+
ctx = create_ctx(mocker, BTN_SEQUENCE)
245+
loader = MnemonicLoader(ctx)
246+
mocker.patch.object(
247+
loader, "_load_key_from_1248_standard", return_value=MENU_CONTINUE
248+
)
249+
mocker.spy(loader, "_load_key_from_1248_vertical")
250+
loader.load_key_from_1248()
251+
252+
loader._load_key_from_1248_standard.assert_called_once()
253+
loader._load_key_from_1248_vertical.assert_not_called()
254+
assert ctx.input.wait_for_button.call_count == len(BTN_SEQUENCE)
255+
256+
257+
def test_load_key_from_1248_vertical(m5stickv, mocker):
258+
"""Selecting Vertical in the 1248 submenu calls _load_key_from_1248_vertical."""
259+
from krux.pages.mnemonic_loader import MnemonicLoader
260+
from krux.pages import MENU_CONTINUE
261+
from krux.input import BUTTON_ENTER, BUTTON_PAGE
262+
263+
BTN_SEQUENCE = [
264+
BUTTON_PAGE, # Go to "Vertical"
265+
BUTTON_ENTER, # Select "Vertical"
266+
# _load_key_from_1248_vertical is patched, returns immediately
267+
BUTTON_PAGE, # Go to "Back" in submenu
268+
BUTTON_ENTER, # Select "Back"
269+
]
270+
ctx = create_ctx(mocker, BTN_SEQUENCE)
271+
loader = MnemonicLoader(ctx)
272+
mocker.patch.object(
273+
loader, "_load_key_from_1248_vertical", return_value=MENU_CONTINUE
274+
)
275+
mocker.spy(loader, "_load_key_from_1248_standard")
276+
loader.load_key_from_1248()
277+
278+
loader._load_key_from_1248_vertical.assert_called_once()
279+
loader._load_key_from_1248_standard.assert_not_called()
280+
assert ctx.input.wait_for_button.call_count == len(BTN_SEQUENCE)
281+
282+
283+
def test_enter_stackbit_vertical(m5stickv, mocker):
284+
"""Button navigation: enter 12 'language' words on a vertical 1248 grid."""
285+
from krux.pages.stack_1248 import Stackbit
286+
from krux.input import BUTTON_ENTER, BUTTON_PAGE_PREV
287+
288+
BTN_SEQUENCE = (
289+
# Toggle bit-weight 1, jump to Go, confirm word
290+
[BUTTON_ENTER, BUTTON_PAGE_PREV, BUTTON_ENTER, BUTTON_ENTER] * 11
291+
# 12th word: same plus confirm "Done?"
292+
+ [BUTTON_ENTER, BUTTON_PAGE_PREV, BUTTON_ENTER, BUTTON_ENTER, BUTTON_ENTER]
293+
)
294+
TEST_12_WORDS = "language language language language language language language language language language language language"
295+
296+
ctx = create_ctx(mocker, BTN_SEQUENCE)
297+
stackbit = Stackbit(ctx)
298+
words = stackbit.enter_1248_vertical()
299+
300+
assert ctx.input.wait_for_button.call_count == len(BTN_SEQUENCE)
301+
assert " ".join(words) == TEST_12_WORDS
302+
303+
304+
def test_enter_stackbit_vertical_touch(amigo, mocker):
305+
"""Touch navigation: enter 12 'language' words via touch screen."""
306+
from krux.pages.stack_1248 import Stackbit, VERT_GO_INDEX
307+
from krux.input import BUTTON_TOUCH
308+
309+
YES = 1
310+
BTN_SEQUENCE = [BUTTON_TOUCH] * 3 * 12 + [BUTTON_TOUCH]
311+
TOUCH_SEQUENCE = [0, VERT_GO_INDEX, YES] * 12 + [YES]
312+
TEST_12_WORDS = "language language language language language language language language language language language language"
313+
314+
ctx = create_ctx(mocker, BTN_SEQUENCE, touch_seq=TOUCH_SEQUENCE)
315+
stackbit = Stackbit(ctx)
316+
words = stackbit.enter_1248_vertical()
317+
318+
assert ctx.input.wait_for_button.call_count == len(BTN_SEQUENCE)
319+
assert " ".join(words) == TEST_12_WORDS
320+
321+
322+
def test_esc_entering_stackbit_vertical(amigo, mocker):
323+
"""Pressing Esc from the vertical input grid returns None."""
324+
from krux.pages.stack_1248 import Stackbit
325+
from krux.input import BUTTON_ENTER, BUTTON_PAGE_PREV
326+
327+
BTN_SEQUENCE = (
328+
# Move to Esc
329+
[BUTTON_PAGE_PREV] * 3
330+
+ [BUTTON_ENTER] # Select "Esc"
331+
+ [BUTTON_ENTER] # Confirm
332+
)
333+
ctx = create_ctx(mocker, BTN_SEQUENCE)
334+
stackbit = Stackbit(ctx)
335+
words = stackbit.enter_1248_vertical()
336+
337+
assert ctx.input.wait_for_button.call_count == len(BTN_SEQUENCE)
338+
assert words is None
339+
340+
239341
def test_entering_stackbit_buttons_turbo(mocker, m5stickv):
240342
from krux.pages.stack_1248 import Stackbit
241343
from krux.input import PRESSED, FAST_FORWARD, FAST_BACKWARD, Input

0 commit comments

Comments
 (0)