@@ -207,8 +207,8 @@ impl Transition {
207
207
compute_function_id ( & U16Native :: new ( CurrentNetwork :: ID ) , self . 0 . program_id ( ) , self . 0 . function_name ( ) )
208
208
. map_err ( |e| e. to_string ( ) ) ?;
209
209
210
- // Create a vector that will be populated with decrypted private inputs and
211
- // non-private inputs.
210
+ // Create a vector that will be populated with decrypted private inputs and
211
+ // non-private inputs.
212
212
let mut decrypted_inputs = Vec :: with_capacity ( self . 0 . inputs ( ) . len ( ) ) ;
213
213
214
214
// Iterate over the inputs and decrypt if they are private. Non-private inputs
@@ -229,7 +229,7 @@ impl Transition {
229
229
let outputs = self . 0 . outputs ( ) ;
230
230
let num_inputs = self . 0 . inputs ( ) . len ( ) ;
231
231
232
- // Create a vector that will be populated with decrypted private outputs and
232
+ // Create a vector that will be populated with decrypted private outputs and
233
233
// non-private outputs.
234
234
let mut decrypted_outputs = Vec :: with_capacity ( outputs. len ( ) ) ;
235
235
@@ -259,7 +259,7 @@ impl Transition {
259
259
* self . 0 . tcm ( ) ,
260
260
* self . 0 . scm ( ) ,
261
261
)
262
- . map_err ( || "failed to construct decrypted transition" . to_string ( ) ) ,
262
+ . map_err ( |_| "failed to construct decrypted transition" . to_string ( ) ) ? ,
263
263
) )
264
264
}
265
265
}
@@ -520,4 +520,40 @@ mod tests {
520
520
521
521
assert_eq ! ( decrypted_transition. to_string( ) , TRANSITION_MAINNET_DECRYPTED ) ;
522
522
}
523
+
524
+ #[ wasm_bindgen_test]
525
+ #[ cfg( feature = "testnet" ) ]
526
+ fn test_transition_decrypt_testnet_invalid_vk ( ) {
527
+ // Create a view key from the test private key.
528
+ let private_key = PrivateKey :: from_str ( TEST_PRIVATE_KEY ) . unwrap ( ) ;
529
+ let view_key = ViewKey :: from_private_key ( & private_key) ;
530
+
531
+ // Get a transition with records.
532
+ let transition = Transition :: from_string ( TRANSITION_TESTNET ) . unwrap ( ) ;
533
+
534
+ // Create an invalid transition view key.
535
+ let invalid_tvk = transition. tvk ( & view_key) ;
536
+
537
+ // Attempt to decrypt the transition using the invalid transition view key.
538
+ let result = transition. decrypt_transition ( & invalid_tvk) ;
539
+ assert ! ( result. is_err( ) ) ;
540
+ }
541
+
542
+ #[ wasm_bindgen_test]
543
+ #[ cfg( feature = "mainnet" ) ]
544
+ fn test_transition_decrypt_testnet_invalid_vk ( ) {
545
+ // Create a view key from the test private key.
546
+ let private_key = PrivateKey :: from_str ( TEST_PRIVATE_KEY ) . unwrap ( ) ;
547
+ let view_key = ViewKey :: from_private_key ( & private_key) ;
548
+
549
+ // Get a transition with records.
550
+ let transition = Transition :: from_string ( TRANSITION_MAINNET ) . unwrap ( ) ;
551
+
552
+ // Create an invalid transition view key.
553
+ let invalid_tvk = transition. tvk ( & view_key) ;
554
+
555
+ // Attempt to decrypt the transition using the invalid transition view key.
556
+ let result = transition. decrypt_transition ( & invalid_tvk) ;
557
+ assert ! ( result. is_err( ) ) ;
558
+ }
523
559
}
0 commit comments