Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

fix: contract class version mismatch format #2068

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/blockifier/src/transaction.rs
Original file line number Diff line number Diff line change
@@ -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))]
Expand Down
16 changes: 16 additions & 0 deletions crates/blockifier/src/transaction/error_format_test.rs
Original file line number Diff line number Diff line change
@@ -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."
);
}
10 changes: 7 additions & 3 deletions crates/blockifier/src/transaction/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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))
Expand Down
5 changes: 3 additions & 2 deletions crates/blockifier/src/transaction/transaction_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -22,7 +23,7 @@ pub fn verify_contract_class_version(
}
Err(TransactionExecutionError::ContractClassVersionMismatch {
declare_version,
cairo_version: 0,
cairo_version: CairoVersion::Cairo0,
})
}
ContractClass::V1(_) => {
Expand All @@ -33,7 +34,7 @@ pub fn verify_contract_class_version(
}
Err(TransactionExecutionError::ContractClassVersionMismatch {
declare_version,
cairo_version: 1,
cairo_version: CairoVersion::Cairo1,
})
}
}
Expand Down
Loading