Skip to content

Commit

Permalink
Merge branch 'main' into add-bytes31-return-type
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Fontana authored and Pedro Fontana committed May 22, 2024
2 parents 28a83bc + ad8529d commit c05f7ec
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 14 deletions.
34 changes: 24 additions & 10 deletions src/bin/cairo-native-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 12 additions & 1 deletion src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,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::<NonNull<()>>().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::Bitwise(_) => todo!(),
Expand Down
2 changes: 1 addition & 1 deletion tests/cases/cairo_vm/felt_dict_squash.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn main() -> SquashedFelt252Dict<Nullable<Span<felt252>>> {

// 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`
Expand Down
27 changes: 27 additions & 0 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions tests/tests/cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down

0 comments on commit c05f7ec

Please sign in to comment.