-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix error while calling nonexistent entry point selector (#2606)
<!-- Reference any GitHub issues resolved by this PR --> Closes #1812 The `Err` message chosen to be thrown by `safe-dispatcher` is intended to replicate `cairo-test` behavior. These felts are taken explicitly from [`CairoHintProcessor`](https://github.com/starkware-libs/cairo/blob/2ad7718591a8d2896fec2b435c509ee5a3da9fad/crates/cairo-lang-runner/src/casm_run/mod.rs#L1055-L1057) ## Introduced changes <!-- A brief description of the changes --> - Add proper regex to catch falling error message ## Checklist <!-- Make sure all of these are complete --> - [x] Linked relevant issue - [x] Updated relevant documentation - [x] Added relevant tests - [x] Performed self-review of the code - [x] Added changes to `CHANGELOG.md`
- Loading branch information
Showing
8 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[package] | ||
name = "nonexistent_selector" | ||
version = "0.1.0" | ||
edition = "2023_11" | ||
|
||
# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html | ||
|
||
[dependencies] | ||
starknet = "2.4.0" | ||
|
||
[dev-dependencies] | ||
snforge_std = { path = "../../../../../snforge_std" } | ||
|
||
[[target.starknet-contract]] | ||
sierra = true | ||
|
||
[scripts] | ||
test = "snforge test" |
24 changes: 24 additions & 0 deletions
24
crates/forge/tests/data/nonexistent_selector/src/lib.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#[starknet::interface] | ||
pub trait IMyContract<TState> { | ||
fn my_function(self: @TState); | ||
} | ||
|
||
#[starknet::contract] | ||
pub mod MyContract { | ||
use starknet::SyscallResultTrait; | ||
use starknet::syscalls::call_contract_syscall; | ||
|
||
#[storage] | ||
pub struct Storage {} | ||
|
||
#[abi(embed_v0)] | ||
impl MyContract of super::IMyContract<ContractState> { | ||
fn my_function(self: @ContractState) { | ||
let this = starknet::get_contract_address(); | ||
let selector = selector!("nonexistent"); | ||
let calldata = array![].span(); | ||
|
||
call_contract_syscall(this, selector, calldata).unwrap_syscall(); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
crates/forge/tests/data/nonexistent_selector/tests/test_contract.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use starknet::ContractAddress; | ||
|
||
use snforge_std::{declare, ContractClassTrait, DeclareResultTrait}; | ||
|
||
use nonexistent_selector::IMyContractSafeDispatcher; | ||
use nonexistent_selector::IMyContractSafeDispatcherTrait; | ||
|
||
#[test] | ||
#[feature("safe_dispatcher")] | ||
fn test_unwrapped_call_contract_syscall() { | ||
let contract = declare("MyContract").unwrap().contract_class(); | ||
let (contract_address, _) = contract.deploy(@array![]).unwrap(); | ||
|
||
let safe_dispatcher = IMyContractSafeDispatcher { contract_address }; | ||
let res = safe_dispatcher.my_function(); | ||
match res { | ||
Result::Ok(_) => panic!("Expected an error"), | ||
Result::Err(err_data) => { | ||
assert(*err_data.at(0) == 'ENTRYPOINT_NOT_FOUND', *err_data.at(0)); | ||
assert(*err_data.at(1) == 'ENTRYPOINT_FAILED', *err_data.at(1)); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters