1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-01-03 12:00:59 +00:00

chore(core): add test for Slip39_Single

[no changelog]
This commit is contained in:
Ioan Bizău 2024-12-06 10:57:56 +01:00 committed by Ioan Bizău
parent 7eb0b4d689
commit ad06a54d76
3 changed files with 40 additions and 9 deletions

View File

@ -195,7 +195,7 @@ def click_through(
def read_and_confirm_mnemonic(
debug: "DebugLink", choose_wrong: bool = False
) -> Generator[None, "ButtonRequest", Optional[str]]:
"""Read a given number of mnemonic words from the screen and answer
"""Read mnemonic words from the screen and answer
confirmation questions.
Return the full mnemonic or None if `choose_wrong` is True.

View File

@ -27,6 +27,7 @@ from ..common import (
MNEMONIC12,
MNEMONIC_SLIP39_ADVANCED_20,
MNEMONIC_SLIP39_CUSTOM_SECRET,
MNEMONIC_SLIP39_SINGLE_EXT_20,
MNEMONIC_SLIP39_BASIC_20_3of6,
MNEMONIC_SLIP39_CUSTOM_1of1,
)
@ -89,6 +90,32 @@ def test_backup_slip39_basic(client: Client, click_info: bool):
assert expected_ms == actual_ms
@pytest.mark.models("core")
@pytest.mark.setup_client(needs_backup=True, mnemonic=MNEMONIC_SLIP39_SINGLE_EXT_20)
def test_backup_slip39_single(client: Client):
assert client.features.backup_availability == messages.BackupAvailability.Required
with client:
IF = InputFlowBip39Backup(
client, confirm_success=(client.layout_type is not LayoutType.Mercury)
)
client.set_input_flow(IF.get())
device.backup(client)
client.init_device()
assert client.features.initialized is True
assert (
client.features.backup_availability == messages.BackupAvailability.NotAvailable
)
assert client.features.unfinished_backup is False
assert client.features.no_backup is False
assert client.features.backup_type is messages.BackupType.Slip39_Single_Extendable
assert shamir.combine_mnemonics([IF.mnemonic]) == shamir.combine_mnemonics(
MNEMONIC_SLIP39_SINGLE_EXT_20
)
@pytest.mark.models("core")
@pytest.mark.setup_client(needs_backup=True, mnemonic=MNEMONIC_SLIP39_ADVANCED_20)
@pytest.mark.parametrize(

View File

@ -1216,8 +1216,9 @@ class InputFlowEthereumSignTxStaking(InputFlowBase):
yield from self.ETH.confirm_tx_staking(info=True)
def get_mnemonic_and_confirm_success(
def get_mnemonic(
debug: DebugLink,
confirm_success: bool = True,
) -> Generator[None, "messages.ButtonRequest", str]:
# mnemonic phrases
mnemonic = yield from read_and_confirm_mnemonic(debug)
@ -1228,8 +1229,10 @@ def get_mnemonic_and_confirm_success(
assert br.code == B.Success
debug.press_yes()
br = yield # confirm success
assert br.code == B.Success
if confirm_success:
br = yield
assert br.code == B.Success
debug.press_yes()
assert mnemonic is not None
@ -1237,9 +1240,10 @@ def get_mnemonic_and_confirm_success(
class InputFlowBip39Backup(InputFlowBase):
def __init__(self, client: Client):
def __init__(self, client: Client, confirm_success: bool = True):
super().__init__(client)
self.mnemonic = None
self.confirm_success = confirm_success
def input_flow_common(self) -> BRGeneratorType:
# 1. Backup intro
@ -1247,7 +1251,7 @@ class InputFlowBip39Backup(InputFlowBase):
yield from click_through(self.debug, screens=2, code=B.ResetDevice)
# mnemonic phrases and rest
self.mnemonic = yield from get_mnemonic_and_confirm_success(self.debug)
self.mnemonic = yield from get_mnemonic(self.debug, self.confirm_success)
class InputFlowBip39ResetBackup(InputFlowBase):
@ -1264,7 +1268,7 @@ class InputFlowBip39ResetBackup(InputFlowBase):
yield from click_through(self.debug, screens=4, code=B.ResetDevice)
# mnemonic phrases and rest
self.mnemonic = yield from get_mnemonic_and_confirm_success(self.debug)
self.mnemonic = yield from get_mnemonic(self.debug)
def input_flow_tr(self) -> BRGeneratorType:
# 1. Confirm Reset
@ -1274,7 +1278,7 @@ class InputFlowBip39ResetBackup(InputFlowBase):
yield from click_through(self.debug, screens=4, code=B.ResetDevice)
# mnemonic phrases and rest
self.mnemonic = yield from get_mnemonic_and_confirm_success(self.debug)
self.mnemonic = yield from get_mnemonic(self.debug)
def input_flow_t3t1(self) -> BRGeneratorType:
# 1. Confirm Reset
@ -1285,7 +1289,7 @@ class InputFlowBip39ResetBackup(InputFlowBase):
yield from click_through(self.debug, screens=5, code=B.ResetDevice)
# mnemonic phrases and rest
self.mnemonic = yield from get_mnemonic_and_confirm_success(self.debug)
self.mnemonic = yield from get_mnemonic(self.debug)
class InputFlowBip39ResetPIN(InputFlowBase):