Skip to content

Commit

Permalink
chore(blockifier): add with_attr error message to fail test
Browse files Browse the repository at this point in the history
  • Loading branch information
aner-starkware committed Aug 27, 2024
1 parent 3ef79fd commit caebe1c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,26 @@
"L1_HANDLER": []
},
"program": {
"attributes": [],
"attributes": [
{
"accessible_scopes": [
"__main__",
"__main__",
"__main__.fail"
],
"end_pc": 1186,
"flow_tracking_data": {
"ap_tracking": {
"group": 95,
"offset": 0
},
"reference_ids": {}
},
"name": "error_message",
"start_pc": 1182,
"value": "You shall not pass!"
}
],
"builtins": [
"pedersen",
"range_check",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ func invoke_call_chain{syscall_ptr: felt*}(calldata_len: felt, calldata: felt*)

@external
func fail() {
assert 0 = 1;
with_attr error_message("You shall not pass!") {
assert 0 = 1;
}
return ();
}

Expand Down
1 change: 1 addition & 0 deletions crates/blockifier/src/execution/stack_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ impl From<&VmExceptionFrame> for String {
} else {
"".to_string()
};
// TODO(Aner): add test for error message in intermediate call"
format!("{error_msg}{vm_exception_preamble}{vm_exception_traceback}")
}
}
Expand Down
25 changes: 23 additions & 2 deletions crates/blockifier/src/execution/stack_trace_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Unknown location (pc=0:{entry_point_location})
2: Error in the called contract (contract address: {test_contract_address_2_felt:#064x}, class \
hash: {test_contract_hash:#064x}, selector: {inner_entry_point_selector_felt:#064x}):
Error message: You shall not pass!
Error at pc=0:1184:
Cairo traceback (most recent call last):
Unknown location (pc=0:1188)
Expand Down Expand Up @@ -160,6 +161,16 @@ fn test_trace_callchain_ends_with_regular_call(
#[case] expected_error: &str,
#[case] expected_pc_locations: (u16, u16),
) {
let expected_with_attr_error_msg = match cairo_version {
CairoVersion::Cairo0 => {
if last_func_name == "fail" {
"Error message: You shall not pass!\n".to_string()
} else {
String::new()
}
}
CairoVersion::Cairo1 => String::new(),
};
let chain_info = ChainInfo::create_for_testing();
let account_contract = FeatureContract::AccountWithoutValidations(cairo_version);
let test_contract = FeatureContract::TestContract(cairo_version);
Expand Down Expand Up @@ -234,7 +245,7 @@ Unknown location (pc=0:{entry_point_location})
2: Error in the called contract (contract address: {contract_address_felt:#064x}, class hash: \
{test_contract_hash:#064x}, selector: {invoke_call_chain_selector_felt:#064x}):
Error at pc=0:{expected_pc0}:
{expected_with_attr_error_msg}Error at pc=0:{expected_pc0}:
Cairo traceback (most recent call last):
Unknown location (pc=0:{call_location})
Unknown location (pc=0:{expected_pc1})
Expand Down Expand Up @@ -285,6 +296,16 @@ fn test_trace_call_chain_with_syscalls(
#[case] call_type: u8,
#[case] expected_pcs: (u16, u16, u16, u16),
) {
let expected_with_attr_error_msg = match cairo_version {
CairoVersion::Cairo0 => {
if last_func_name == "fail" {
"Error message: You shall not pass!\n".to_string()
} else {
String::new()
}
}
CairoVersion::Cairo1 => String::new(),
};
let chain_info = ChainInfo::create_for_testing();
let account_contract = FeatureContract::AccountWithoutValidations(cairo_version);
let test_contract = FeatureContract::TestContract(cairo_version);
Expand Down Expand Up @@ -387,7 +408,7 @@ Unknown location (pc=0:{call_location})
Unknown location (pc=0:{expected_pc1})
3: {last_call_preamble}:
Error at pc=0:{expected_pc2}:
{expected_with_attr_error_msg}Error at pc=0:{expected_pc2}:
Cairo traceback (most recent call last):
Unknown location (pc=0:{expected_pc3})
Expand Down

0 comments on commit caebe1c

Please sign in to comment.