diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs index 5b417f0d73..8bf2807852 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs @@ -14,14 +14,11 @@ use crate::test_utils::contracts::FeatureContract; use crate::test_utils::initial_test_state::test_state; use crate::test_utils::{calldata_for_deploy_test, trivial_external_entry_point_new, CairoVersion}; -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1);"VM")] -#[cfg_attr( - feature = "cairo_native", - test_case(FeatureContract::TestContract(CairoVersion::Native);"Native") -)] -fn no_constructor(deployer_contract: FeatureContract) { +#[test_case(CairoVersion::Cairo1;"VM")] +#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Native;"Native"))] +fn no_constructor(cairo_version: CairoVersion) { // 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); let class_hash = empty_contract.get_class_hash(); @@ -62,12 +59,10 @@ fn no_constructor(deployer_contract: FeatureContract) { assert_eq!(state.get_class_hash_at(deployed_contract_address).unwrap(), class_hash); } -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1);"VM")] -#[cfg_attr( - feature = "cairo_native", - test_case(FeatureContract::TestContract(CairoVersion::Native);"Native") -)] -fn no_constructor_nonempty_calldata(deployer_contract: FeatureContract) { +#[test_case(CairoVersion::Cairo1;"VM")] +#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Native;"Native"))] +fn no_constructor_nonempty_calldata(cairo_version: CairoVersion) { + let deployer_contract = FeatureContract::TestContract(cairo_version); let empty_contract = FeatureContract::Empty(CairoVersion::Cairo1); let class_hash = empty_contract.get_class_hash(); @@ -92,12 +87,10 @@ fn no_constructor_nonempty_calldata(deployer_contract: FeatureContract) { )); } -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1);"VM")] -#[cfg_attr( - feature = "cairo_native", - test_case(FeatureContract::TestContract(CairoVersion::Native);"Native") -)] -fn with_constructor(deployer_contract: FeatureContract) { +#[test_case(CairoVersion::Cairo1;"VM")] +#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Native;"Native"))] +fn with_constructor(cairo_version: CairoVersion) { + let deployer_contract = FeatureContract::TestContract(cairo_version); let mut state = test_state(&ChainInfo::create_for_testing(), Fee(0), &[(deployer_contract, 1)]); let class_hash = deployer_contract.get_class_hash(); @@ -145,12 +138,10 @@ fn with_constructor(deployer_contract: FeatureContract) { assert_eq!(state.get_class_hash_at(contract_address).unwrap(), class_hash); } -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1);"VM")] -#[cfg_attr( - feature = "cairo_native", - test_case(FeatureContract::TestContract(CairoVersion::Native);"Native") -)] -fn to_unavailable_address(deployer_contract: FeatureContract) { +#[test_case(CairoVersion::Cairo1;"VM")] +#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Native;"Native"))] +fn to_unavailable_address(cairo_version: CairoVersion) { + let deployer_contract = FeatureContract::TestContract(cairo_version); let mut state = test_state(&ChainInfo::create_for_testing(), Fee(0), &[(deployer_contract, 1)]); let class_hash = deployer_contract.get_class_hash(); diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/emit_event.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/emit_event.rs index 4598c482ad..46e7564bd2 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/emit_event.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/emit_event.rs @@ -26,12 +26,10 @@ const DATA: [Felt; 3] = [ ]; const N_EMITTED_EVENTS: [Felt; 1] = [Felt::from_hex_unchecked("0x1")]; -#[cfg_attr( - feature = "cairo_native", - test_case(FeatureContract::TestContract(CairoVersion::Native); "Native") -)] -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1); "VM")] -fn positive_flow(test_contract: FeatureContract) { +#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Native;"Native"))] +#[test_case(CairoVersion::Cairo1;"VM")] +fn positive_flow(cairo_version: CairoVersion) { + let test_contract = FeatureContract::TestContract(cairo_version); let call_info = emit_events(test_contract, &N_EMITTED_EVENTS, &KEYS, &DATA) .expect("emit_events failed with valued parameters"); let event = EventContent { @@ -49,12 +47,10 @@ fn positive_flow(test_contract: FeatureContract) { ); } -#[cfg_attr( - feature = "cairo_native", - test_case(FeatureContract::TestContract(CairoVersion::Native); "Native") -)] -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1); "VM")] -fn data_length_exceeds_limit(test_contract: FeatureContract) { +#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Native;"Native"))] +#[test_case(CairoVersion::Cairo1;"VM")] +fn data_length_exceeds_limit(cairo_version: CairoVersion) { + let test_contract = FeatureContract::TestContract(cairo_version); let versioned_constants = VersionedConstants::create_for_testing(); let max_event_data_length = versioned_constants.tx_event_limits.max_data_length; @@ -71,12 +67,10 @@ fn data_length_exceeds_limit(test_contract: FeatureContract) { assert!(error_message.contains(&expected_error.to_string())); } -#[cfg_attr( - feature = "cairo_native", - test_case(FeatureContract::TestContract(CairoVersion::Native); "Native") -)] -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1); "VM")] -fn keys_length_exceeds_limit(test_contract: FeatureContract) { +#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Native;"Native"))] +#[test_case(CairoVersion::Cairo1;"VM")] +fn keys_length_exceeds_limit(cairo_version: CairoVersion) { + let test_contract = FeatureContract::TestContract(cairo_version); let versioned_constants = VersionedConstants::create_for_testing(); let max_event_keys_length = versioned_constants.tx_event_limits.max_keys_length; @@ -94,10 +88,10 @@ fn keys_length_exceeds_limit(test_contract: FeatureContract) { assert!(error_message.contains(&expected_error.to_string())); } -#[cfg(feature = "cairo_native")] -#[test_case(FeatureContract::TestContract(CairoVersion::Native); "Native")] -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1); "VM")] -fn event_number_exceeds_limit(test_contract: FeatureContract) { +#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Native;"Native"))] +#[test_case(CairoVersion::Cairo1;"VM")] +fn event_number_exceeds_limit(cairo_version: CairoVersion) { + let test_contract = FeatureContract::TestContract(cairo_version); let versioned_constants = VersionedConstants::create_for_testing(); let max_n_emitted_events = versioned_constants.tx_event_limits.max_n_emitted_events; diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/get_block_hash.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/get_block_hash.rs index 0e273e7527..83c7af1a63 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/get_block_hash.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/get_block_hash.rs @@ -40,12 +40,10 @@ fn initialize_state(test_contract: FeatureContract) -> (CachedState(test_contract: &FeatureContract) -> impl Fn(T, T) -> T + '_ { - move |native: T, non_native: T| { - #[cfg(feature = "cairo_native")] - { - if matches!(test_contract, FeatureContract::TestContract(CairoVersion::Native)) { - native - } else { - non_native - } - } - #[cfg(not(feature = "cairo_native"))] - { - non_native - } - } - } - +#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Native; "Native"))] +#[test_case(CairoVersion::Cairo1; "VM")] +fn test_nested_library_call(cairo_version: CairoVersion) { + let test_contract = FeatureContract::TestContract(cairo_version); let chain_info = &ChainInfo::create_for_testing(); let mut state = test_state(chain_info, BALANCE, &[(test_contract, 1)]); @@ -188,18 +161,17 @@ fn test_nested_library_call(test_contract: FeatureContract) { ..nested_storage_entry_point }; - let first_storage_entry_point_resources = if_native(&test_contract)( - ChargedResources { vm_resources: ExecutionResources::default(), gas_for_fee: GasAmount(0) }, - ChargedResources::from_execution_resources(ExecutionResources { + let mut first_storage_entry_point_resources = + ChargedResources { gas_for_fee: GasAmount(0), ..Default::default() }; + if cairo_version == CairoVersion::Cairo1 { + first_storage_entry_point_resources.vm_resources = ExecutionResources { n_steps: 244, n_memory_holes: 0, builtin_instance_counter: HashMap::from([(BuiltinName::range_check, 7)]), - }), - ); - let storage_entry_point_resources = if_native(&test_contract)( - ChargedResources { vm_resources: ExecutionResources::default(), gas_for_fee: GasAmount(0) }, - first_storage_entry_point_resources.clone(), - ); + }; + } + + let storage_entry_point_resources = first_storage_entry_point_resources.clone(); // The default VersionedConstants is used in the execute_directly call bellow. let tracked_resource = test_contract.get_runnable_class().tracked_resource( @@ -221,17 +193,16 @@ fn test_nested_library_call(test_contract: FeatureContract) { ..Default::default() }; - let library_call_resources = if_native(&test_contract)( - ChargedResources { vm_resources: ExecutionResources::default(), gas_for_fee: GasAmount(0) }, - ChargedResources::from_execution_resources( - &get_syscall_resources(SyscallSelector::LibraryCall) - + &ExecutionResources { - n_steps: 377, - n_memory_holes: 0, - builtin_instance_counter: HashMap::from([(BuiltinName::range_check, 15)]), - }, - ), - ); + let mut library_call_resources = + ChargedResources { gas_for_fee: GasAmount(0), ..Default::default() }; + if cairo_version == CairoVersion::Cairo1 { + library_call_resources.vm_resources = &get_syscall_resources(SyscallSelector::LibraryCall) + + &ExecutionResources { + n_steps: 377, + n_memory_holes: 0, + builtin_instance_counter: HashMap::from([(BuiltinName::range_check, 15)]), + } + } let library_call_info = CallInfo { call: library_entry_point, @@ -260,17 +231,17 @@ fn test_nested_library_call(test_contract: FeatureContract) { ..Default::default() }; - let main_call_resources = if_native(&test_contract)( - ChargedResources { vm_resources: ExecutionResources::default(), gas_for_fee: GasAmount(0) }, - ChargedResources::from_execution_resources( - &(&get_syscall_resources(SyscallSelector::LibraryCall) * 3) - + &ExecutionResources { - n_steps: 727, - n_memory_holes: 2, - builtin_instance_counter: HashMap::from([(BuiltinName::range_check, 27)]), - }, - ), - ); + let mut main_call_resources = + ChargedResources { gas_for_fee: GasAmount(0), ..Default::default() }; + if cairo_version == CairoVersion::Cairo1 { + main_call_resources.vm_resources = &(&get_syscall_resources(SyscallSelector::LibraryCall) + * 3) + + &ExecutionResources { + n_steps: 727, + n_memory_holes: 2, + builtin_instance_counter: HashMap::from([(BuiltinName::range_check, 27)]), + } + } let expected_call_info = CallInfo { call: main_entry_point.clone(), diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/out_of_gas.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/out_of_gas.rs index ab036caa64..3a6f909170 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/out_of_gas.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/out_of_gas.rs @@ -1,17 +1,20 @@ use starknet_api::abi::abi_utils::selector_from_name; -use starknet_api::execution_utils::format_panic_data; use starknet_api::{calldata, felt}; use test_case::test_case; use crate::context::ChainInfo; +use crate::execution::call_info::CallExecution; use crate::execution::entry_point::CallEntryPoint; use crate::execution::syscalls::syscall_tests::constants::REQUIRED_GAS_STORAGE_READ_WRITE_TEST; +use crate::retdata; 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, BALANCE}; -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1); "VM")] -fn test_out_of_gas(test_contract: FeatureContract) { +#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Native; "Native"))] +#[test_case(CairoVersion::Cairo1; "VM")] +fn test_out_of_gas(cairo_version: CairoVersion) { + let test_contract = FeatureContract::TestContract(cairo_version); let chain_info = &ChainInfo::create_for_testing(); let mut state = test_state(chain_info, BALANCE, &[(test_contract, 1)]); @@ -25,9 +28,14 @@ fn test_out_of_gas(test_contract: FeatureContract) { ..trivial_external_entry_point_new(test_contract) }; let call_info = entry_point_call.execute_directly(&mut state).unwrap(); - assert!(call_info.execution.failed); assert_eq!( - format_panic_data(&call_info.execution.retdata.0), - "0x4f7574206f6620676173 ('Out of gas')" + call_info.execution, + CallExecution { + // 'Out of gas' + retdata: retdata![felt!["0x4f7574206f6620676173"]], + gas_consumed: REQUIRED_GAS_STORAGE_READ_WRITE_TEST - 70, + failed: true, + ..Default::default() + } ); } diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/replace_class.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/replace_class.rs index 75ca53dbc2..03eecc996b 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/replace_class.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/replace_class.rs @@ -11,12 +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, BALANCE}; -#[cfg_attr( - feature = "cairo_native", - test_case(FeatureContract::TestContract(CairoVersion::Native); "Native") -)] -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1); "VM")] -fn undeclared_class_hash(test_contract: FeatureContract) { +#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Native; "Native"))] +#[test_case(CairoVersion::Cairo1; "VM")] +fn undeclared_class_hash(cairo_version: CairoVersion) { + let test_contract = FeatureContract::TestContract(cairo_version); let mut state = test_state(&ChainInfo::create_for_testing(), BALANCE, &[(test_contract, 1)]); let entry_point_call = CallEntryPoint { @@ -29,12 +27,10 @@ fn undeclared_class_hash(test_contract: FeatureContract) { assert!(error.to_string().contains("is not declared")); } -#[cfg_attr( - feature = "cairo_native", - test_case(FeatureContract::TestContract(CairoVersion::Native); "Native") -)] -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1); "VM")] -fn cairo0_class_hash(test_contract: FeatureContract) { +#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Native; "Native"))] +#[test_case(CairoVersion::Cairo1; "VM")] +fn cairo0_class_hash(cairo_version: CairoVersion) { + let test_contract = FeatureContract::TestContract(cairo_version); let empty_contract_cairo0 = FeatureContract::Empty(CairoVersion::Cairo0); let mut state = test_state( &ChainInfo::create_for_testing(), @@ -55,12 +51,10 @@ fn cairo0_class_hash(test_contract: FeatureContract) { assert!(error.to_string().contains("Cannot replace V1 class hash with V0 class hash")); } -#[cfg_attr( - feature = "cairo_native", - test_case(FeatureContract::TestContract(CairoVersion::Native); "Native") -)] -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1); "VM")] -fn positive_flow(test_contract: FeatureContract) { +#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Native; "Native"))] +#[test_case(CairoVersion::Cairo1; "VM")] +fn positive_flow(cairo_version: CairoVersion) { + let test_contract = FeatureContract::TestContract(cairo_version); let empty_contract = FeatureContract::Empty(CairoVersion::Cairo1); let empty_contract_cairo0 = FeatureContract::Empty(CairoVersion::Cairo0); let mut state = test_state( diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/secp.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/secp.rs index f5da4f6fa0..14255d9891 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/secp.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/secp.rs @@ -9,12 +9,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, BALANCE}; -#[cfg_attr( - feature = "cairo_native", - test_case(FeatureContract::TestContract(CairoVersion::Native); "Native") -)] -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1); "VM")] -fn test_secp256k1(test_contract: FeatureContract) { +#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Native; "Native"))] +#[test_case(CairoVersion::Cairo1; "VM")] +fn test_secp256k1(cairo_version: CairoVersion) { + let test_contract = FeatureContract::TestContract(cairo_version); let chain_info = &ChainInfo::create_for_testing(); let mut state = test_state(chain_info, BALANCE, &[(test_contract, 1)]); @@ -31,12 +29,10 @@ fn test_secp256k1(test_contract: FeatureContract) { ); } -#[cfg_attr( - feature = "cairo_native", - test_case(FeatureContract::TestContract(CairoVersion::Native); "Native") -)] -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1); "VM")] -fn test_secp256r1(test_contract: FeatureContract) { +#[cfg_attr(feature = "cairo_native",test_case(CairoVersion::Native; "Native"))] +#[test_case(CairoVersion::Cairo1; "VM")] +fn test_secp256r1(cairo_version: CairoVersion) { + let test_contract = FeatureContract::TestContract(cairo_version); let chain_info = &ChainInfo::create_for_testing(); let mut state = test_state(chain_info, BALANCE, &[(test_contract, 1)]); diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/send_message_to_l1.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/send_message_to_l1.rs index 5528c6f6ed..ab4e59b85b 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/send_message_to_l1.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/send_message_to_l1.rs @@ -13,12 +13,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, BALANCE}; -#[cfg_attr( - feature = "cairo_native", - test_case(FeatureContract::TestContract(CairoVersion::Native); "Native") -)] -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1); "VM")] -fn test_send_message_to_l1(test_contract: FeatureContract) { +#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Native; "Native"))] +#[test_case(CairoVersion::Cairo1; "VM")] +fn test_send_message_to_l1(cairo_version: CairoVersion) { + let test_contract = FeatureContract::TestContract(cairo_version); let chain_info = &ChainInfo::create_for_testing(); let mut state = test_state(chain_info, BALANCE, &[(test_contract, 1)]); diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/sha256.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/sha256.rs index 7497720078..9f8c57b9c0 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/sha256.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/sha256.rs @@ -10,12 +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, BALANCE}; -#[cfg_attr( - feature = "cairo_native", - test_case(FeatureContract::TestContract(CairoVersion::Native); "Native") -)] -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1); "VM")] -fn test_sha256(test_contract: FeatureContract) { +#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Native; "Native"))] +#[test_case(CairoVersion::Cairo1; "VM")] +fn test_sha256(cairo_version: CairoVersion) { + let test_contract = FeatureContract::TestContract(cairo_version); let chain_info = &ChainInfo::create_for_testing(); let mut state = test_state(chain_info, BALANCE, &[(test_contract, 1)]); diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/storage_read_write.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/storage_read_write.rs index 198ed7fa40..a87b6adc8b 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/storage_read_write.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/storage_read_write.rs @@ -13,12 +13,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, BALANCE}; -#[cfg_attr( - feature = "cairo_native", - test_case(FeatureContract::TestContract(CairoVersion::Native); "Native") -)] -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1); "VM")] -fn test_storage_read_write(test_contract: FeatureContract) { +#[cfg_attr(feature = "cairo_native", test_case(CairoVersion::Native; "Native"))] +#[test_case(CairoVersion::Cairo1; "VM")] +fn test_storage_read_write(cairo_version: CairoVersion) { + let test_contract = FeatureContract::TestContract(cairo_version); let chain_info = &ChainInfo::create_for_testing(); let mut state = test_state(chain_info, BALANCE, &[(test_contract, 1)]);