Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: import in macro body for improved readablity #1462

Closed
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
66 changes: 33 additions & 33 deletions crates/blockifier/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,42 +183,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 @@ -229,7 +232,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 @@ -242,31 +245,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 @@ -285,6 +285,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 @@ -294,9 +296,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
Loading