@@ -168,3 +168,50 @@ pub async fn from_mnemonic(
168
168
unlock:: unlock_bip39 ( hal) . await ;
169
169
Ok ( Response :: Success ( pb:: Success { } ) )
170
170
}
171
+
172
+ #[ cfg( test) ]
173
+ mod tests {
174
+ use super :: * ;
175
+
176
+ use crate :: bb02_async:: block_on;
177
+ use crate :: hal:: testing:: TestingHal ;
178
+ use bitbox02:: testing:: mock_memory;
179
+ use bitbox02:: { keystore, memory} ;
180
+
181
+ use alloc:: boxed:: Box ;
182
+
183
+ #[ test]
184
+ fn test_from_mnemonic ( ) {
185
+ mock_memory ( ) ;
186
+ keystore:: lock ( ) ;
187
+ let mut counter = 0u32 ;
188
+ let mut mock_hal = TestingHal :: new ( ) ;
189
+ mock_hal. ui . set_enter_string ( Box :: new ( |params| {
190
+ counter += 1 ;
191
+ match counter {
192
+ 1 => assert_eq ! ( params. title, "Set password" ) ,
193
+ 2 => assert_eq ! ( params. title, "Repeat password" ) ,
194
+ _ => panic ! ( "too many user inputs" ) ,
195
+ }
196
+ Ok ( "password" . into ( ) )
197
+ } ) ) ;
198
+
199
+ bitbox02:: securechip:: fake_event_counter_reset ( ) ;
200
+ assert_eq ! (
201
+ block_on( from_mnemonic(
202
+ & mut mock_hal,
203
+ & pb:: RestoreFromMnemonicRequest {
204
+ timestamp: 0 ,
205
+ timezone_offset: 0 ,
206
+ }
207
+ ) ) ,
208
+ Ok ( Response :: Success ( pb:: Success { } ) )
209
+ ) ;
210
+ assert_eq ! ( bitbox02:: securechip:: fake_event_counter( ) , 19 ) ;
211
+ drop ( mock_hal) ; // to remove mutable borrow of counter
212
+ assert_eq ! ( counter, 2 ) ;
213
+ assert ! ( !keystore:: is_locked( ) ) ;
214
+ assert ! ( memory:: is_initialized( ) ) ;
215
+ assert ! ( keystore:: copy_seed( ) . unwrap( ) . len( ) == 32 ) ;
216
+ }
217
+ }
0 commit comments