From 511faf75a0b6606e1a7f59b39f85e3df58d659ab Mon Sep 17 00:00:00 2001 From: Julian Gonzalez Calderon Date: Tue, 21 May 2024 07:11:23 -0300 Subject: [PATCH 1/2] Fix Ignored Flag Bug (#609) * Fix bug * Improve lazyness of iterators * Add comment --- src/bin/cairo-native-test.rs | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/bin/cairo-native-test.rs b/src/bin/cairo-native-test.rs index 481f008a9..973179182 100644 --- a/src/bin/cairo-native-test.rs +++ b/src/bin/cairo-native-test.rs @@ -226,17 +226,31 @@ pub fn filter_test_cases( let named_tests = compiled .named_tests .into_iter() - .map(|(func, mut test)| { - // Un-ignoring all the tests in `include-ignored` mode. - if include_ignored { + .filter(|(name, _)| name.contains(&filter)); + + let named_tests = if include_ignored { + // enable the ignored tests + named_tests + .into_iter() + .map(|(name, mut test)| { test.ignored = false; - } - (func, test) - }) - .filter(|(name, _)| name.contains(&filter)) - // Filtering unignored tests in `ignored` mode - .filter(|(_, test)| !ignored || test.ignored) - .collect_vec(); + (name, test) + }) + .collect_vec() + } else if ignored { + // filter not ignored tests and enable the remaining ones + named_tests + .into_iter() + .map(|(name, mut test)| { + test.ignored = !test.ignored; + (name, test) + }) + .filter(|(_, test)| !test.ignored) + .collect_vec() + } else { + named_tests.collect_vec() + }; + let filtered_out = total_tests_count - named_tests.len(); let tests = TestCompilation { named_tests, From ad8529da2f0ca9f8543777b7b91fdf30642da8d7 Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Wed, 22 May 2024 12:29:51 +0200 Subject: [PATCH 2/2] add `SquashedFelt252Dict` in executor (#611) * add SquashedFelt252Dict in executor * update --- src/executor.rs | 13 +++++++++- tests/cases/cairo_vm/felt_dict_squash.cairo | 2 +- tests/common.rs | 27 +++++++++++++++++++++ tests/tests/cases.rs | 4 +-- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/src/executor.rs b/src/executor.rs index 5f3d70b1d..34a7b0793 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -803,7 +803,18 @@ fn parse_result( ), }, CoreTypeConcrete::Felt252DictEntry(_) => todo!(), - CoreTypeConcrete::SquashedFelt252Dict(_) => todo!(), + CoreTypeConcrete::SquashedFelt252Dict(_) => match return_ptr { + Some(return_ptr) => JitValue::from_jit( + unsafe { *return_ptr.cast::>().as_ref() }, + type_id, + registry, + ), + None => JitValue::from_jit( + NonNull::new(ret_registers[0] as *mut ()).unwrap(), + type_id, + registry, + ), + }, CoreTypeConcrete::Span(_) => todo!(), CoreTypeConcrete::Snapshot(_) => todo!(), CoreTypeConcrete::Bytes31(_) => todo!(), diff --git a/tests/cases/cairo_vm/felt_dict_squash.cairo b/tests/cases/cairo_vm/felt_dict_squash.cairo index 7f1e284e3..da79323b8 100644 --- a/tests/cases/cairo_vm/felt_dict_squash.cairo +++ b/tests/cases/cairo_vm/felt_dict_squash.cairo @@ -7,7 +7,7 @@ fn main() -> SquashedFelt252Dict>> { // Create the array to insert let a = array![8, 9, 10, 11]; - let b = array![1, 2, 3]; + let b = array![1, 2, 3, 44]; let c = array![4, 5, 6]; // Insert it as a `Span` diff --git a/tests/common.rs b/tests/common.rs index 66e1141a9..118c58f55 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -342,6 +342,9 @@ pub fn compare_outputs( CoreTypeConcrete::NonZero(info) => map_vm_sizes(size_cache, registry, &info.ty), CoreTypeConcrete::EcPoint(_) => 2, CoreTypeConcrete::EcState(_) => 4, + CoreTypeConcrete::Snapshot(info) => { + map_vm_sizes(size_cache, registry, &info.ty) + } x => todo!("vm size not yet implemented: {:?}", x.info()), }; size_cache.insert(ty.clone(), type_size); @@ -459,6 +462,30 @@ pub fn compare_outputs( .collect(), debug_name: ty.debug_name.as_deref().map(String::from), }, + CoreTypeConcrete::SquashedFelt252Dict(info) => JitValue::Felt252Dict { + value: (values[0].to_usize().unwrap()..values[1].to_usize().unwrap()) + .step_by(3) + .map(|index| { + ( + Felt::from_bytes_le(&memory[index].clone().unwrap().to_le_bytes()), + match &info.info.long_id.generic_args[0] { + cairo_lang_sierra::program::GenericArg::Type(ty) => map_vm_values( + size_cache, + registry, + memory, + &[memory[index + 2].clone().unwrap()], + ty, + ), + _ => unimplemented!("unsupported dict value type"), + }, + ) + }) + .collect(), + debug_name: ty.debug_name.as_deref().map(String::from), + }, + CoreTypeConcrete::Snapshot(info) => { + map_vm_values(size_cache, registry, memory, values, &info.ty) + } CoreTypeConcrete::Nullable(info) => { assert_eq!(values.len(), 1); diff --git a/tests/tests/cases.rs b/tests/tests/cases.rs index 933942b19..4b54b876e 100644 --- a/tests/tests/cases.rs +++ b/tests/tests/cases.rs @@ -111,14 +111,14 @@ use test_case::test_case; #[test_case("tests/cases/cairo_vm/array_integer_tuple.cairo")] #[test_case("tests/cases/cairo_vm/bitwise.cairo")] // #[test_case("tests/cases/cairo_vm/bytes31_ret.cairo")] -// #[test_case("tests/cases/cairo_vm/dict_with_struct.cairo")] +#[test_case("tests/cases/cairo_vm/dict_with_struct.cairo")] #[test_case("tests/cases/cairo_vm/dictionaries.cairo")] #[test_case("tests/cases/cairo_vm/ecdsa_recover.cairo")] #[test_case("tests/cases/cairo_vm/enum_flow.cairo")] #[test_case("tests/cases/cairo_vm/enum_match.cairo")] #[test_case("tests/cases/cairo_vm/factorial.cairo")] // #[test_case("tests/cases/cairo_vm/felt_dict.cairo")] -// #[test_case("tests/cases/cairo_vm/felt_dict_squash.cairo")] +#[test_case("tests/cases/cairo_vm/felt_dict_squash.cairo")] // #[test_case("tests/cases/cairo_vm/felt_span.cairo")] #[test_case("tests/cases/cairo_vm/fibonacci.cairo")] #[test_case("tests/cases/cairo_vm/hello.cairo")]