1414# You should have received a copy of the License along with this library.
1515# If not, see <https://www.gnu.org/licenses/lgpl-3.0.html>.
1616
17- from itertools import combinations
17+ from itertools import combinations , product
1818
1919import pytest
2020from shamir_mnemonic import MnemonicError , shamir
2323from trezorlib .btc import get_public_node
2424from trezorlib .debuglink import DebugSession as Session
2525from trezorlib .exceptions import TrezorFailure
26- from trezorlib .messages import BackupAvailability , BackupType
26+ from trezorlib .messages import BackupAvailability , BackupMethod , BackupType
2727
28+ from . import check_support
2829from ...common import EXTERNAL_ENTROPY , MOCK_GET_ENTROPY , generate_entropy
2930from ...input_flows import (
3031 FlowAdapter ,
4041 try_to_cancel ({"backup_device" , "setup_device" , "success_backup" }),
4142]
4243
44+ METHODS = [
45+ BackupMethod .Display ,
46+ BackupMethod .N4W1 ,
47+ ]
48+
49+
50+ def reset_device (
51+ session : Session , strength : int , adapt_flow : FlowAdapter , method : BackupMethod
52+ ):
53+ check_support (session , method )
4354
44- def reset_device (session : Session , strength : int , adapt_flow : FlowAdapter ):
4555 member_threshold = 3
4656
4757 with session .test_ctx as client :
48- IF = InputFlowSlip39BasicResetRecovery (session )
58+ IF = InputFlowSlip39BasicResetRecovery (session , method )
4959 client .set_input_flow (adapt_flow (session , IF .get ()))
5060
5161 # No PIN, no passphrase, don't display random
@@ -56,6 +66,7 @@ def reset_device(session: Session, strength: int, adapt_flow: FlowAdapter):
5666 pin_protection = False ,
5767 label = "test" ,
5868 backup_type = BackupType .Slip39_Basic ,
69+ backup_method = method ,
5970 entropy_check_count = 0 ,
6071 _get_entropy = MOCK_GET_ENTROPY ,
6172 )
@@ -80,27 +91,41 @@ def reset_device(session: Session, strength: int, adapt_flow: FlowAdapter):
8091 device .backup (session )
8192
8293
94+ TEST_PARAMS = [
95+ pytest .param (adapt_flow , method , id = f"{ adapt_flow .__name__ } -{ method .name } " )
96+ for adapt_flow , method in product (FLOW_ADAPTERS , METHODS )
97+ ]
98+
99+
83100@pytest .mark .setup_client (uninitialized = True )
84- @pytest .mark .parametrize ("adapt_flow" , FLOW_ADAPTERS , ids = lambda f : f .__name__ )
85- def test_reset_device_slip39_basic (session : Session , adapt_flow : FlowAdapter ):
86- reset_device (session , 128 , adapt_flow )
101+ @pytest .mark .parametrize ("adapt_flow,method" , TEST_PARAMS )
102+ def test_reset_device_slip39_basic (
103+ session : Session , adapt_flow : FlowAdapter , method : BackupMethod
104+ ):
105+ reset_device (session , 128 , adapt_flow , method = method )
87106
88107
89- @pytest .mark .parametrize ("adapt_flow" , FLOW_ADAPTERS , ids = lambda f : f . __name__ )
108+ @pytest .mark .parametrize ("adapt_flow,method " , TEST_PARAMS )
90109@pytest .mark .setup_client (uninitialized = True )
91- def test_reset_device_slip39_basic_256 (session : Session , adapt_flow : FlowAdapter ):
92- reset_device (session , 256 , adapt_flow )
110+ def test_reset_device_slip39_basic_256 (
111+ session : Session , adapt_flow : FlowAdapter , method : BackupMethod
112+ ):
113+ reset_device (session , 256 , adapt_flow , method = method )
93114
94115
95116@pytest .mark .setup_client (uninitialized = True )
96- @pytest .mark .parametrize ("adapt_flow" , FLOW_ADAPTERS , ids = lambda f : f .__name__ )
97- def test_reset_entropy_check (session : Session , adapt_flow : FlowAdapter ):
117+ @pytest .mark .parametrize ("adapt_flow,method" , TEST_PARAMS )
118+ def test_reset_entropy_check (
119+ session : Session , adapt_flow : FlowAdapter , method : BackupMethod
120+ ):
121+ check_support (session , method )
122+
98123 member_threshold = 3
99124
100125 strength = 128 # 20 words
101126
102127 with session .test_ctx as client :
103- IF = InputFlowSlip39BasicResetRecovery (session )
128+ IF = InputFlowSlip39BasicResetRecovery (session , method )
104129 client .set_input_flow (adapt_flow (session , IF .get ()))
105130
106131 # No PIN, no passphrase.
@@ -111,6 +136,7 @@ def test_reset_entropy_check(session: Session, adapt_flow: FlowAdapter):
111136 pin_protection = False ,
112137 label = "test" ,
113138 backup_type = BackupType .Slip39_Basic ,
139+ backup_method = method ,
114140 entropy_check_count = 3 ,
115141 _get_entropy = MOCK_GET_ENTROPY ,
116142 )
0 commit comments