From 79ed71c68eed56eae0d3d0495771601fc6aaf6bb Mon Sep 17 00:00:00 2001 From: greged93 <82421016+greged93@users.noreply.github.com> Date: Tue, 9 Jan 2024 13:26:29 +0100 Subject: [PATCH] fix: header (#635) * handle missing header * fix * warn on failure to find entrypoint --- crates/build-utils/src/lib.rs | 1 - crates/ef-testing/src/models/case.rs | 19 +++++++++++-------- crates/ef-testing/src/models/result.rs | 26 ++++++++++++++++++++------ 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/crates/build-utils/src/lib.rs b/crates/build-utils/src/lib.rs index b9190d4c..9c9d951d 100644 --- a/crates/build-utils/src/lib.rs +++ b/crates/build-utils/src/lib.rs @@ -1,4 +1,3 @@ -//! Procedural macros. mod constants; mod content_reader; pub mod converter; diff --git a/crates/ef-testing/src/models/case.rs b/crates/ef-testing/src/models/case.rs index a0eb8b2a..143864b5 100644 --- a/crates/ef-testing/src/models/case.rs +++ b/crates/ef-testing/src/models/case.rs @@ -194,15 +194,18 @@ impl BlockchainTestCase { #[async_trait] impl Case for BlockchainTestCase { fn run(&self) -> Result<(), RunnerError> { - let block_header = self - .block - .block_header - .as_ref() - .expect("Missing block header"); + let maybe_block_header = self.block.block_header.as_ref(); + + let coinbase_address = maybe_block_header.map(|b| b.coinbase).unwrap_or_default(); + + let block_number = maybe_block_header.map(|b| b.number.0).unwrap_or_default(); + let block_number = TryInto::::try_into(block_number).unwrap_or_default(); + + let block_timestamp = maybe_block_header + .map(|b| b.timestamp.0) + .unwrap_or_default(); + let block_timestamp = TryInto::::try_into(block_timestamp).unwrap_or_default(); - let coinbase_address = block_header.coinbase; - let block_number = TryInto::::try_into(block_header.number.0).unwrap_or_default(); - let block_timestamp = TryInto::::try_into(block_header.number.0).unwrap_or_default(); let mut sequencer = KakarotSequencer::new(coinbase_address, block_number, block_timestamp); sequencer.setup_state()?; diff --git a/crates/ef-testing/src/models/result.rs b/crates/ef-testing/src/models/result.rs index cd8bea13..64b2e5c1 100644 --- a/crates/ef-testing/src/models/result.rs +++ b/crates/ef-testing/src/models/result.rs @@ -1,6 +1,9 @@ use blockifier::{ - execution::call_info::CallInfo, - transaction::objects::{TransactionExecutionInfo, TransactionExecutionResult}, + execution::{call_info::CallInfo, errors::EntryPointExecutionError}, + transaction::{ + errors::TransactionExecutionError, + objects::{TransactionExecutionInfo, TransactionExecutionResult}, + }, }; use starknet::macros::selector; use starknet_api::transaction::EventContent; @@ -22,7 +25,7 @@ pub(crate) fn log_execution_result( if let Some(call) = info.execute_call_info { use starknet::core::types::FieldElement; use starknet_api::hash::StarkFelt; - let events = get_kakarot_execution_events(&call); + let events = kakarot_execution_events(&call); // Check only one execution event. if events.len() != 1 { warn!( @@ -62,14 +65,25 @@ pub(crate) fn log_execution_result( } } } - TransactionExecutionResult::Err(err) => { - error!("{} tx failed with:\n{:?}", case, err); + TransactionExecutionResult::Err(TransactionExecutionError::ValidateTransactionError( + EntryPointExecutionError::VirtualMachineExecutionErrorWithTrace { trace, .. }, + )) => { + let re = regex::Regex::new( + r#"Error in the called contract \((0x[0-9a-zA-Z]+)\)[\s\S]*?EntryPointSelector\(StarkFelt\("(0x[0-9a-zA-Z]+)"\)\)"#, + ).unwrap(); + let matches: Vec<_> = re.captures_iter(&trace).map(|c| c.extract::<2>()).collect(); + let last_match = matches.last().cloned().unwrap_or_default(); + warn!( + "Failed to find entrypoint {} for contract {}", + last_match.1[1], last_match.1[0] + ); } + TransactionExecutionResult::Err(err) => error!("{} failed with:\n{:?}", case, err), } } #[allow(dead_code)] -fn get_kakarot_execution_events(call_info: &CallInfo) -> Vec { +fn kakarot_execution_events(call_info: &CallInfo) -> Vec { let mut events = Vec::new(); for c in call_info.into_iter() { let mut filtered_events = c