Skip to content

Commit

Permalink
Fix returned error array. (#6442)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyalesokhin-starkware authored Oct 1, 2024
1 parent ca2dceb commit 227cea9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions crates/cairo-lang-runner/src/casm_run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ enum SyscallResult {
}

macro_rules! fail_syscall {
([$reason1:expr, $reason2:expr]) => {
return Ok(SyscallResult::Failure(vec![
Felt252::from_bytes_be_slice($reason1),
Felt252::from_bytes_be_slice($reason2),
]))
};
($reason:expr) => {
return Ok(SyscallResult::Failure(vec![Felt252::from_bytes_be_slice($reason)]))
};
Expand Down Expand Up @@ -1035,7 +1041,7 @@ impl<'a> CairoHintProcessor<'a> {

// Get the class hash of the contract.
let Some(class_hash) = self.starknet_state.deployed_contracts.get(&contract_address) else {
fail_syscall!(b"CONTRACT_NOT_DEPLOYED");
fail_syscall!([b"CONTRACT_NOT_DEPLOYED", b"ENTRYPOINT_FAILED"]);
};

// Prepare runner for running the ctor.
Expand All @@ -1047,7 +1053,7 @@ impl<'a> CairoHintProcessor<'a> {

// Call the function.
let Some(entry_point) = contract_info.externals.get(&selector) else {
fail_syscall!(b"ENTRYPOINT_NOT_FOUND");
fail_syscall!([b"ENTRYPOINT_NOT_FOUND", b"ENTRYPOINT_FAILED"]);
};

let old_addrs = self.starknet_state.open_caller_context((
Expand Down Expand Up @@ -1085,7 +1091,7 @@ impl<'a> CairoHintProcessor<'a> {

// Call the function.
let Some(entry_point) = contract_info.externals.get(&selector) else {
fail_syscall!(b"ENTRYPOINT_NOT_FOUND");
fail_syscall!([b"ENTRYPOINT_NOT_FOUND", b"ENTRYPOINT_FAILED"]);
};
match self.call_entry_point(gas_counter, runner, entry_point, calldata, vm) {
Ok((res_data_start, res_data_end)) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn test_class_hash_not_found() {
}

#[test]
#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED',))]
#[should_panic(expected: ('CONTRACT_NOT_DEPLOYED', 'ENTRYPOINT_FAILED',))]
fn test_contract_not_deployed() {
let mut contract = IContractDispatcher { contract_address: 5.try_into().unwrap() };
contract.foo(10);
Expand Down

0 comments on commit 227cea9

Please sign in to comment.