Skip to content

Commit

Permalink
chore(blockifier): set syscall tests to get runnable version (#2543)
Browse files Browse the repository at this point in the history
  • Loading branch information
meship-starkware authored Dec 9, 2024
1 parent bf8011e commit 4269d45
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ use crate::test_utils::{
BALANCE,
};

#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Cairo1(RunnableCairo1::Native); "Native"))]
#[test_case(CairoVersion::Cairo1(RunnableCairo1::Casm);"VM")]
fn test_call_contract_that_panics(cairo_version: CairoVersion) {
let test_contract = FeatureContract::TestContract(cairo_version);
let empty_contract = FeatureContract::Empty(CairoVersion::Cairo1(RunnableCairo1::Casm));
#[cfg_attr(feature = "cairo_native", test_case(RunnableCairo1::Native; "Native"))]
#[test_case(RunnableCairo1::Casm;"VM")]
fn test_call_contract_that_panics(runnable_version: RunnableCairo1) {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
let empty_contract = FeatureContract::Empty(CairoVersion::Cairo1(runnable_version));
let chain_info = &ChainInfo::create_for_testing();
let mut state = test_state(chain_info, BALANCE, &[(test_contract, 1), (empty_contract, 0)]);

Expand Down
36 changes: 18 additions & 18 deletions crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ use crate::test_utils::{
RunnableCairo1,
};

#[test_case(CairoVersion::Cairo1(RunnableCairo1::Casm);"VM")]
#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Cairo1(RunnableCairo1::Native);"Native"))]
fn no_constructor(cairo_version: CairoVersion) {
#[test_case(RunnableCairo1::Casm;"VM")]
#[cfg_attr(feature = "cairo_native", test_case(RunnableCairo1::Native;"Native"))]
fn no_constructor(runnable_version: RunnableCairo1) {
// TODO(Yoni): share the init code of the tests in this file.
let deployer_contract = FeatureContract::TestContract(cairo_version);
let empty_contract = FeatureContract::Empty(CairoVersion::Cairo1(RunnableCairo1::Casm));
let deployer_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
let empty_contract = FeatureContract::Empty(CairoVersion::Cairo1(runnable_version));
let class_hash = empty_contract.get_class_hash();

let mut state = test_state(
Expand Down Expand Up @@ -64,11 +64,11 @@ fn no_constructor(cairo_version: CairoVersion) {
assert_eq!(state.get_class_hash_at(deployed_contract_address).unwrap(), class_hash);
}

#[test_case(CairoVersion::Cairo1(RunnableCairo1::Casm);"VM")]
#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Cairo1(RunnableCairo1::Native);"Native"))]
fn no_constructor_nonempty_calldata(cairo_version: CairoVersion) {
let deployer_contract = FeatureContract::TestContract(cairo_version);
let empty_contract = FeatureContract::Empty(CairoVersion::Cairo1(RunnableCairo1::Casm));
#[test_case(RunnableCairo1::Casm;"VM")]
#[cfg_attr(feature = "cairo_native", test_case(RunnableCairo1::Native;"Native"))]
fn no_constructor_nonempty_calldata(runnable_version: RunnableCairo1) {
let deployer_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
let empty_contract = FeatureContract::Empty(CairoVersion::Cairo1(runnable_version));
let class_hash = empty_contract.get_class_hash();

let mut state = test_state(
Expand All @@ -92,10 +92,10 @@ fn no_constructor_nonempty_calldata(cairo_version: CairoVersion) {
));
}

#[test_case(CairoVersion::Cairo1(RunnableCairo1::Casm);"VM")]
#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Cairo1(RunnableCairo1::Native);"Native"))]
fn with_constructor(cairo_version: CairoVersion) {
let deployer_contract = FeatureContract::TestContract(cairo_version);
#[test_case(RunnableCairo1::Casm;"VM")]
#[cfg_attr(feature = "cairo_native", test_case(RunnableCairo1::Native;"Native"))]
fn with_constructor(runnable_version: RunnableCairo1) {
let deployer_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
let mut state = test_state(&ChainInfo::create_for_testing(), Fee(0), &[(deployer_contract, 1)]);

let class_hash = deployer_contract.get_class_hash();
Expand Down Expand Up @@ -143,10 +143,10 @@ fn with_constructor(cairo_version: CairoVersion) {
assert_eq!(state.get_class_hash_at(contract_address).unwrap(), class_hash);
}

#[test_case(CairoVersion::Cairo1(RunnableCairo1::Casm);"VM")]
#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Cairo1(RunnableCairo1::Native);"Native"))]
fn to_unavailable_address(cairo_version: CairoVersion) {
let deployer_contract = FeatureContract::TestContract(cairo_version);
#[test_case(RunnableCairo1::Casm;"VM")]
#[cfg_attr(feature = "cairo_native", test_case(RunnableCairo1::Native;"Native"))]
fn to_unavailable_address(runnable_version: RunnableCairo1) {
let deployer_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
let mut state = test_state(&ChainInfo::create_for_testing(), Fee(0), &[(deployer_contract, 1)]);

let class_hash = deployer_contract.get_class_hash();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ const DATA: [Felt; 3] = [
];
const N_EMITTED_EVENTS: [Felt; 1] = [Felt::from_hex_unchecked("0x1")];

#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Cairo1(RunnableCairo1::Native);"Native"))]
#[test_case(CairoVersion::Cairo1(RunnableCairo1::Casm);"VM")]
fn positive_flow(cairo_version: CairoVersion) {
let test_contract = FeatureContract::TestContract(cairo_version);
#[cfg_attr(feature = "cairo_native", test_case(RunnableCairo1::Native;"Native"))]
#[test_case(RunnableCairo1::Casm;"VM")]
fn positive_flow(runnable_version: RunnableCairo1) {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
let call_info = emit_events(test_contract, &N_EMITTED_EVENTS, &KEYS, &DATA)
.expect("emit_events failed with valued parameters");
let event = EventContent {
Expand All @@ -47,10 +47,10 @@ fn positive_flow(cairo_version: CairoVersion) {
);
}

#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Cairo1(RunnableCairo1::Native);"Native"))]
#[test_case(CairoVersion::Cairo1(RunnableCairo1::Casm);"VM")]
fn data_length_exceeds_limit(cairo_version: CairoVersion) {
let test_contract = FeatureContract::TestContract(cairo_version);
#[cfg_attr(feature = "cairo_native", test_case(RunnableCairo1::Native;"Native"))]
#[test_case(RunnableCairo1::Casm;"VM")]
fn data_length_exceeds_limit(runnable_version: RunnableCairo1) {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
let versioned_constants = VersionedConstants::create_for_testing();

let max_event_data_length = versioned_constants.tx_event_limits.max_data_length;
Expand All @@ -67,10 +67,10 @@ fn data_length_exceeds_limit(cairo_version: CairoVersion) {
assert!(error_message.contains(&expected_error.to_string()));
}

#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Cairo1(RunnableCairo1::Native);"Native"))]
#[test_case(CairoVersion::Cairo1(RunnableCairo1::Casm);"VM")]
fn keys_length_exceeds_limit(cairo_version: CairoVersion) {
let test_contract = FeatureContract::TestContract(cairo_version);
#[cfg_attr(feature = "cairo_native", test_case(RunnableCairo1::Native;"Native"))]
#[test_case(RunnableCairo1::Casm;"VM")]
fn keys_length_exceeds_limit(runnable_version: RunnableCairo1) {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
let versioned_constants = VersionedConstants::create_for_testing();

let max_event_keys_length = versioned_constants.tx_event_limits.max_keys_length;
Expand All @@ -88,10 +88,10 @@ fn keys_length_exceeds_limit(cairo_version: CairoVersion) {
assert!(error_message.contains(&expected_error.to_string()));
}

#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Cairo1(RunnableCairo1::Native);"Native"))]
#[test_case(CairoVersion::Cairo1(RunnableCairo1::Casm);"VM")]
fn event_number_exceeds_limit(cairo_version: CairoVersion) {
let test_contract = FeatureContract::TestContract(cairo_version);
#[cfg_attr(feature = "cairo_native", test_case(RunnableCairo1::Native;"Native"))]
#[test_case(RunnableCairo1::Casm;"VM")]
fn event_number_exceeds_limit(runnable_version: RunnableCairo1) {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
let versioned_constants = VersionedConstants::create_for_testing();

let max_n_emitted_events = versioned_constants.tx_event_limits.max_n_emitted_events;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ fn initialize_state(test_contract: FeatureContract) -> (CachedState<DictStateRea
(state, block_number, block_hash)
}

#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Cairo1(RunnableCairo1::Native);"Native"))]
#[test_case(CairoVersion::Cairo1(RunnableCairo1::Casm);"VM")]
fn positive_flow(cairo_version: CairoVersion) {
let test_contract = FeatureContract::TestContract(cairo_version);
#[cfg_attr(feature = "cairo_native", test_case(RunnableCairo1::Native;"Native"))]
#[test_case(RunnableCairo1::Casm;"VM")]
fn positive_flow(runnable_version: RunnableCairo1) {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
let (mut state, block_number, block_hash) = initialize_state(test_contract);

let calldata = calldata![block_number];
Expand All @@ -62,10 +62,10 @@ fn positive_flow(cairo_version: CairoVersion) {
);
}

#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Cairo1(RunnableCairo1::Native);"Native"))]
#[test_case(CairoVersion::Cairo1(RunnableCairo1::Casm);"VM")]
fn negative_flow_execution_mode_validate(cairo_version: CairoVersion) {
let test_contract = FeatureContract::TestContract(cairo_version);
#[cfg_attr(feature = "cairo_native", test_case(RunnableCairo1::Native;"Native"))]
#[test_case(RunnableCairo1::Casm;"VM")]
fn negative_flow_execution_mode_validate(runnable_version: RunnableCairo1) {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
let (mut state, block_number, _) = initialize_state(test_contract);

let calldata = calldata![block_number];
Expand Down Expand Up @@ -99,10 +99,10 @@ fn negative_flow_execution_mode_validate(cairo_version: CairoVersion) {
);
}

#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Cairo1(RunnableCairo1::Native);"Native"))]
#[test_case(CairoVersion::Cairo1(RunnableCairo1::Casm);"VM")]
fn negative_flow_block_number_out_of_range(cairo_version: CairoVersion) {
let test_contract = FeatureContract::TestContract(cairo_version);
#[cfg_attr(feature = "cairo_native", test_case(RunnableCairo1::Native;"Native"))]
#[test_case(RunnableCairo1::Casm;"VM")]
fn negative_flow_block_number_out_of_range(runnable_version: RunnableCairo1) {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
let (mut state, _, _) = initialize_state(test_contract);

let requested_block_number = CURRENT_BLOCK_NUMBER - constants::STORED_BLOCK_HASH_BUFFER + 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ use crate::test_utils::{trivial_external_entry_point_new, CairoVersion, Runnable
/// 3. Execution succeeds with expected gas for valid cases.
/// 4. Execution fails if `address` has a different `class_hash`.
/// 5. Execution succeeds and returns `class_hash` = 0 if `address` is absent.
#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Cairo1(RunnableCairo1::Native);"Native"))]
#[test_case(CairoVersion::Cairo1(RunnableCairo1::Casm);"VM")]
fn test_get_class_hash_at(cairo_version: CairoVersion) {
let test_contract = FeatureContract::TestContract(cairo_version);
#[cfg_attr(feature = "cairo_native", test_case(RunnableCairo1::Native;"Native"))]
#[test_case(RunnableCairo1::Casm;"VM")]
fn test_get_class_hash_at(runnable_version: RunnableCairo1) {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
let chain_info = &ChainInfo::create_for_testing();
let mut state = test_state(chain_info, BALANCE, &[(test_contract, 1)]);
let address = contract_address!("0x111");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::{trivial_external_entry_point_new, CairoVersion, RunnableCairo1, BALANCE};

#[test_case(CairoVersion::Cairo1(RunnableCairo1::Casm); "VM")]
#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Cairo1(RunnableCairo1::Native); "Native"))]
fn test_keccak(cairo_version: CairoVersion) {
let test_contract = FeatureContract::TestContract(cairo_version);
#[test_case(RunnableCairo1::Casm; "VM")]
#[cfg_attr(feature = "cairo_native", test_case(RunnableCairo1::Native; "Native"))]
fn test_keccak(runnable_version: RunnableCairo1) {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
let chain_info = &ChainInfo::create_for_testing();
let mut state = test_state(chain_info, BALANCE, &[(test_contract, 1)]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ use crate::test_utils::{
};
use crate::versioned_constants::VersionedConstants;

#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Cairo1(RunnableCairo1::Native); "Native"))]
#[test_case(CairoVersion::Cairo1(RunnableCairo1::Casm); "VM")]
fn test_library_call(cairo_version: CairoVersion) {
let test_contract = FeatureContract::TestContract(cairo_version);
#[cfg_attr(feature = "cairo_native", test_case(RunnableCairo1::Native; "Native"))]
#[test_case(RunnableCairo1::Casm; "VM")]
fn test_library_call(runnable_version: RunnableCairo1) {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
let chain_info = &ChainInfo::create_for_testing();
let mut state = test_state(chain_info, BALANCE, &[(test_contract, 1)]);

Expand Down Expand Up @@ -61,10 +61,10 @@ fn test_library_call(cairo_version: CairoVersion) {
);
}

#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Cairo1(RunnableCairo1::Native); "Native"))]
#[test_case(CairoVersion::Cairo1(RunnableCairo1::Casm); "VM")]
fn test_library_call_assert_fails(cairo_version: CairoVersion) {
let test_contract = FeatureContract::TestContract(cairo_version);
#[cfg_attr(feature = "cairo_native", test_case(RunnableCairo1::Native; "Native"))]
#[test_case(RunnableCairo1::Casm; "VM")]
fn test_library_call_assert_fails(runnable_version: RunnableCairo1) {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
let chain_info = &ChainInfo::create_for_testing();
let mut state = test_state(chain_info, BALANCE, &[(test_contract, 1)]);
let inner_entry_point_selector = selector_from_name("assert_eq");
Expand Down Expand Up @@ -100,10 +100,10 @@ fn test_library_call_assert_fails(cairo_version: CairoVersion) {
);
}

#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Cairo1(RunnableCairo1::Native); "Native"))]
#[test_case(CairoVersion::Cairo1(RunnableCairo1::Casm); "VM")]
fn test_nested_library_call(cairo_version: CairoVersion) {
let test_contract = FeatureContract::TestContract(cairo_version);
#[cfg_attr(feature = "cairo_native", test_case(RunnableCairo1::Native; "Native"))]
#[test_case(RunnableCairo1::Casm; "VM")]
fn test_nested_library_call(runnable_version: RunnableCairo1) {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
let chain_info = &ChainInfo::create_for_testing();
let mut state = test_state(chain_info, BALANCE, &[(test_contract, 1)]);

Expand Down Expand Up @@ -159,7 +159,7 @@ fn test_nested_library_call(cairo_version: CairoVersion) {

let mut first_storage_entry_point_resources =
ChargedResources { gas_for_fee: GasAmount(0), ..Default::default() };
if cairo_version == CairoVersion::Cairo1(RunnableCairo1::Casm) {
if runnable_version == RunnableCairo1::Casm {
first_storage_entry_point_resources.vm_resources = ExecutionResources {
n_steps: 244,
n_memory_holes: 0,
Expand Down Expand Up @@ -191,7 +191,7 @@ fn test_nested_library_call(cairo_version: CairoVersion) {

let mut library_call_resources =
ChargedResources { gas_for_fee: GasAmount(0), ..Default::default() };
if cairo_version == CairoVersion::Cairo1(RunnableCairo1::Casm) {
if runnable_version == RunnableCairo1::Casm {
library_call_resources.vm_resources = &get_syscall_resources(SyscallSelector::LibraryCall)
+ &ExecutionResources {
n_steps: 377,
Expand Down Expand Up @@ -229,7 +229,7 @@ fn test_nested_library_call(cairo_version: CairoVersion) {

let mut main_call_resources =
ChargedResources { gas_for_fee: GasAmount(0), ..Default::default() };
if cairo_version == CairoVersion::Cairo1(RunnableCairo1::Casm) {
if runnable_version == RunnableCairo1::Casm {
main_call_resources.vm_resources = &(&get_syscall_resources(SyscallSelector::LibraryCall)
* 3)
+ &ExecutionResources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ use crate::test_utils::contracts::FeatureContract;
use crate::test_utils::initial_test_state::test_state;
use crate::test_utils::{trivial_external_entry_point_new, CairoVersion, RunnableCairo1, BALANCE};

#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Cairo1(RunnableCairo1::Native); "Native"))]
#[test_case(CairoVersion::Cairo1(RunnableCairo1::Casm); "VM")]
fn test_out_of_gas(cairo_version: CairoVersion) {
let test_contract = FeatureContract::TestContract(cairo_version);
#[cfg_attr(feature = "cairo_native", test_case(RunnableCairo1::Native; "Native"))]
#[test_case(RunnableCairo1::Casm; "VM")]
fn test_out_of_gas(runnable_version: RunnableCairo1) {
let test_contract = FeatureContract::TestContract(CairoVersion::Cairo1(runnable_version));
let chain_info = &ChainInfo::create_for_testing();
let mut state = test_state(chain_info, BALANCE, &[(test_contract, 1)]);

Expand Down
Loading

0 comments on commit 4269d45

Please sign in to comment.