@@ -179,6 +179,7 @@ mod tests {
179
179
180
180
let mut mock_hal = TestingHal :: new ( ) ;
181
181
mock_hal. sd . inserted = Some ( true ) ;
182
+ bitbox02:: securechip:: fake_event_counter_reset ( ) ;
182
183
assert_eq ! (
183
184
block_on( create(
184
185
& mut mock_hal,
@@ -189,6 +190,7 @@ mod tests {
189
190
) ) ,
190
191
Ok ( Response :: Success ( pb:: Success { } ) )
191
192
) ;
193
+ assert_eq ! ( bitbox02:: securechip:: fake_event_counter( ) , 1 ) ;
192
194
assert_eq ! ( EXPECTED_TIMESTMAP , bitbox02:: memory:: get_seed_birthdate( ) ) ;
193
195
assert_eq ! (
194
196
mock_hal. ui. screens,
@@ -216,6 +218,68 @@ mod tests {
216
218
) ;
217
219
}
218
220
221
+ /// Test backup creation on a initialized keystore. The sdcard does not contain the backup yet.
222
+ #[ test]
223
+ pub fn test_create_initialized_new ( ) {
224
+ const TIMESTMAP : u32 = 1601281809 ;
225
+
226
+ mock_memory ( ) ;
227
+
228
+ let seed = hex:: decode ( "cb33c20cea62a5c277527e2002da82e6e2b37450a755143a540a54cea8da9044" )
229
+ . unwrap ( ) ;
230
+ bitbox02:: keystore:: encrypt_and_store_seed ( & seed, "password" ) . unwrap ( ) ;
231
+ bitbox02:: memory:: set_initialized ( ) . unwrap ( ) ;
232
+
233
+ let mut password_entered: bool = false ;
234
+
235
+ let mut mock_hal = TestingHal :: new ( ) ;
236
+ mock_hal. sd . inserted = Some ( true ) ;
237
+ mock_hal. ui . set_enter_string ( Box :: new ( |_params| {
238
+ password_entered = true ;
239
+ Ok ( "password" . into ( ) )
240
+ } ) ) ;
241
+ bitbox02:: securechip:: fake_event_counter_reset ( ) ;
242
+ assert_eq ! (
243
+ block_on( create(
244
+ & mut mock_hal,
245
+ & pb:: CreateBackupRequest {
246
+ timestamp: TIMESTMAP ,
247
+ timezone_offset: 18000 ,
248
+ }
249
+ ) ) ,
250
+ Ok ( Response :: Success ( pb:: Success { } ) )
251
+ ) ;
252
+ assert_eq ! ( bitbox02:: securechip:: fake_event_counter( ) , 6 ) ;
253
+ assert_eq ! (
254
+ mock_hal. ui. screens,
255
+ vec![
256
+ Screen :: Confirm {
257
+ title: "Is today?" . into( ) ,
258
+ body: "Mon 2020-09-28" . into( ) ,
259
+ longtouch: false
260
+ } ,
261
+ Screen :: Status {
262
+ title: "Backup created" . into( ) ,
263
+ success: true
264
+ }
265
+ ]
266
+ ) ;
267
+
268
+ mock_hal. ui . remove_enter_string ( ) ; // no more password entry needed
269
+ assert_eq ! (
270
+ block_on( check(
271
+ & mut mock_hal,
272
+ & pb:: CheckBackupRequest { silent: true }
273
+ ) ) ,
274
+ Ok ( Response :: CheckBackup ( pb:: CheckBackupResponse {
275
+ id: backup:: id( & seed) ,
276
+ } ) )
277
+ ) ;
278
+
279
+ drop ( mock_hal) ; // to remove mutable borrow of `password_entered`
280
+ assert ! ( password_entered) ;
281
+ }
282
+
219
283
/// Use backup file fixtures generated using firmware v9.12.0 and perform tests on it. This
220
284
/// should catch regressions when changing backup loading/verification in the firmware code.
221
285
#[ test]
0 commit comments