Skip to content

Commit

Permalink
feat(blockifier): version bound accounts: add a failure test (#3836)
Browse files Browse the repository at this point in the history
commit-id:68833c86
  • Loading branch information
liorgold2 authored Feb 5, 2025
1 parent 3de0342 commit 70ab0cc
Showing 1 changed file with 73 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use test_case::test_case;
use crate::context::ChainInfo;
use crate::execution::common_hints::ExecutionMode;
use crate::execution::entry_point::CallEntryPoint;
use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::contracts::{FeatureContract, FeatureContractData};
use crate::test_utils::initial_test_state::test_state_ex;
use crate::test_utils::{
trivial_external_entry_point_with_address,
CairoVersion,
Expand All @@ -42,13 +42,15 @@ use crate::transaction::objects::{
DeprecatedTransactionInfo,
TransactionInfo,
};
use crate::versioned_constants::VersionedConstants;

#[cfg_attr(
feature = "cairo_native",
test_case(
FeatureContract::SierraExecutionInfoV1Contract(RunnableCairo1::Native),
ExecutionMode::Validate,
TransactionVersion::ONE,
false,
false;
"Native: Validate execution mode: block info fields should be zeroed. Transaction V1."
)
Expand All @@ -59,6 +61,7 @@ use crate::transaction::objects::{
FeatureContract::SierraExecutionInfoV1Contract(RunnableCairo1::Native),
ExecutionMode::Execute,
TransactionVersion::ONE,
false,
false;
"Native: Execute execution mode: block info should be as usual. Transaction V1."
)
Expand All @@ -69,6 +72,7 @@ use crate::transaction::objects::{
FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Native)),
ExecutionMode::Validate,
TransactionVersion::THREE,
false,
false;
"Native: Validate execution mode: block info fields should be zeroed. Transaction V3."
)
Expand All @@ -79,6 +83,7 @@ use crate::transaction::objects::{
FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Native)),
ExecutionMode::Execute,
TransactionVersion::THREE,
false,
false;
"Native: Execute execution mode: block info should be as usual. Transaction V3."
)
Expand All @@ -89,8 +94,9 @@ use crate::transaction::objects::{
FeatureContract::LegacyTestContract,
ExecutionMode::Execute,
TransactionVersion::ONE,
false,
false;
"Native: Legacy contract. Execute execution mode: block info should be as usual. Transaction
"Native: Legacy contract. Execute execution mode: block info should be as usual. Transaction
V1."
)
)]
Expand All @@ -100,8 +106,9 @@ use crate::transaction::objects::{
FeatureContract::LegacyTestContract,
ExecutionMode::Execute,
TransactionVersion::THREE,
false,
false;
"Native: Legacy contract. Execute execution mode: block info should be as usual. Transaction
"Native: Legacy contract. Execute execution mode: block info should be as usual. Transaction
V3."
)
)]
Expand All @@ -111,59 +118,112 @@ use crate::transaction::objects::{
FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Native)),
ExecutionMode::Execute,
TransactionVersion::THREE,
true;
true,
false;
"Native: Execute execution mode: block info should be as usual. Transaction V3. Query"
)
)]
#[cfg_attr(
feature = "cairo_native",
test_case(
FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Native)),
ExecutionMode::Execute,
TransactionVersion::THREE,
false,
true;
"Native: V1 bound account: execute"
)
)]
#[cfg_attr(
feature = "cairo_native",
test_case(
FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Native)),
ExecutionMode::Execute,
TransactionVersion::THREE,
true,
true;
"Native: V1 bound account: query"
)
)]
#[test_case(
FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm)),
ExecutionMode::Validate,
TransactionVersion::ONE,
false,
false;
"Validate execution mode: block info fields should be zeroed. Transaction V1.")]
#[test_case(
FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm)),
ExecutionMode::Execute,
TransactionVersion::ONE,
false,
false;
"Execute execution mode: block info should be as usual. Transaction V1.")]
#[test_case(
FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm)),
ExecutionMode::Validate,
TransactionVersion::THREE,
false,
false;
"Validate execution mode: block info fields should be zeroed. Transaction V3.")]
#[test_case(
FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm)),
ExecutionMode::Execute,
TransactionVersion::THREE,
false,
false;
"Execute execution mode: block info should be as usual. Transaction V3.")]
#[test_case(
FeatureContract::LegacyTestContract,
ExecutionMode::Execute,
TransactionVersion::ONE,
false,
false;
"Legacy contract. Execute execution mode: block info should be as usual. Transaction V1.")]
#[test_case(
FeatureContract::LegacyTestContract,
ExecutionMode::Execute,
TransactionVersion::THREE,
false,
false;
"Legacy contract. Execute execution mode: block info should be as usual. Transaction V3.")]
#[test_case(
FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm)),
ExecutionMode::Execute,
TransactionVersion::THREE,
true;
true,
false;
"Execute execution mode: block info should be as usual. Transaction V3. Query.")]
#[test_case(
FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm)),
ExecutionMode::Execute,
TransactionVersion::THREE,
false,
true;
"V1 bound account: execute")]
#[test_case(
FeatureContract::TestContract(CairoVersion::Cairo1(RunnableCairo1::Casm)),
ExecutionMode::Execute,
TransactionVersion::THREE,
true,
true;
"V1 bound account: query")]
fn test_get_execution_info(
test_contract: FeatureContract,
execution_mode: ExecutionMode,
mut version: TransactionVersion,
only_query: bool,
v1_bound_account: bool,
) {
let state = &mut test_state(&ChainInfo::create_for_testing(), BALANCE, &[(test_contract, 1)]);
let mut test_contract_data: FeatureContractData = test_contract.into();
if v1_bound_account {
let optional_class_hash =
VersionedConstants::latest_constants().os_constants.v1_bound_accounts_cairo1.first();
test_contract_data.class_hash =
*optional_class_hash.expect("No v1 bound accounts found in versioned constants.");
}
let state =
&mut test_state_ex(&ChainInfo::create_for_testing(), BALANCE, &[(test_contract_data, 1)]);
let expected_block_info = match execution_mode {
ExecutionMode::Validate => [
// Rounded block number.
Expand Down Expand Up @@ -209,10 +269,14 @@ fn test_get_execution_info(
}
};

let mut expected_version = version.0;
// TODO(lior): Uncomment the line below once version-bound accounts are supported.
// let mut expected_version = if v1_bound_account { 1.into() } else { version.0 };
if only_query {
let simulate_version_base = *QUERY_VERSION_BASE;
let query_version = simulate_version_base + version.0;
version = TransactionVersion(query_version);
expected_version += simulate_version_base;
}

let tx_hash = tx_hash!(1991);
Expand Down Expand Up @@ -245,7 +309,7 @@ fn test_get_execution_info(
let tx_info: TransactionInfo;
if version == TransactionVersion::ONE {
expected_tx_info = vec![
version.0, /* Transaction
expected_version, /* Transaction
* version. */
*sender_address.0.key(), // Account address.
felt!(max_fee.0), // Max fee.
Expand All @@ -268,7 +332,7 @@ fn test_get_execution_info(
});
} else {
expected_tx_info = vec![
version.0, /* Transaction
expected_version, /* Transaction
* version. */
*sender_address.0.key(), // Account address.
Felt::ZERO, // Max fee.
Expand Down

0 comments on commit 70ab0cc

Please sign in to comment.