Skip to content

Commit

Permalink
chore: import in macro body for improved readablity (#1780)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware authored Nov 4, 2024
1 parent b2c68b4 commit 9818bb1
Showing 1 changed file with 33 additions and 33 deletions.
66 changes: 33 additions & 33 deletions crates/blockifier/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,42 +217,45 @@ pub fn trivial_external_entry_point_with_address(

#[macro_export]
macro_rules! check_inner_exc_for_custom_hint {
($inner_exc:expr, $expected_hint:expr) => {
if let cairo_vm::vm::errors::vm_errors::VirtualMachineError::Hint(hint) = $inner_exc {
if let cairo_vm::vm::errors::hint_errors::HintError::Internal(
cairo_vm::vm::errors::vm_errors::VirtualMachineError::Other(error),
) = &hint.1
{
($inner_exc:expr, $expected_hint:expr) => {{
use cairo_vm::vm::errors::hint_errors::HintError;
use cairo_vm::vm::errors::vm_errors::VirtualMachineError;

if let VirtualMachineError::Hint(hint) = $inner_exc {
if let HintError::Internal(VirtualMachineError::Other(error)) = &hint.1 {
assert_eq!(error.to_string(), $expected_hint.to_string());
} else {
panic!("Unexpected hint: {:?}", hint);
}
} else {
panic!("Unexpected structure for inner_exc: {:?}", $inner_exc);
}
};
}};
}

#[macro_export]
macro_rules! check_inner_exc_for_invalid_scenario {
($inner_exc:expr) => {
if let cairo_vm::vm::errors::vm_errors::VirtualMachineError::DiffAssertValues(_) =
$inner_exc
{
($inner_exc:expr) => {{
use cairo_vm::vm::errors::vm_errors::VirtualMachineError;

if let VirtualMachineError::DiffAssertValues(_) = $inner_exc {
} else {
panic!("Unexpected structure for inner_exc: {:?}", $inner_exc)
}
};
}};
}

#[macro_export]
macro_rules! check_entry_point_execution_error {
($error:expr, $expected_hint:expr $(,)?) => {
if let $crate::execution::errors::EntryPointExecutionError::CairoRunError(
cairo_vm::vm::errors::cairo_run_errors::CairoRunError::VmException(
cairo_vm::vm::errors::vm_exception::VmException { inner_exc, .. },
),
) = $error
($error:expr, $expected_hint:expr $(,)?) => {{
use cairo_vm::vm::errors::cairo_run_errors::CairoRunError;
use cairo_vm::vm::errors::vm_exception::VmException;
use $crate::execution::errors::EntryPointExecutionError;

if let EntryPointExecutionError::CairoRunError(CairoRunError::VmException(VmException {
inner_exc,
..
})) = $error
{
match $expected_hint {
Some(expected_hint) => {
Expand All @@ -263,7 +266,7 @@ macro_rules! check_entry_point_execution_error {
} else {
panic!("Unexpected structure for error: {:?}", $error);
}
};
}};
}

/// Checks that the given error is a `HintError::CustomHint` with the given hint.
Expand All @@ -276,31 +279,28 @@ macro_rules! check_entry_point_execution_error_for_custom_hint {

#[macro_export]
macro_rules! check_tx_execution_error_inner {
($error:expr, $expected_hint:expr, $validate_constructor:expr $(,)?) => {
($error:expr, $expected_hint:expr, $validate_constructor:expr $(,)?) => {{
use $crate::execution::errors::ConstructorEntryPointExecutionError;
use $crate::transaction::errors::TransactionExecutionError;

if $validate_constructor {
match $error {
$crate::transaction::errors::TransactionExecutionError::
ContractConstructorExecutionFailed(
$crate::execution::errors::ConstructorEntryPointExecutionError::ExecutionError {
error, ..
}
TransactionExecutionError::ContractConstructorExecutionFailed(
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,
..
} => {
TransactionExecutionError::ValidateTransactionError { error, .. } => {
$crate::check_entry_point_execution_error!(error, $expected_hint)
}
_ => panic!("Unexpected structure for error: {:?}", $error),
}
}
};
}};
}

#[macro_export]
Expand All @@ -319,6 +319,8 @@ macro_rules! check_tx_execution_error_for_custom_hint {
#[macro_export]
macro_rules! check_tx_execution_error_for_invalid_scenario {
($cairo_version:expr, $error:expr, $validate_constructor:expr $(,)?) => {
use $crate::transaction::errors::TransactionExecutionError;

match $cairo_version {
CairoVersion::Cairo0 => {
$crate::check_tx_execution_error_inner!(
Expand All @@ -328,9 +330,7 @@ macro_rules! check_tx_execution_error_for_invalid_scenario {
);
}
CairoVersion::Cairo1 => {
if let $crate::transaction::errors::TransactionExecutionError::ValidateTransactionError {
error, ..
} = $error {
if let TransactionExecutionError::ValidateTransactionError { error, .. } = $error {
assert_eq!(
error.to_string(),
"Execution failed. Failure reason: 0x496e76616c6964207363656e6172696f \
Expand Down

0 comments on commit 9818bb1

Please sign in to comment.