Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for Slip39_Single #4425

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def input_flow():
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.

Expand Down
27 changes: 27 additions & 0 deletions tests/device_tests/test_msg_backup_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
MNEMONIC12,
MNEMONIC_SLIP39_ADVANCED_20,
MNEMONIC_SLIP39_CUSTOM_SECRET,
MNEMONIC_SLIP39_SINGLE_EXT_20,
MNEMONIC_SLIP39_BASIC_20_3of6,
MNEMONIC_SLIP39_CUSTOM_1of1,
)
Expand Down Expand Up @@ -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(
Expand Down
20 changes: 12 additions & 8 deletions tests/input_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -1216,8 +1216,9 @@ def input_flow_common(self) -> BRGeneratorType:
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)
Expand All @@ -1228,26 +1229,29 @@ 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
return mnemonic


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
# 2. Backup warning
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):
Expand All @@ -1264,7 +1268,7 @@ def input_flow_tt(self) -> BRGeneratorType:
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
Expand All @@ -1274,7 +1278,7 @@ def input_flow_tr(self) -> BRGeneratorType:
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
Expand All @@ -1285,7 +1289,7 @@ def input_flow_t3t1(self) -> BRGeneratorType:
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):
Expand Down
Loading
Loading