Skip to content

Commit

Permalink
fix: header (#635)
Browse files Browse the repository at this point in the history
* handle missing header

* fix

* warn on failure to find entrypoint
  • Loading branch information
greged93 authored Jan 9, 2024
1 parent d1767f3 commit 79ed71c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
1 change: 0 additions & 1 deletion crates/build-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//! Procedural macros.
mod constants;
mod content_reader;
pub mod converter;
Expand Down
19 changes: 11 additions & 8 deletions crates/ef-testing/src/models/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u64>::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::<u64>::try_into(block_timestamp).unwrap_or_default();

let coinbase_address = block_header.coinbase;
let block_number = TryInto::<u64>::try_into(block_header.number.0).unwrap_or_default();
let block_timestamp = TryInto::<u64>::try_into(block_header.number.0).unwrap_or_default();
let mut sequencer = KakarotSequencer::new(coinbase_address, block_number, block_timestamp);

sequencer.setup_state()?;
Expand Down
26 changes: 20 additions & 6 deletions crates/ef-testing/src/models/result.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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!(
Expand Down Expand Up @@ -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<EventContent> {
fn kakarot_execution_events(call_info: &CallInfo) -> Vec<EventContent> {
let mut events = Vec::new();
for c in call_info.into_iter() {
let mut filtered_events = c
Expand Down

0 comments on commit 79ed71c

Please sign in to comment.