@@ -207,8 +207,8 @@ impl Transition {
207207 compute_function_id ( & U16Native :: new ( CurrentNetwork :: ID ) , self . 0 . program_id ( ) , self . 0 . function_name ( ) )
208208 . map_err ( |e| e. to_string ( ) ) ?;
209209
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.
212212 let mut decrypted_inputs = Vec :: with_capacity ( self . 0 . inputs ( ) . len ( ) ) ;
213213
214214 // Iterate over the inputs and decrypt if they are private. Non-private inputs
@@ -229,7 +229,7 @@ impl Transition {
229229 let outputs = self . 0 . outputs ( ) ;
230230 let num_inputs = self . 0 . inputs ( ) . len ( ) ;
231231
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
233233 // non-private outputs.
234234 let mut decrypted_outputs = Vec :: with_capacity ( outputs. len ( ) ) ;
235235
@@ -259,7 +259,7 @@ impl Transition {
259259 * self . 0 . tcm ( ) ,
260260 * self . 0 . scm ( ) ,
261261 )
262- . map_err ( || "failed to construct decrypted transition" . to_string ( ) ) ,
262+ . map_err ( |_| "failed to construct decrypted transition" . to_string ( ) ) ? ,
263263 ) )
264264 }
265265}
@@ -520,4 +520,40 @@ mod tests {
520520
521521 assert_eq ! ( decrypted_transition. to_string( ) , TRANSITION_MAINNET_DECRYPTED ) ;
522522 }
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+ }
523559}
0 commit comments