Skip to content

Commit

Permalink
sorted stored mnemonics - adapt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
odudex committed Dec 10, 2024
1 parent 9b3bc70 commit aaaa067
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions tests/pages/test_encryption_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def test_load_encrypted_from_flash(m5stickv, mocker):
from krux.input import BUTTON_ENTER, BUTTON_PAGE
from krux.pages.encryption_ui import LoadEncryptedMnemonic

BTN_SEQUENCE = [BUTTON_ENTER] # First mnemonic
BTN_SEQUENCE = [BUTTON_PAGE, BUTTON_ENTER] # Second mnemonic
mocker.patch(
"krux.pages.encryption_ui.EncryptionKey.encryption_key",
mocker.MagicMock(return_value=TEST_KEY),
Expand All @@ -245,7 +245,7 @@ def test_load_encrypted_from_sd(m5stickv, mocker, mock_file_operations):
from krux.input import BUTTON_ENTER, BUTTON_PAGE
from krux.pages.encryption_ui import LoadEncryptedMnemonic

BTN_SEQUENCE = [BUTTON_ENTER] # First mnemonic
BTN_SEQUENCE = [BUTTON_PAGE, BUTTON_ENTER] # Second mnemonic
mocker.patch(
"krux.pages.encryption_ui.EncryptionKey.encryption_key",
mocker.MagicMock(return_value=TEST_KEY),
Expand Down
12 changes: 7 additions & 5 deletions tests/pages/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ def test_tools_menu(m5stickv, mocker):

def test_delete_mnemonic_from_flash(m5stickv, mocker):
from krux.pages.tools import Tools
from krux.input import BUTTON_ENTER, BUTTON_PAGE_PREV
from krux.input import BUTTON_ENTER, BUTTON_PAGE, BUTTON_PAGE_PREV

BTN_SEQUENCE = [
BUTTON_PAGE, # Move to 2th mnemonic
BUTTON_ENTER, # Select first mnemonic
BUTTON_ENTER, # Confirm deletion
BUTTON_ENTER, # Read remove message
Expand All @@ -61,7 +62,7 @@ def test_delete_mnemonic_from_flash(m5stickv, mocker):
with patch("krux.encryption.open", new=mocker.mock_open(read_data=SEEDS_JSON)) as m:
tool = Tools(ctx)
tool.rm_stored_mnemonic()
# First mnemonic in the list (ECB) will be deleted
# Second mnemonic in the list (ECB) will be deleted
# Assert only CBC remains
m().write.assert_called_once_with(CBC_ONLY_JSON)
assert ctx.input.wait_for_button.call_count == len(BTN_SEQUENCE)
Expand Down Expand Up @@ -110,9 +111,10 @@ def test_delete_mnemonic_from_sd(m5stickv, mocker, mock_file_operations):
# File reading mock operations will mock 4 mnemonics, 2 from flash, 2 from SD card

BTN_SEQUENCE = [
BUTTON_PAGE, # Move to 3rd mnemonic (first listed from SD card)
BUTTON_PAGE, # Move to 4th mnemonic (second listed from SD card)
BUTTON_PAGE,
BUTTON_ENTER, # Select first mnemonic
BUTTON_PAGE,
BUTTON_ENTER, # Select second mnemonic from SD - ECB
BUTTON_ENTER, # Confirm deletion
BUTTON_ENTER, # Read remove message
BUTTON_PAGE_PREV, # Go to Back
Expand All @@ -123,7 +125,7 @@ def test_delete_mnemonic_from_sd(m5stickv, mocker, mock_file_operations):
with patch("krux.sd_card.open", new=mocker.mock_open(read_data=SEEDS_JSON)) as m:
tool = Tools(ctx)
tool.rm_stored_mnemonic()
# First mnemonic in the list (ECB) will be deleted
# Fourth mnemonic in the list (ECB from SD) will be deleted
# Assert only CBC remains
padding_size = len(SEEDS_JSON) - len(CBC_ONLY_JSON)
m().write.assert_called_once_with(CBC_ONLY_JSON + " " * padding_size)
Expand Down

0 comments on commit aaaa067

Please sign in to comment.