diff --git a/cairo1-run/src/main.rs b/cairo1-run/src/main.rs index 669ab067a8..4560482486 100644 --- a/cairo1-run/src/main.rs +++ b/cairo1-run/src/main.rs @@ -475,6 +475,55 @@ mod tests { assert_matches!(run(args), Ok(Some(res)) if res == expected_output, "Program {} failed with flags {}", program, extra_flags.concat()); } + // these tests are separated so as to run them without --append_return_values and --proof_mode options + // since they require to use the squashed version of felt252 + #[rstest] + #[case( + "dict_non_squashed/dict_with_struct_non_squash.cairo", + "{0: 1 true 1: 1 false 2: 1 true}", + None + )] + #[case( + "dict_non_squashed/nullable_box_vec_non_squash.cairo", + "{0: 10 1: 20 2: 30} 3", + None + )] + #[case( + "dict_non_squashed/felt_dict_non_squash.cairo", + "{66675: [8 9 10 11] 66676: [1 2 3]}", + None + )] + fn test_run_progarm_non_proof( + #[case] program: &str, + #[case] expected_output: &str, + #[case] inputs: Option<&str>, + #[values( + &["--cairo_pie_output", "/dev/null"], // Non proof-mode + )] + extra_flags: &[&str], + ) { + let common_flags = &[ + "--print_output", + "--trace_file", + "/dev/null", + "--memory_file", + "/dev/null", + "--layout", + "all_cairo", + ]; + let mut args = vec!["cairo1-run"]; + let filename = format!("../cairo_programs/cairo-1-programs/{}", program); + + args.push(&filename); + args.extend_from_slice(common_flags); + args.extend_from_slice(extra_flags); + if let Some(inputs) = inputs { + args.extend_from_slice(&["--args", inputs]) + } + let args = args.iter().cloned().map(String::from); + assert_matches!(run(args), Ok(Some(res)) if res == expected_output, "Program {} failed with flags {}", program, extra_flags.concat()); + } + #[rstest] #[case(["cairo1-run", "../cairo_programs/cairo-1-programs/serialized_output/with_input/branching.cairo", "--layout", "all_cairo", "--cairo_pie_output", "/dev/null"].as_slice())] #[case(["cairo1-run", "../cairo_programs/cairo-1-programs/serialized_output/with_input/branching.cairo", "--layout", "all_cairo", "--proof_mode"].as_slice())] diff --git a/cairo1-run/trace b/cairo1-run/trace new file mode 100644 index 0000000000..338056a5a3 Binary files /dev/null and b/cairo1-run/trace differ diff --git a/cairo_programs/cairo-1-programs/dict_non_squashed/dict_with_struct_non_squash.cairo b/cairo_programs/cairo-1-programs/dict_non_squashed/dict_with_struct_non_squash.cairo new file mode 100644 index 0000000000..1816897def --- /dev/null +++ b/cairo_programs/cairo-1-programs/dict_non_squashed/dict_with_struct_non_squash.cairo @@ -0,0 +1,28 @@ +use core::nullable::{nullable_from_box, match_nullable, FromNullableResult}; + + +#[derive(Drop, Copy)] +struct FP16x16 { + mag: u32, + sign: bool +} + +fn main() -> Felt252Dict> { + // Create the dictionary + let mut d: Felt252Dict> = Default::default(); + + let box_a = BoxTrait::new(identity(FP16x16 { mag: 1, sign: false })); + let box_b = BoxTrait::new(identity(FP16x16 { mag: 1, sign: true })); + let box_c = BoxTrait::new(identity(FP16x16 { mag: 1, sign: true })); + + // Insert it as a `Span` + d.insert(0, nullable_from_box(box_c)); + d.insert(1, nullable_from_box(box_a)); + d.insert(2, nullable_from_box(box_b)); + + d +} + +// TODO: remove this temporary fix once fixed in cairo +#[inline(never)] +fn identity(t: T) -> T { t } diff --git a/cairo_programs/cairo-1-programs/dict_non_squashed/felt_dict_non_squash.cairo b/cairo_programs/cairo-1-programs/dict_non_squashed/felt_dict_non_squash.cairo new file mode 100644 index 0000000000..9934d4dcc9 --- /dev/null +++ b/cairo_programs/cairo-1-programs/dict_non_squashed/felt_dict_non_squash.cairo @@ -0,0 +1,15 @@ +use core::nullable::{nullable_from_box, match_nullable, FromNullableResult}; + +fn main() -> Felt252Dict>> { + // Create the dictionary + let mut d: Felt252Dict>> = Default::default(); + + // Create the array to insert + let a = array![8, 9, 10, 11]; + let b = array![1, 2, 3]; + + // Insert it as a `Span` + d.insert(66675, nullable_from_box(BoxTrait::new(a.span()))); + d.insert(66676, nullable_from_box(BoxTrait::new(b.span()))); + d +} diff --git a/cairo_programs/cairo-1-programs/dict_non_squashed/nullable_box_vec_non_squash.cairo b/cairo_programs/cairo-1-programs/dict_non_squashed/nullable_box_vec_non_squash.cairo new file mode 100644 index 0000000000..1b284325b0 --- /dev/null +++ b/cairo_programs/cairo-1-programs/dict_non_squashed/nullable_box_vec_non_squash.cairo @@ -0,0 +1,23 @@ +struct NullableVec { + items: Felt252Dict>>, + len: usize, +} + +fn main() -> NullableVec { + let mut d: Felt252Dict>> = Default::default(); + + // Populate the dictionary + d.insert(0, nullable_from_box(BoxTrait::new(BoxTrait::new(identity(10))))); + d.insert(1, nullable_from_box(BoxTrait::new(BoxTrait::new(identity(20))))); + d.insert(2, nullable_from_box(BoxTrait::new(BoxTrait::new(identity(30))))); + + // Return NullableVec + NullableVec { + items: d, + len: 3, + } +} + +// TODO: remove this temporary fix once fixed in cairo +#[inline(never)] +fn identity(t: T) -> T { t }