Skip to content

Commit 540b6fe

Browse files
Buttons turbo tests + CHANGELOG (#710)
1 parent a1fe42e commit 540b6fe

File tree

5 files changed

+169
-6
lines changed

5 files changed

+169
-6
lines changed

CHANGELOG.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ SHA-256 and PBKDF2-HMAC now use hardware-accelerated hashing, doubling the speed
2222
We added support for BIP45 (Legacy multisig `P2SH`) and complete BIP48 (Nested-Segwit `P2SH-P2WSH`).
2323

2424
### Button Turbo
25-
Hold the NEXT or PREVIOUS button to move faster through menus and more keypads.
25+
Hold the NEXT or PREVIOUS button to move faster through menus and other keypads (Tinyseed, Stackbit, Mnemonic Editor, Show Datum).
2626

2727
### 'New Mnemonic' Menu Disabled with 'Hide Mnemonic'
2828
When 'Hide Mnemonic' setting is enabled, the 'New Mnemonic' menu is automatically disabled.
@@ -40,21 +40,21 @@ To facilitate comparison, addresses are displayed in space-separated groups of 4
4040
Export *receive or change* addresses to a CSV file on the SD card.
4141

4242
### New CNC Printer Support and Fixes (OpenBuilds GRBL 1.1)
43-
- Fixed CNC/FilePrinter compatibility with optimized QR codes from v24.0.3.0;
44-
- Introduced CNC/GRBLPrinter for direct serial printing to CNC machines;
45-
- Added support to choose between router/laser head engravers.
43+
- Fixed CNC/FilePrinter compatibility with optimized QR codes from v24.0.3.0
44+
- Introduced CNC/GRBLPrinter for direct serial printing to CNC machines
45+
- Added support to choose between router/laser head engravers
4646

4747
### Export QR Codes as SVG
4848
Exported QR codes can now be saved as SVG images.
4949

5050
### Improved Tests
51-
- Code coverage: 10,000+ lines (96%) with 682 tests, improving stability and reliability
51+
- Code coverage: 10,000+ lines (96%) with 680+ tests, improving stability and reliability
5252
- Added in-device tests focusing on hardware-accelerated features in Tools
5353

5454
### Other Bug Fixes and Improvements
5555
- Numbers are no longer printed as words in "Backup Mnemonic > Other formats > Numbers"
5656
- Expanded keypad touch area to screen edges
57-
- "Tools > Print Test QR" now asks for confirmation before printing
57+
- Tools > Print Test QR now asks for confirmation before printing
5858
- Tools > Check SD Card now allows deleting files
5959
- Load mnemonic > Via Manual Input > Word Numbers now shows the double mnemonic indicator (*) if applicable
6060
- Added fingerprint to mnemonic preview and editor
@@ -74,6 +74,7 @@ Exported QR codes can now be saved as SVG images.
7474
- Added confirmation prompt before exiting after showing signed PSBT QR code
7575
- Sign message now supports all binary file types
7676
- Change Addresses menu hidden when descriptor cannot provide them
77+
- List Addresses now allows swiping up or down to navigate to move between pages
7778
- Hide Mnemonic now skips confirmation when loading via word numbers
7879
- Text improvements for clarity and easier translation
7980
- Fixed mixed ASCII/Asian fonts not using full display width

tests/pages/test_menu.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,92 @@ def _click(i="a", seq=None):
219219
assert index == menu.back_index
220220
assert status == MENU_EXIT
221221
assert ctx.input.wait_for_button.call_count == len(BTN_SEQUENCE)
222+
223+
224+
def test_fast_forward(mocker, m5stickv):
225+
from krux.input import PRESSED, FAST_FORWARD, FAST_BACKWARD
226+
from krux.pages import Menu
227+
228+
ctx = mock_context(mocker)
229+
ctx.input.page_value = mocker.MagicMock(return_value=PRESSED)
230+
menu = Menu(ctx, [])
231+
232+
assert menu._get_btn_input() == FAST_FORWARD
233+
234+
ctx.input.page_value = mocker.MagicMock(return_value=None)
235+
236+
ctx.input.page_prev_value = mocker.MagicMock(return_value=PRESSED)
237+
238+
assert menu._get_btn_input() == FAST_BACKWARD
239+
240+
241+
def test_swipe_up(mocker, amigo):
242+
from krux.pages import Menu, MENU_EXIT, MENU_CONTINUE
243+
from krux.input import SWIPE_UP
244+
245+
ctx = mock_context(mocker)
246+
menu = Menu(ctx, [])
247+
248+
def swipe_fnc():
249+
return (1, MENU_EXIT)
250+
251+
assert menu._process_swipe_up(0, swipe_up_fnc=swipe_fnc) == (1, MENU_EXIT)
252+
assert menu._process_swipe_down(0, swipe_down_fnc=swipe_fnc) == (1, MENU_EXIT)
253+
254+
BTN_SEQUENCE = [
255+
SWIPE_UP,
256+
]
257+
ctx.input.wait_for_button.side_effect = BTN_SEQUENCE
258+
index, status = menu.run_loop(swipe_up_fnc=swipe_fnc)
259+
assert index == 1
260+
assert status == MENU_EXIT
261+
262+
def swipe_fnc_continue():
263+
return (2, MENU_CONTINUE)
264+
265+
assert menu._process_swipe_up(0, swipe_up_fnc=swipe_fnc_continue) == 0
266+
assert menu._process_swipe_down(0, swipe_down_fnc=swipe_fnc_continue) == 0
267+
268+
269+
def test_start_from(mocker, m5stickv):
270+
from krux.pages import Menu, MENU_EXIT, MENU_CONTINUE
271+
from krux.input import BUTTON_ENTER, BUTTON_PAGE_PREV
272+
273+
ctx = mock_context(mocker)
274+
275+
mock_fnc = mocker.MagicMock(return_value=MENU_CONTINUE)
276+
menu_items = [
277+
("1", mock_fnc),
278+
("2", lambda: MENU_EXIT),
279+
]
280+
menu = Menu(ctx, menu_items)
281+
# test start menu clicking on index 1 that will exit
282+
index, status = menu.run_loop(start_from_index=1)
283+
assert index == 1
284+
assert status == MENU_EXIT
285+
286+
# test start menu clicking on index 0 that will NOT exit
287+
BTN_SEQUENCE = [BUTTON_PAGE_PREV] + [BUTTON_ENTER] # go to back # click back
288+
ctx.input.wait_for_button.side_effect = BTN_SEQUENCE
289+
index, status = menu.run_loop(start_from_index=0)
290+
assert index == menu.back_index
291+
assert status == MENU_EXIT
292+
mock_fnc.assert_called()
293+
assert ctx.input.wait_for_button.call_count == len(BTN_SEQUENCE)
294+
295+
296+
def test_disabled_entry(mocker, m5stickv):
297+
from krux.pages import Menu, MENU_EXIT
298+
from krux.input import BUTTON_ENTER, BUTTON_PAGE
299+
300+
ctx = mock_context(mocker)
301+
menu_items = [("Disabled", None)]
302+
BTN_SEQUENCE = (
303+
[BUTTON_ENTER] + [BUTTON_PAGE] + [BUTTON_ENTER] # click disabled # click back
304+
)
305+
ctx.input.wait_for_button.side_effect = BTN_SEQUENCE
306+
menu = Menu(ctx, menu_items)
307+
index, status = menu.run_loop()
308+
assert index == menu.back_index
309+
assert status == MENU_EXIT
310+
assert ctx.input.wait_for_button.call_count == len(BTN_SEQUENCE)

tests/pages/test_mnemonic_editor.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,43 @@ def test_loop_through_words(mocker, cube):
4141
assert ctx.input.wait_for_button.call_count == len(btn_sequence)
4242

4343

44+
def test_button_turbo(mocker, m5stickv):
45+
from krux.pages.mnemonic_editor import MnemonicEditor
46+
from krux.input import PRESSED
47+
import pytest
48+
49+
ctx = create_ctx(mocker, [])
50+
mnemonic_editor = MnemonicEditor(ctx, TEST_12_WORD_MNEMONIC)
51+
mnemonic_editor._map_words = mocker.MagicMock(
52+
side_effect=[True, ValueError, True, ValueError]
53+
)
54+
55+
# fast forward
56+
ctx.input.page_value = mocker.MagicMock(return_value=PRESSED)
57+
with pytest.raises(ValueError):
58+
edited_mnemonic = mnemonic_editor.edit()
59+
60+
mnemonic_editor._map_words.assert_has_calls(
61+
[
62+
mocker.call(25, 0),
63+
mocker.call(0, 0),
64+
]
65+
)
66+
67+
# fast backward
68+
ctx.input.page_value = mocker.MagicMock(return_value=None)
69+
ctx.input.page_prev_value = mocker.MagicMock(return_value=PRESSED)
70+
with pytest.raises(ValueError):
71+
edited_mnemonic = mnemonic_editor.edit()
72+
73+
mnemonic_editor._map_words.assert_has_calls(
74+
[
75+
mocker.call(25, 0),
76+
mocker.call(24, 0),
77+
]
78+
)
79+
80+
4481
def test_edit_new_mnemonic_using_buttons(mocker, cube):
4582
from krux.pages.mnemonic_editor import MnemonicEditor
4683
from krux.input import BUTTON_ENTER, BUTTON_PAGE, BUTTON_PAGE_PREV

tests/pages/test_tiny_seed.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,31 @@ def test_enter_tiny_seed_12w_m5stickv(m5stickv, mocker):
9494
assert " ".join(words) == TEST_12_WORDS
9595

9696

97+
def test_enter_tiny_seed_button_turbo(mocker, m5stickv):
98+
from krux.pages.tiny_seed import TinySeed
99+
from krux.input import PRESSED, FAST_FORWARD, FAST_BACKWARD
100+
import pytest
101+
102+
ctx = create_ctx(mocker, [])
103+
tiny_seed = TinySeed(ctx)
104+
105+
# fast forward
106+
ctx.input.page_value = mocker.MagicMock(return_value=PRESSED)
107+
tiny_seed._new_index = mocker.MagicMock(side_effect=ValueError)
108+
with pytest.raises(ValueError):
109+
tiny_seed.enter_tiny_seed()
110+
111+
tiny_seed._new_index.assert_called_with(0, FAST_FORWARD, False, 0)
112+
113+
# fast backward
114+
ctx.input.page_value = mocker.MagicMock(return_value=None)
115+
ctx.input.page_prev_value = mocker.MagicMock(return_value=PRESSED)
116+
with pytest.raises(ValueError):
117+
tiny_seed.enter_tiny_seed()
118+
119+
tiny_seed._new_index.assert_called_with(0, FAST_BACKWARD, False, 0)
120+
121+
97122
def test_enter_tiny_seed_24w_m5stickv(m5stickv, mocker):
98123
from krux.pages.tiny_seed import TinySeed
99124
from krux.input import BUTTON_ENTER, BUTTON_PAGE, BUTTON_PAGE_PREV

tests/test_input.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,3 +932,14 @@ def test_touch_damaged(mocker, amigo):
932932

933933
# Should return False since touch is damaged, sowy!
934934
assert not input.touch_event()
935+
936+
937+
def test_amigo_fast_forward_from_start(mocker, amigo):
938+
from krux.input import Input, BUTTON_PAGE, ACTIVATING_BUTTONS
939+
940+
mocker.patch("time.ticks_ms", return_value=10)
941+
942+
input = Input()
943+
# input.page_value = lambda: PRESSED
944+
value = input._detect_press_type(BUTTON_PAGE)
945+
assert value == ACTIVATING_BUTTONS

0 commit comments

Comments
 (0)