Skip to content

Commit 6435a77

Browse files
Test custom serde impl
1 parent 43c2d41 commit 6435a77

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

vm/src/air_private_input.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,65 @@ mod mod_input_instance_batch_serde {
228228

229229
Ok(value.into_iter().enumerate().collect())
230230
}
231+
232+
#[cfg(feature = "std")]
233+
#[test]
234+
fn test_serde() {
235+
let input_value = vec![
236+
(
237+
0,
238+
ModInputMemoryVars {
239+
a_offset: 5,
240+
b_offset: 5,
241+
c_offset: 5,
242+
a0: Felt252::from(5u32),
243+
a1: Felt252::from(5u32),
244+
a2: Felt252::from(5u32),
245+
a3: Felt252::from(5u32),
246+
b0: Felt252::from(5u32),
247+
b1: Felt252::from(5u32),
248+
b2: Felt252::from(5u32),
249+
b3: Felt252::from(5u32),
250+
c0: Felt252::from(5u32),
251+
c1: Felt252::from(5u32),
252+
c2: Felt252::from(5u32),
253+
c3: Felt252::from(5u32),
254+
},
255+
),
256+
(
257+
1,
258+
ModInputMemoryVars {
259+
a_offset: 7,
260+
b_offset: 7,
261+
c_offset: 7,
262+
a0: Felt252::from(7u32),
263+
a1: Felt252::from(7u32),
264+
a2: Felt252::from(7u32),
265+
a3: Felt252::from(7u32),
266+
b0: Felt252::from(7u32),
267+
b1: Felt252::from(7u32),
268+
b2: Felt252::from(7u32),
269+
b3: Felt252::from(7u32),
270+
c0: Felt252::from(7u32),
271+
c1: Felt252::from(7u32),
272+
c2: Felt252::from(7u32),
273+
c3: Felt252::from(7u32),
274+
},
275+
),
276+
]
277+
.into_iter()
278+
.collect::<BTreeMap<usize, _>>();
279+
280+
let bytes = Vec::new();
281+
let mut serializer = serde_json::Serializer::new(bytes);
282+
serialize(&input_value, &mut serializer).unwrap();
283+
let bytes = serializer.into_inner();
284+
285+
let mut deserializer = serde_json::Deserializer::from_slice(&bytes);
286+
let output_value = deserialize(&mut deserializer).unwrap();
287+
288+
assert_eq!(input_value, output_value);
289+
}
231290
}
232291

233292
#[cfg(test)]

0 commit comments

Comments
 (0)