Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Add a test calling a contract that uses keccak in testnet submodule (#…
Browse files Browse the repository at this point in the history
…1110)

* Updated submodule to latest commit

* wip

* Added a usage target to makefile (#1069)

* Added a usage target to makefile

* Fixed typo

* Implement `NativeSyscallHandler::deploy` (#1106)

* wip

* Minor improvements + add test

* Improve make clippy

* Clippy + fmt

* Update error messages

* Add failure flag test

* Fix typo

* Apply suggestions + run formatter

* Add llvm setup so we can run clippy with `cairo-native` feature

* Fix

* Remove todo

* Use a proper class_hash

* Fix test assertion

---------

Co-authored-by: Juan Bono <[email protected]>

* update cairo native to use gas consumed (#1102)

* update cairo native to use gas consumed

* gas consumed

* update native rev

* fix gas consumed

* remove comments

* fixes

---------

Co-authored-by: Juan Bono <[email protected]>

* Save `SierraProgram` + `ContractEntryPoints` instead of `SierraContractClass` in `CompiledProgram` (#1112)

* Save Program + EntryPoints instead of ContractClass

* clippy

* `get_execution_info`test (#1067)

* Added cairo native flag

* Added cairo_native as dependency

* Partial progress

* Progress

* Partial progress

* Point to newly created branch on cairo native

* Use updated version of cairo native and make test pass

* Run test with storage_write and storage_read with cairo native

* Tidy up code

* Start unhardcoding stuff

* Handle return values

* Tidy up code a little

* Added sierra programs cache

* Add impl for emit_event and send_l1_message

* Fix tests

* Install LLVM on CI

* Test

* Test CI

* Fix lint step

* Save work in progress

* Unhardcode calldata and entry point

* Unhardcode more stuff

* Fix test

* Add basic implementation for call_contract

* Add call to get_name to integration test

* Make call_contract impl compile

* Fix test

* Pass the correct amount of builtins for every function

* Improve test legibility

* Write call_contract test skeleton

* Finish writing test, still bugs to fix

* implement get_execution_info, make increase_allowance work

* More debugging

* Basic test for call_contract working

* More progress on testing ERC20

* More progress on test

* Add caller and callee contracts

* Fix call_contract test after merge

* Fix callee address in tests

* Polish some details

* Remove use_cairo_native from TransactionExecutionContext

* Write test skeleton

* Add test contracts

* Fix tests

* Readd deleted contracts

* Echo contract test passing

* Update cairo compiler to version 2.2.0

* Calling another contract with events test is passing

* Fix failing tests

* Remove internal_calls field TODO in CallInfo returned by native_execute

* Add event_emitter contract

* Add cairo vm execution to the erc20 test for comparison

* Add simple implementation for panics in native execution

* Add some documentation in code

* Assert equality between events, accessed_storage_keys and l1_l2 messages between native and vm runs

* Add event_emitter contract

* Remove print

* Remove comments

* Move native syscall handler to its own file

* Add felt decode to string when program panics

* Make cairo native an optional dependency behind a feature

* Move execution result to cairo native

* Add a README section explaining how to setup cairo native

* Fix some clippy issues

* Fix test compilation

* CI test

* Revert "CI test"

This reverts commit 4631e5e.

* CI test

* Test

* Test

* Address comment about multiple cfgs

* Remove unnecessary clone

* Test

* Test

* Switch to special workflow for native integration tests

* Fix workflow

* Fix stuff after merge.

* Fix clippy warnings.

* Fix after merge.

* Fix comments.

* Fix `Makefile`.

* Remove unused import.

* Use transactional state.

* update cairo native to llvm 17 and remove nightly requirement

* update ci

* upd ci

* try to fix ci

* use ubuntu on native

* try to fix ci

* not needed?

* fix ci

* update cairo native

* fix nightly usage

* try to fix ci

* dont need a transactional state reader, simply clone the state reader

* try to fix ci

* format

* fix again

* fix if

* values

* force rebuild

* make cache track cairo 2 version to trigger rebuilds

* try no restore key

* Added get_execution_info test

* mend

* fix test + update native latest

* add deleted test

* mend

* delete unused struct

---------

Co-authored-by: Javier Chatruc <[email protected]>
Co-authored-by: Mariano Nicolini <[email protected]>
Co-authored-by: Esteve Soler Arderiu <[email protected]>
Co-authored-by: Edgar Luque <[email protected]>
Co-authored-by: toni-calvin <[email protected]>

* Cairo native: Implement library_call syscall (#1074)

* cairo-native initial implementation of library call

* rebase

* clippy

* fix

* library call test

* suggestion

* Replace class native (#1105)

* update cairo native to use gas consumed

* implement native replace class syscall

* gas consumed

* add test

* update native rev

* add failing test

* fix gas consumed

* remove comments

* minor changes

* update cairo-native dependency

* improve test

* update latest native version

* use add sierra contract to cache method

* update latest native version

* Replace class contract call native (#1115)

* add last native version

* add failing test

* fix test

* easier merge

* fix test

---------

Co-authored-by: Edgar Luque <[email protected]>

* `get_block_hash` syscall native (#1048)

* Added cairo native flag

* Added cairo_native as dependency

* Partial progress

* Progress

* Partial progress

* Point to newly created branch on cairo native

* Use updated version of cairo native and make test pass

* Run test with storage_write and storage_read with cairo native

* Tidy up code

* Start unhardcoding stuff

* Handle return values

* Tidy up code a little

* Added sierra programs cache

* Add impl for emit_event and send_l1_message

* Fix tests

* Install LLVM on CI

* Test

* Test CI

* Fix lint step

* Save work in progress

* Unhardcode calldata and entry point

* Unhardcode more stuff

* Fix test

* Add basic implementation for call_contract

* Add call to get_name to integration test

* Make call_contract impl compile

* Fix test

* Pass the correct amount of builtins for every function

* Improve test legibility

* Write call_contract test skeleton

* Finish writing test, still bugs to fix

* implement get_execution_info, make increase_allowance work

* More debugging

* Basic test for call_contract working

* More progress on testing ERC20

* More progress on test

* Add caller and callee contracts

* Fix call_contract test after merge

* Fix callee address in tests

* Polish some details

* Remove use_cairo_native from TransactionExecutionContext

* Write test skeleton

* Add test contracts

* Fix tests

* Readd deleted contracts

* Echo contract test passing

* Update cairo compiler to version 2.2.0

* Calling another contract with events test is passing

* Fix failing tests

* Remove internal_calls field TODO in CallInfo returned by native_execute

* Add event_emitter contract

* Add cairo vm execution to the erc20 test for comparison

* Add simple implementation for panics in native execution

* Add some documentation in code

* Assert equality between events, accessed_storage_keys and l1_l2 messages between native and vm runs

* Add event_emitter contract

* Remove print

* Remove comments

* Move native syscall handler to its own file

* Add felt decode to string when program panics

* Make cairo native an optional dependency behind a feature

* Move execution result to cairo native

* Add a README section explaining how to setup cairo native

* Fix some clippy issues

* Fix test compilation

* CI test

* Revert "CI test"

This reverts commit 4631e5e.

* CI test

* Test

* Test

* Address comment about multiple cfgs

* Remove unnecessary clone

* Test

* Test

* Switch to special workflow for native integration tests

* Fix workflow

* Fix stuff after merge.

* Fix clippy warnings.

* Fix after merge.

* Fix comments.

* Fix `Makefile`.

* Remove unused import.

* WIP: Implementing get_block_hash syscall

* Fix stuff.

* Use transactional state.

* update cairo native to llvm 17 and remove nightly requirement

* update ci

* upd ci

* try to fix ci

* use ubuntu on native

* try to fix ci

* not needed?

* fix ci

* update cairo native

* fix nightly usage

* try to fix ci

* dont need a transactional state reader, simply clone the state reader

* try to fix ci

* format

* fix again

* fix if

* values

* force rebuild

* make cache track cairo 2 version to trigger rebuilds

* try no restore key

* make get_hash_test syscall work with native and vm

* update readme

* implement get_block_hash on vm

* fmt

* fix tests on ci

* update cairo native commit

* fix more tests on ci

* fix cairo native interface

* try ci without cache

* checout earlier

* fix ci clippy

* test rpc reader execution

* try ci without cache

* setup rustup home

* make param passing to cairo native not obscure

* try

* try again

* remove large packages

* remove large dirs

* remove android too

* polly is needed

* needs sudo

* fix cov

* fix test for now

* format

* cleanup ci file

* use pyenv if available

* nightly not needed in readme

* add .sierra as generated to gitattributes

* fix gitattributes

* add casm too

* implement get_block_hash_native

* remove debug

* add vm execution

* merge

* add less code

* fix syscall

* fmt

* update native to last version

* correctly insert sierra class into cache test

* update latest native version

* remove comments

---------

Co-authored-by: Esteban Dimitroff Hódi <[email protected]>
Co-authored-by: Javier Chatruc <[email protected]>
Co-authored-by: Mariano Nicolini <[email protected]>
Co-authored-by: Esteve Soler Arderiu <[email protected]>
Co-authored-by: toni-calvin <[email protected]>
Co-authored-by: Edgar Luque <[email protected]>

* Add logging to syscalls (#1111)

* replace println by tracing::debug

* replace MLIR with Cairo Native

* fmt

---------

Co-authored-by: juanbono <[email protected]>

* Add error handling to `RpcState` (#1107)

* Remove explicit and implicit unwraps in RpcCallInfo deserialization

* Handle errors in RpcState::new_infura

* push RpcStateError

* Progress

* Remove all unwraps from rpc code

* Adapt tests

* Clippy

* Unify RpcError & RpcStateError

* Guard potential panicks + fmt

* clippy

* Convert my_contract/target from a submodule to a regular directory

* Add my_contract/target files

* added test that check fees and return data

* Add Keccak_contract folder

* add test price and retdata

* add test to check retdata and fee

* wip

* wip

* wip

* wip

* wip

* corrected format

* removed unused files

* Merge remote-tracking branch 'origin/rpc_state_reader-add-test-calling-contract-uses-keccak-testnet'

---------

Co-authored-by: fannyguthmann <[email protected]>
Co-authored-by: Iñaki Garay <[email protected]>
Co-authored-by: fmoletta <[email protected]>
Co-authored-by: Juan Bono <[email protected]>
Co-authored-by: Edgar <[email protected]>
Co-authored-by: ElFantasma <[email protected]>
Co-authored-by: Javier Chatruc <[email protected]>
Co-authored-by: Mariano Nicolini <[email protected]>
Co-authored-by: Esteve Soler Arderiu <[email protected]>
Co-authored-by: toni-calvin <[email protected]>
Co-authored-by: juanbono <[email protected]>
Co-authored-by: Pedro Fontana <[email protected]>
  • Loading branch information
13 people authored Nov 17, 2023
1 parent 9154239 commit 5763f6b
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion rpc_state_reader/tests/sir_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,6 @@ fn starknet_in_rust_test_case_declare_tx(hash: &str, block_number: u64, chain: R
fn starknet_in_rust_test_case_tx_skip_nonce_check(hash: &str, block_number: u64, chain: RpcChain) {
let (tx_info, trace, receipt) =
execute_tx_configurable(hash, chain, BlockNumber(block_number), false, true);

let TransactionExecutionInfo {
call_info,
actual_fee,
Expand Down Expand Up @@ -621,3 +620,47 @@ fn starknet_in_rust_test_case_tx_skip_nonce_check(hash: &str, block_number: u64,
}
}
}

#[test_case(
"0x037e199c9560666d810862bc0cf62a67aae33af6b65823068143640cdeecd8ab",
895707, // real block 895708
RpcChain::TestNet
)]
#[test_case(
"0x048ffc49f04504710e984923980fb63c4f17fb3022467251329adc75aae93c4b",
900795, // real block 900796
RpcChain::TestNet
)]
fn starknet_in_rust_check_fee_and_retdata(hash: &str, block_number: u64, chain: RpcChain) {
let (tx_info, trace, receipt) = execute_tx(hash, chain, BlockNumber(block_number));

let TransactionExecutionInfo {
call_info,
actual_fee,
..
} = tx_info;
let CallInfo { retdata, .. } = call_info.unwrap();

// check actual fee calculation
if receipt.actual_fee != actual_fee {
let diff = 100 * receipt.actual_fee.abs_diff(actual_fee) / receipt.actual_fee;

if diff >= 5 {
assert_eq!(
actual_fee, receipt.actual_fee,
"actual_fee mismatch differs from the baseline by more than 5% ({diff}%)",
);
}
}

let rpc_retdata: Vec<Felt252> = trace
.function_invocation
.unwrap()
.retdata
.unwrap()
.into_iter()
.map(|sf| Felt252::from_bytes_be(sf.bytes()))
.collect();

assert_eq!(retdata, rpc_retdata);
}

0 comments on commit 5763f6b

Please sign in to comment.