Skip to content

Commit

Permalink
Test divmod hint (lambdaclass#1138)
Browse files Browse the repository at this point in the history
* Implement TryFrom<CasmContractClass> for Program

* Add cairo1hintprocessor dependency

* Map hints to pc

* Add Cairo1HintProcessor

* Move cairo-1-hint-processor to cairo-rs crate

* fixes

* Fix test helper

* Remove allow

* fix test func

* Add builtins to test

* Extract builtins from contract_class

* Add _builtin to builtin names in etrypoint data

* Copy logic from cairo1 contract execution in starknet

* Remove unused code

* Use lower initial_gas value

* Add program segment size argument

* Check return values in run_cairo_1_entrypoint fn

* Remove debug prints

* Add basic fibonacci test

* Add another fibonacci case

* Always verify secure

* Clippy

* Compile casm contracts when running test target

* Remove unwrap from cell_ref_to_relocatable

* Remove paniking macro from extract_buffer

* Misc improvements

* Misc improvements

* Misc improvements

* Misc improvements

* Remove unwraps & asserts from DictSquashExecScope::pop_current_key

* Remove unwraps & asserts from DictManagerExecScope::new_default_dict

* Remove expect from get_dict_tracker

* Add constants for cairo 1 compiler binaries in makefile

* Add cairo 1 compiler to deps target in makefile

* Add cairo folder to clean target

* Remove todo from execute method

* Separate helper functions from Cairo1HintProcessor implementation

* Add untracked file

* Fix

* Add changelog entry

* Add a job to compile cairo 1 contracts in ci

* Add job dependency

* Fix yml syntax

* Fix yml syntax

* Temporarily extempt cairo-1-hint-processor from codecov

* Fix yml syntax

* Fix workflow

* Remove cache code from new job

* Fix yml syntax

* Fix wrong path

* Fix makefile

* Build only compiler binaries

* Add cairo-1-contracts-cache

* Fetch contracts cache in jobs that need them

* Use no-std version of HashMap

* Import stdlib::prelude::*

* Wrap print in not-wasm block

* Remove std path

* use slices instead of vec

* Make DictSquashExecScope fields private

* Import hint processor dependencies without default features

* -Clippy

* Add type

* Compile cairo 1 contracts in build-programs job

* Rename cache

* Use target dependency instead of explicit $(MAKE)

* Fix yml syntax

* Check for cairo folder before cloning cairo repo

* Ommit folder name

* Swap paths

* Add cairo-1-hints feature flag

* Add compile-hint feature to tests run in workflow

* Add cairo-1-hints to test_utils

* Add cairo-1-hints to test_utils

* Use both paths when fetching compiled test data

* Remove cairo-1-hints feature from test_utils feature

* Move dependencies to cairo-1-hints feature

* add test

* Update CHANGELOG.md

* Fix cfg directive

* Add cairo-1-hints to test workflow

* Add Cairo 1 considerations for Gitignore and Makefile (lambdaclass#1144)

* Add ignore for casm and sierra files

* Add libfunc experimental for cairo 1 compilation

* Add new enty to CHANGELOG

* update CHANGELOG.md

* cargo fmt

---------

Co-authored-by: Federica <fedemoletta@hotmail.com>
Co-authored-by: fmoletta <99273364+fmoletta@users.noreply.github.com>
Co-authored-by: Roberto Catalan <robertitocatalan@gmail.com>
Co-authored-by: Pedro Fontana <fontana.pedro93@gmail.com>
  • Loading branch information
5 people authored and kariy committed Jun 23, 2023
1 parent 8250c14 commit b41dec6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#### Upcoming Changes

* Add a test for the `DivMod` hint [#1138](https://github.com/lambdaclass/cairo-rs/pull/1138).

* Add some small considerations regarding Cairo 1 programs [#1144](https://github.com/lambdaclass/cairo-rs/pull/1144):

* Ignore Casm and Sierra files
Expand Down
8 changes: 8 additions & 0 deletions cairo_programs/cairo-1-contracts/divmod.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#[contract]
mod DivModTestContract {
#[external]
fn div_mod_test(x: u8, y: u8) -> u8 {
let (res, _) = integer::u8_safe_divmod(x, integer::u8_as_non_zero(y));
res
}
}
12 changes: 12 additions & 0 deletions src/tests/cairo_1_run_from_entrypoint_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,15 @@ fn fibonacci_3() {
&[9_usize.into()],
);
}

#[test]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
fn divmod_hint_test() {
let program_data = include_bytes!("../../cairo_programs/cairo-1-contracts/divmod.casm");
run_cairo_1_entrypoint(
program_data.as_slice(),
0,
&[16_usize.into(), 2_usize.into()],
&[8_usize.into()],
);
}

0 comments on commit b41dec6

Please sign in to comment.