@@ -72,7 +72,7 @@ pub mod v1 {
72
72
73
73
pub fn try_from_slice ( bytes : & [ u8 ] ) -> Result < Self , Error > {
74
74
let message = from_slice :: < byteorder:: BE , Self > ( bytes) . unwrap ( ) ;
75
- require ! ( & message. magic[ ..] ! = b"PNAU" , Error :: InvalidMagic ) ;
75
+ require ! ( & message. magic[ ..] = = b"PNAU" , Error :: InvalidMagic ) ;
76
76
require ! ( message. major_version == 1 , Error :: InvalidVersion ) ;
77
77
require ! ( message. minor_version == 0 , Error :: InvalidVersion ) ;
78
78
Ok ( message)
@@ -130,6 +130,8 @@ mod tests {
130
130
Deserializer ,
131
131
PrefixedVec ,
132
132
Serializer ,
133
+ v1:: AccumulatorUpdateData ,
134
+ v1:: Proof ,
133
135
} ;
134
136
135
137
// Test the arbitrary fixed sized array serialization implementation.
@@ -341,4 +343,26 @@ mod tests {
341
343
crate :: wire:: from_slice:: <byteorder:: LE , _>( & buffer) . unwrap( )
342
344
) ;
343
345
}
346
+
347
+ // Test if the AccumulatorUpdateData type can be serialized and deserialized
348
+ // and still be the same as the original.
349
+ #[ test]
350
+ fn test_accumulator_update_data_serde ( ) {
351
+ use serde:: Serialize ;
352
+ // Serialize an empty update into a buffer.
353
+ let empty_update = AccumulatorUpdateData :: new ( Proof :: WormholeMerkle {
354
+ vaa : PrefixedVec :: from ( vec ! [ ] ) ,
355
+ updates : vec ! [ ] ,
356
+ } ) ;
357
+ let mut buffer = Vec :: new ( ) ;
358
+ let mut cursor = std:: io:: Cursor :: new ( & mut buffer) ;
359
+ let mut serializer: Serializer < _ , byteorder:: LE > = Serializer :: new ( & mut cursor) ;
360
+ empty_update. serialize ( & mut serializer) . unwrap ( ) ;
361
+
362
+ // Test if it can be deserialized back into the original type.
363
+ let deserialized_update = AccumulatorUpdateData :: try_from_slice ( & buffer) . unwrap ( ) ;
364
+
365
+ // The deserialized value should be the same as the original.
366
+ assert_eq ! ( deserialized_update, empty_update) ;
367
+ }
344
368
}
0 commit comments