Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Arcticae committed Jun 30, 2023
1 parent 46527e5 commit adbe3f1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 39 deletions.
42 changes: 26 additions & 16 deletions protostar-rust/src/cheatcodes_hint_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ use blockifier::execution::contract_class::{
ContractClass as BlockifierContractClass, ContractClassV1,
};
use blockifier::execution::entry_point::{CallEntryPoint, CallType};
use blockifier::execution::errors::EntryPointExecutionError;
use blockifier::state::cached_state::CachedState;
use blockifier::state::state_api::StateReader;
use blockifier::test_utils::{invoke_tx, DictStateReader};
use blockifier::test_utils::{MAX_FEE, TEST_ACCOUNT_CONTRACT_ADDRESS};
use blockifier::transaction::account_transaction::AccountTransaction;
use blockifier::transaction::errors::TransactionExecutionError;
use blockifier::transaction::transaction_utils_for_protostar::declare_tx_default;
use blockifier::transaction::transactions::{DeclareTransaction, ExecutableTransaction};
use cairo_felt::Felt252;
Expand All @@ -40,8 +42,6 @@ use cairo_vm::vm::errors::hint_errors::HintError;
use cairo_vm::vm::errors::vm_errors::VirtualMachineError;
use cairo_vm::vm::vm_core::VirtualMachine;
use num_traits::{Num, ToPrimitive};
use cairo_vm::vm::vm_core::VirtualMachine;
use num_traits::{Num, ToPrimitive};
use regex::Regex;
use serde::Deserialize;
use starknet_api::core::{ClassHash, ContractAddress, EntryPointSelector, PatriciaKey};
Expand Down Expand Up @@ -386,20 +386,31 @@ fn execute_cheatcode_hint(
insert_value_to_cellref!(vm, panic_data_end, Felt252::from(0))?;
}
Result::Err(e) => {
let msg = e.source().expect("No source error found").to_string();
let unparseable_msg = format!("Deploy failed, full error message: {msg}");
let unparseable_msg = unparseable_msg.as_str();

let extracted_panic_data = try_extract_panic_data(&msg).expect(unparseable_msg);
let mut ptr = vm.add_memory_segment();
insert_value_to_cellref!(vm, panic_data_start, ptr)?;

for datum in extracted_panic_data {
insert_at_pointer(vm, &mut ptr, datum);
if let TransactionExecutionError::ExecutionError(
EntryPointExecutionError::VirtualMachineExecutionErrorWithTrace {
source,
trace,
},
) = e
{
let msg = source.to_string();
let unparseable_msg = format!("Deploy failed, full error message: {msg}");
let unparseable_msg = unparseable_msg.as_str();

let extracted_panic_data =
try_extract_panic_data(&msg).expect(unparseable_msg);
let mut ptr = vm.add_memory_segment();
insert_value_to_cellref!(vm, panic_data_start, ptr)?;

for datum in extracted_panic_data {
insert_at_pointer(vm, &mut ptr, datum);
}

insert_value_to_cellref!(vm, deployed_contract_address, contract_address)?;
insert_value_to_cellref!(vm, panic_data_end, ptr)?;
} else {
panic!("Unparseable error message: {e:?}")
}

insert_value_to_cellref!(vm, deployed_contract_address, contract_address)?;
insert_value_to_cellref!(vm, panic_data_end, ptr)?;
}
}
Ok(())
Expand Down Expand Up @@ -526,7 +537,6 @@ fn try_extract_panic_data(err: &str) -> Option<Vec<Felt252>> {
None
}


#[cfg(test)]
mod test {
use super::*;
Expand Down
25 changes: 2 additions & 23 deletions protostar-rust/tests/e2e/running.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,28 +280,6 @@ fn exit_first_flag() {
"#});
}

#[test]
fn dispatchers() {
let temp = assert_fs::TempDir::new().unwrap();
temp.copy_from("tests/data/dispatchers", &["**/*"]).unwrap();

let snapbox = runner();

snapbox
.current_dir(&temp)
.assert()
.success()
.stdout_matches(indoc! {r#"Collected 2 test(s) and 4 test file(s)
Running 0 test(s) from src/erc20.cairo
Running 0 test(s) from src/hello_starknet.cairo
Running 0 test(s) from src/lib.cairo
Running 2 test(s) from tests/using_dispatchers.cairo
[PASS] using_dispatchers::using_dispatchers::call_and_invoke
[PASS] using_dispatchers::using_dispatchers::advanced_types
Tests: 2 passed, 0 failed, 0 skipped
"#});
}

#[test]
fn test_deploy_error_handling() {
let temp = assert_fs::TempDir::new().unwrap();
Expand All @@ -317,9 +295,10 @@ fn test_deploy_error_handling() {
Running 0 test(s) from src/lib.cairo
Running 1 test(s) from tests/test_deploy_error_handling.cairo
[PASS] test_deploy_error_handling::test_deploy_error_handling::test_deploy_error_handling
Tests: 1 passed, 0 failed
Tests: 1 passed, 0 failed, 0 skipped
"#});
}

#[test]
fn dispatchers() {
let temp = assert_fs::TempDir::new().unwrap();
Expand Down

0 comments on commit adbe3f1

Please sign in to comment.