diff --git a/crates/blockifier/src/transaction.rs b/crates/blockifier/src/transaction.rs index 99a227c1de..78ee679cae 100644 --- a/crates/blockifier/src/transaction.rs +++ b/crates/blockifier/src/transaction.rs @@ -1,5 +1,7 @@ pub mod account_transaction; pub mod constants; +#[cfg(test)] +pub mod error_format_test; pub mod errors; pub mod objects; #[cfg(any(feature = "testing", test))] diff --git a/crates/blockifier/src/transaction/error_format_test.rs b/crates/blockifier/src/transaction/error_format_test.rs new file mode 100644 index 0000000000..fecae43c41 --- /dev/null +++ b/crates/blockifier/src/transaction/error_format_test.rs @@ -0,0 +1,16 @@ +use starknet_api::transaction::TransactionVersion; + +use crate::test_utils::CairoVersion; +use crate::transaction::errors::TransactionExecutionError; + +#[test] +fn test_contract_class_version_mismatch() { + let error = TransactionExecutionError::ContractClassVersionMismatch { + declare_version: TransactionVersion::ONE, + cairo_version: CairoVersion::Cairo0, + }; + assert_eq!( + error.to_string(), + "Declare transaction version 1 must have a contract class of Cairo version Cairo0." + ); +} diff --git a/crates/blockifier/src/transaction/errors.rs b/crates/blockifier/src/transaction/errors.rs index fc7c141e9f..38e9de147b 100644 --- a/crates/blockifier/src/transaction/errors.rs +++ b/crates/blockifier/src/transaction/errors.rs @@ -10,6 +10,7 @@ use crate::execution::errors::{ConstructorEntryPointExecutionError, EntryPointEx use crate::execution::stack_trace::gen_transaction_execution_error_trace; use crate::fee::fee_checks::FeeCheckError; use crate::state::errors::StateError; +use crate::test_utils::CairoVersion; // TODO(Yoni, 1/9/2024): implement Display for Fee. #[derive(Debug, Error)] @@ -50,10 +51,13 @@ pub enum TransactionFeeError { #[derive(Debug, Error)] pub enum TransactionExecutionError { #[error( - "Declare transaction version {declare_version:?} must have a contract class of Cairo \ - version {cairo_version:?}." + "Declare transaction version {} must have a contract class of Cairo \ + version {cairo_version:?}.", **declare_version )] - ContractClassVersionMismatch { declare_version: TransactionVersion, cairo_version: u64 }, + ContractClassVersionMismatch { + declare_version: TransactionVersion, + cairo_version: CairoVersion, + }, #[error( "Contract constructor execution has failed:\n{}", String::from(gen_transaction_execution_error_trace(self)) diff --git a/crates/blockifier/src/transaction/transaction_utils.rs b/crates/blockifier/src/transaction/transaction_utils.rs index 1f4edc40c4..c8722b89d9 100644 --- a/crates/blockifier/src/transaction/transaction_utils.rs +++ b/crates/blockifier/src/transaction/transaction_utils.rs @@ -2,6 +2,7 @@ use starknet_api::transaction::TransactionVersion; use crate::execution::call_info::CallInfo; use crate::execution::contract_class::ContractClass; +use crate::test_utils::CairoVersion; use crate::transaction::errors::TransactionExecutionError; pub fn update_remaining_gas(remaining_gas: &mut u64, call_info: &CallInfo) { @@ -22,7 +23,7 @@ pub fn verify_contract_class_version( } Err(TransactionExecutionError::ContractClassVersionMismatch { declare_version, - cairo_version: 0, + cairo_version: CairoVersion::Cairo0, }) } ContractClass::V1(_) => { @@ -33,7 +34,7 @@ pub fn verify_contract_class_version( } Err(TransactionExecutionError::ContractClassVersionMismatch { declare_version, - cairo_version: 1, + cairo_version: CairoVersion::Cairo1, }) } }