diff --git a/crates/blockifier/src/execution/errors.rs b/crates/blockifier/src/execution/errors.rs index 5657a8b015..915850dfaa 100644 --- a/crates/blockifier/src/execution/errors.rs +++ b/crates/blockifier/src/execution/errors.rs @@ -129,15 +129,6 @@ impl ConstructorEntryPointExecutionError { } } -// TODO(Dori, 5/5/2024): Delete this converter. -impl From for EntryPointExecutionError { - fn from(value: ConstructorEntryPointExecutionError) -> Self { - match value { - ConstructorEntryPointExecutionError::ExecutionError { error, .. } => error, - } - } -} - #[derive(Debug, Error)] pub enum ContractClassError { #[error( diff --git a/crates/blockifier/src/test_utils.rs b/crates/blockifier/src/test_utils.rs index d320992ecf..74321c18ae 100644 --- a/crates/blockifier/src/test_utils.rs +++ b/crates/blockifier/src/test_utils.rs @@ -243,12 +243,29 @@ macro_rules! check_entry_point_execution_error_for_custom_hint { #[macro_export] macro_rules! check_transaction_execution_error_inner { - ($error:expr, $expected_hint:expr, $variant:ident $(,)?) => { - match $error { - $crate::transaction::errors::TransactionExecutionError::$variant { error, .. } => { - $crate::check_entry_point_execution_error!(error, $expected_hint) + ($error:expr, $expected_hint:expr, $validate_constructor:expr $(,)?) => { + if $validate_constructor { + match $error { + $crate::transaction::errors::TransactionExecutionError:: + ContractConstructorExecutionFailed( + $crate::execution::errors::ConstructorEntryPointExecutionError::ExecutionError { + error, .. + } + ) => { + $crate::check_entry_point_execution_error!(error, $expected_hint) + } + _ => panic!("Unexpected structure for error: {:?}", $error), + } + } else { + match $error { + $crate::transaction::errors::TransactionExecutionError::ValidateTransactionError { + error, + .. + } => { + $crate::check_entry_point_execution_error!(error, $expected_hint) + } + _ => panic!("Unexpected structure for error: {:?}", $error), } - _ => panic!("Unexpected structure for error: {:?}", $error), } }; } @@ -256,19 +273,11 @@ macro_rules! check_transaction_execution_error_inner { #[macro_export] macro_rules! check_transaction_execution_error_for_custom_hint { ($error:expr, $expected_hint:expr, $validate_constructor:expr $(,)?) => { - if $validate_constructor { - $crate::check_transaction_execution_error_inner!( - $error, - Some($expected_hint), - ContractConstructorExecutionFailed, - ); - } else { - $crate::check_transaction_execution_error_inner!( - $error, - Some($expected_hint), - ValidateTransactionError, - ); - } + $crate::check_transaction_execution_error_inner!( + $error, + Some($expected_hint), + $validate_constructor, + ); }; } @@ -279,19 +288,11 @@ macro_rules! check_transaction_execution_error_for_invalid_scenario { ($cairo_version:expr, $error:expr, $validate_constructor:expr $(,)?) => { match $cairo_version { CairoVersion::Cairo0 => { - if $validate_constructor { - $crate::check_transaction_execution_error_inner!( - $error, - None::<&str>, - ContractConstructorExecutionFailed, - ); - } else { - $crate::check_transaction_execution_error_inner!( - $error, - None::<&str>, - ValidateTransactionError, - ); - } + $crate::check_transaction_execution_error_inner!( + $error, + None::<&str>, + $validate_constructor, + ); } CairoVersion::Cairo1 => { if let $crate::transaction::errors::TransactionExecutionError::ValidateTransactionError { diff --git a/crates/blockifier/src/transaction/errors.rs b/crates/blockifier/src/transaction/errors.rs index 4a2a5e7d22..d63c1546df 100644 --- a/crates/blockifier/src/transaction/errors.rs +++ b/crates/blockifier/src/transaction/errors.rs @@ -5,7 +5,10 @@ use starknet_api::StarknetApiError; use thiserror::Error; use crate::execution::call_info::Retdata; -use crate::execution::errors::{gen_transaction_execution_error_trace, EntryPointExecutionError}; +use crate::execution::errors::{ + gen_transaction_execution_error_trace, ConstructorEntryPointExecutionError, + EntryPointExecutionError, +}; use crate::fee::fee_checks::FeeCheckError; use crate::state::errors::StateError; @@ -56,12 +59,8 @@ pub enum TransactionExecutionError { version {cairo_version:?}." )] ContractClassVersionMismatch { declare_version: TransactionVersion, cairo_version: u64 }, - #[error("Contract constructor execution has failed: {error}")] - ContractConstructorExecutionFailed { - error: EntryPointExecutionError, - class_hash: ClassHash, - storage_address: ContractAddress, - }, + #[error(transparent)] + ContractConstructorExecutionFailed(#[from] ConstructorEntryPointExecutionError), #[error("Class with hash {class_hash:?} is already declared.")] DeclareTransactionError { class_hash: ClassHash }, #[error("Transaction execution has failed:\n{}", gen_transaction_execution_error_trace(self))] diff --git a/crates/blockifier/src/transaction/transactions.rs b/crates/blockifier/src/transaction/transactions.rs index 37ed72ab04..67046c0943 100644 --- a/crates/blockifier/src/transaction/transactions.rs +++ b/crates/blockifier/src/transaction/transactions.rs @@ -299,22 +299,14 @@ impl Executable for DeployAccountTransaction { storage_address: self.contract_address, caller_address: ContractAddress::default(), }; - let deployment_result = execute_deployment( + let call_info = execute_deployment( state, resources, context, ctor_context, self.constructor_calldata(), *remaining_gas, - ); - let call_info = deployment_result.map_err(|error| { - TransactionExecutionError::ContractConstructorExecutionFailed { - // TODO(Dori, 5/5/2024): Add the constructor error to the error enum. - error: error.into(), - class_hash, - storage_address: self.contract_address, - } - })?; + )?; update_remaining_gas(remaining_gas, &call_info); Ok(Some(call_info)) diff --git a/crates/blockifier/src/transaction/transactions_test.rs b/crates/blockifier/src/transaction/transactions_test.rs index 840ae7620f..f2dcfc63c8 100644 --- a/crates/blockifier/src/transaction/transactions_test.rs +++ b/crates/blockifier/src/transaction/transactions_test.rs @@ -30,7 +30,7 @@ use crate::execution::call_info::{ CallExecution, CallInfo, MessageToL1, OrderedEvent, OrderedL2ToL1Message, Retdata, }; use crate::execution::entry_point::{CallEntryPoint, CallType}; -use crate::execution::errors::EntryPointExecutionError; +use crate::execution::errors::{ConstructorEntryPointExecutionError, EntryPointExecutionError}; use crate::execution::execution_utils::{felt_to_stark_felt, stark_felt_to_felt}; use crate::execution::syscalls::hint_processor::EmitEventError; use crate::execution::syscalls::SyscallSelector; @@ -1362,10 +1362,14 @@ fn test_deploy_account_tx( let error = account_tx.execute(state, block_context, true, true).unwrap_err(); assert_matches!( error, - TransactionExecutionError::ContractConstructorExecutionFailed { - error: EntryPointExecutionError::StateError(StateError::UnavailableContractAddress(_)), - .. - } + TransactionExecutionError::ContractConstructorExecutionFailed( + ConstructorEntryPointExecutionError::ExecutionError { + error: EntryPointExecutionError::StateError( + StateError::UnavailableContractAddress(_) + ), + .. + } + ) ); } @@ -1394,9 +1398,14 @@ fn test_fail_deploy_account_undeclared_class_hash(block_context: BlockContext) { let error = account_tx.execute(state, block_context, true, true).unwrap_err(); assert_matches!( error, - TransactionExecutionError::ContractConstructorExecutionFailed{ - error: EntryPointExecutionError::StateError(StateError::UndeclaredClassHash(class_hash)), .. - } + TransactionExecutionError::ContractConstructorExecutionFailed( + ConstructorEntryPointExecutionError::ExecutionError { + error: EntryPointExecutionError::StateError( + StateError::UndeclaredClassHash(class_hash) + ), + .. + } + ) if class_hash == undeclared_hash ); }