@@ -165,3 +165,55 @@ pub async fn unlock(hal: &mut impl crate::hal::Hal) -> Result<(), ()> {
165
165
unlock_bip39 ( hal, & bitbox02:: keystore:: copy_seed ( ) ?) . await ;
166
166
Ok ( ( ) )
167
167
}
168
+
169
+ #[ cfg( test) ]
170
+ mod tests {
171
+ use super :: * ;
172
+
173
+ use crate :: hal:: testing:: TestingHal ;
174
+ use crate :: workflow:: testing:: Screen ;
175
+ use alloc:: boxed:: Box ;
176
+ use bitbox02:: testing:: { mock_memory, mock_unlocked, mock_unlocked_using_mnemonic} ;
177
+ use util:: bb02_async:: block_on;
178
+
179
+ #[ test]
180
+ fn test_unlock_success ( ) {
181
+ mock_memory ( ) ;
182
+
183
+ // Set up an initialized wallet with password
184
+ bitbox02:: keystore:: encrypt_and_store_seed (
185
+ hex:: decode ( "c7940c13479b8d9a6498f4e50d5a42e0d617bc8e8ac9f2b8cecf97e94c2b035c" )
186
+ . unwrap ( )
187
+ . as_slice ( ) ,
188
+ "password" ,
189
+ )
190
+ . unwrap ( ) ;
191
+
192
+ bitbox02:: memory:: set_initialized ( ) . unwrap ( ) ;
193
+
194
+ // Lock the keystore to simulate the normal locked state
195
+ bitbox02:: keystore:: lock ( ) ;
196
+
197
+ let mut password_entered = false ;
198
+
199
+ let mut mock_hal = TestingHal :: new ( ) ;
200
+ mock_hal. ui . set_enter_string ( Box :: new ( |_params| {
201
+ password_entered = true ;
202
+ Ok ( "password" . into ( ) )
203
+ } ) ) ;
204
+ bitbox02:: securechip:: fake_event_counter_reset ( ) ;
205
+ assert_eq ! ( block_on( unlock( & mut mock_hal) ) , Ok ( ( ) ) ) ;
206
+ assert_eq ! ( bitbox02:: securechip:: fake_event_counter( ) , 8 ) ;
207
+
208
+ assert ! ( !bitbox02:: keystore:: is_locked( ) ) ;
209
+
210
+ assert_eq ! (
211
+ bitbox02:: keystore:: copy_bip39_seed( ) . unwrap( ) . as_slice( ) ,
212
+ hex:: decode( "cff4b263e5b0eb299e5fd35fcd09988f6b14e5b464f8d18fb84b152f889dd2a30550f4c2b346cae825ffedd4a87fc63fc12a9433de5125b6c7fdbc5eab0c590b" )
213
+ . unwrap( ) ,
214
+ ) ;
215
+
216
+ drop ( mock_hal) ; // to remove mutable borrow of `password_entered`
217
+ assert ! ( password_entered) ;
218
+ }
219
+ }
0 commit comments