From aad35418797b6dce3570e6c49c63fb7984a71a48 Mon Sep 17 00:00:00 2001 From: meship-starkware Date: Thu, 15 Aug 2024 14:30:10 +0300 Subject: [PATCH] chore(blockifier): add a check on deploy syscall gas cost in the happy flows of deploy tests --- .../syscalls/syscall_tests/deploy.rs | 50 +++++++++++++++---- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs b/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs index f3517e1f9d..d93b961a4e 100644 --- a/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs +++ b/crates/blockifier/src/execution/syscalls/syscall_tests/deploy.rs @@ -14,8 +14,8 @@ 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")] -fn no_constructor(deployer_contract: FeatureContract) { +#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1), 204260;"VM")] +fn no_constructor(deployer_contract: FeatureContract, expected_gas: u64) { // TODO(Yoni): share the init code of the tests in this file. let empty_contract = FeatureContract::Empty(CairoVersion::Cairo1); @@ -33,6 +33,17 @@ fn no_constructor(deployer_contract: FeatureContract) { calldata, ..trivial_external_entry_point_new(deployer_contract) }; + + let deploy_call = &entry_point_call.execute_directly(&mut state).unwrap(); + assert_eq!( + deploy_call.execution, + CallExecution { + retdata: retdata![], + gas_consumed: expected_gas, + ..CallExecution::default() + } + ); + let deployed_contract_address = calculate_contract_address( ContractAddressSalt::default(), class_hash, @@ -41,11 +52,13 @@ fn no_constructor(deployer_contract: FeatureContract) { ) .unwrap(); - let deploy_call = &entry_point_call.execute_directly(&mut state).unwrap().inner_calls[0]; + // Note, this is the CallInfo of the constructor call. Meaning the CallExecution is the + // execution of the constructor and not the deploy syscall. + let deploy_constructor_call = &deploy_call.inner_calls[0]; - assert_eq!(deploy_call.call.storage_address, deployed_contract_address); + assert_eq!(deploy_constructor_call.call.storage_address, deployed_contract_address); assert_eq!( - deploy_call.execution, + deploy_constructor_call.execution, CallExecution { retdata: retdata![], gas_consumed: 0, ..CallExecution::default() } ); assert_eq!(state.get_class_hash_at(deployed_contract_address).unwrap(), class_hash); @@ -77,8 +90,12 @@ fn no_constructor_nonempty_calldata(deployer_contract: FeatureContract) { )); } -#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1), 5210;"VM")] -fn with_constructor(deployer_contract: FeatureContract, expected_gas: u64) { +#[test_case(FeatureContract::TestContract(CairoVersion::Cairo1),214210, 5210;"VM")] +fn with_constructor( + deployer_contract: FeatureContract, + expected_gas: u64, + expected_constructor_gas: u64, +) { let empty_contract = FeatureContract::Empty(CairoVersion::Cairo1); let mut state = test_state( &ChainInfo::create_for_testing(), @@ -108,17 +125,28 @@ fn with_constructor(deployer_contract: FeatureContract, expected_gas: u64) { deployer_contract.get_instance_address(0), ) .unwrap(); - // Note, this is the call info of the constructor call (inner call). - let deploy_call = &entry_point_call.execute_directly(&mut state).unwrap().inner_calls[0]; - assert_eq!(deploy_call.call.storage_address, contract_address); + let deploy_call = &entry_point_call.execute_directly(&mut state).unwrap(); assert_eq!( deploy_call.execution, + CallExecution { + retdata: retdata![], + gas_consumed: expected_gas, + ..CallExecution::default() + } + ); + + // Note, this is the call info of the constructor call (inner call). + let deploy_constructor_call = &deploy_call.inner_calls[0]; + + assert_eq!(deploy_constructor_call.call.storage_address, contract_address); + assert_eq!( + deploy_constructor_call.execution, CallExecution { // The test contract constructor returns its first argument. retdata: retdata![constructor_calldata[0]], // This reflects the gas cost of storage write syscall. - gas_consumed: expected_gas, + gas_consumed: expected_constructor_gas, ..CallExecution::default() } );