@@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
66
77use crate :: backends:: plonky2:: mock_main:: MockMainPod ;
88use crate :: backends:: plonky2:: mock_signed:: MockSignedPod ;
9- use crate :: frontend:: containers:: Dictionary ;
9+ use crate :: frontend:: containers:: { Array , Dictionary , Set } ;
1010use crate :: frontend:: Statement ;
1111use crate :: middleware:: { PodId , F } ;
1212use crate :: middleware:: { HASH_SIZE , VALUE_SIZE } ;
@@ -197,21 +197,46 @@ mod tests {
197197
198198 #[ test]
199199 fn test_value_serialization ( ) {
200+ // Pairs of values and their expected serialized representations
200201 let values = vec ! [
201- Value :: String ( "hello" . to_string( ) ) ,
202- Value :: Int ( 42 ) ,
203- Value :: Bool ( true ) ,
202+ ( Value :: String ( "hello" . to_string( ) ) , "\" hello\" " ) ,
203+ ( Value :: Int ( 42 ) , "{\" Int\" :\" 42\" }" ) ,
204+ ( Value :: Bool ( true ) , "true" ) ,
205+ (
206+ Value :: Array ( Array :: new( vec![
207+ Value :: String ( "foo" . to_string( ) ) ,
208+ Value :: Bool ( false ) ,
209+ ] ) ) ,
210+ "[\" foo\" ,false]" ,
211+ ) ,
212+ (
213+ Value :: Dictionary ( Dictionary :: new( HashMap :: from( [
214+ ( "foo" . to_string( ) , Value :: Int ( 123 ) ) ,
215+ ( "bar" . to_string( ) , Value :: String ( "baz" . to_string( ) ) ) ,
216+ ] ) ) ) ,
217+ "{\" Dictionary\" :{\" bar\" :\" baz\" ,\" foo\" :{\" Int\" :\" 123\" }}}" ,
218+ ) ,
219+ (
220+ Value :: Set ( Set :: new( vec![
221+ Value :: String ( "foo" . to_string( ) ) ,
222+ Value :: String ( "bar" . to_string( ) ) ,
223+ ] ) ) ,
224+ "{\" Set\" :[\" foo\" ,\" bar\" ]}" ,
225+ ) ,
204226 ] ;
205227
206- for value in values {
228+ for ( value, expected ) in values {
207229 let serialized = serde_json:: to_string ( & value) . unwrap ( ) ;
230+ assert_eq ! ( serialized, expected) ;
208231 let deserialized: Value = serde_json:: from_str ( & serialized) . unwrap ( ) ;
209232 assert_eq ! ( value, deserialized) ;
233+ let expected_deserialized: Value = serde_json:: from_str ( & expected) . unwrap ( ) ;
234+ assert_eq ! ( value, expected_deserialized) ;
210235 }
211236 }
212237
213238 #[ test]
214- fn test_serialized_signed_pod ( ) {
239+ fn test_signed_pod_serialization ( ) {
215240 let mut signer = MockSigner { pk : "test" . into ( ) } ;
216241 let mut builder = SignedPodBuilder :: new ( & Params :: default ( ) ) ;
217242 builder. insert ( "name" , "test" ) ;
@@ -286,15 +311,4 @@ mod tests {
286311 assert_eq ! ( kyc_pod. pod. id( ) , deserialized. pod. id( ) ) ;
287312 assert_eq ! ( kyc_pod. pod. verify( ) , deserialized. pod. verify( ) ) ;
288313 }
289-
290- #[ test]
291- fn test_gen_schema ( ) {
292- let schema = schemars:: schema_for!( SignedPodHelper ) ;
293- let schema = serde_json:: to_string_pretty ( & schema) . unwrap ( ) ;
294- println ! ( "schema: {}" , schema) ;
295-
296- let schema = schemars:: schema_for!( MainPodHelper ) ;
297- let schema = serde_json:: to_string_pretty ( & schema) . unwrap ( ) ;
298- println ! ( "schema: {}" , schema) ;
299- }
300314}
0 commit comments