From e7523c68d373565dc08ea54a0a2206c8db086de2 Mon Sep 17 00:00:00 2001 From: dorimedini-starkware Date: Wed, 18 Oct 2023 12:44:52 +0300 Subject: [PATCH] Better test_call_contract (#994) Signed-off-by: Dori Medini --- crates/blockifier/src/execution/call_info.rs | 4 ++ .../deprecated_syscalls_test.rs | 51 ++++++++++++++++--- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/crates/blockifier/src/execution/call_info.rs b/crates/blockifier/src/execution/call_info.rs index 9aa94a101f..0ef80a1a42 100644 --- a/crates/blockifier/src/execution/call_info.rs +++ b/crates/blockifier/src/execution/call_info.rs @@ -20,18 +20,21 @@ macro_rules! retdata { }; } +#[cfg_attr(test, derive(Clone))] #[derive(Debug, Default, Eq, PartialEq)] pub struct OrderedEvent { pub order: usize, pub event: EventContent, } +#[cfg_attr(test, derive(Clone))] #[derive(Debug, Default, Eq, PartialEq)] pub struct MessageToL1 { pub to_address: EthAddress, pub payload: L2ToL1Payload, } +#[cfg_attr(test, derive(Clone))] #[derive(Debug, Default, Eq, PartialEq)] pub struct OrderedL2ToL1Message { pub order: usize, @@ -39,6 +42,7 @@ pub struct OrderedL2ToL1Message { } /// Represents the effects of executing a single entry point. +#[cfg_attr(test, derive(Clone))] #[derive(Debug, Default, Eq, PartialEq)] pub struct CallExecution { pub retdata: Retdata, diff --git a/crates/blockifier/src/execution/deprecated_syscalls/deprecated_syscalls_test.rs b/crates/blockifier/src/execution/deprecated_syscalls/deprecated_syscalls_test.rs index 53fab13d09..9b850abd15 100644 --- a/crates/blockifier/src/execution/deprecated_syscalls/deprecated_syscalls_test.rs +++ b/crates/blockifier/src/execution/deprecated_syscalls/deprecated_syscalls_test.rs @@ -165,22 +165,59 @@ fn test_call_contract() { let mut state = deprecated_create_test_state(); let outer_entry_point_selector = selector_from_name("test_call_contract"); let inner_entry_point_selector = selector_from_name("test_storage_read_write"); + let (key, value) = (stark_felt!(405_u16), stark_felt!(48_u8)); + let inner_calldata = calldata![key, value]; let calldata = calldata![ stark_felt!(TEST_CONTRACT_ADDRESS), // Contract address. inner_entry_point_selector.0, // Function selector. stark_felt!(2_u8), // Calldata length. - stark_felt!(405_u16), // Calldata: address. - stark_felt!(48_u8) // Calldata: value. + key, // Calldata: address. + value // Calldata: value. ]; let entry_point_call = CallEntryPoint { entry_point_selector: outer_entry_point_selector, - calldata, + calldata: calldata.clone(), ..trivial_external_entry_point() }; - assert_eq!( - entry_point_call.execute_directly(&mut state).unwrap().execution, - CallExecution::from_retdata(retdata![stark_felt!(48_u8)]) - ); + let call_info = entry_point_call.clone().execute_directly(&mut state).unwrap(); + + let expected_execution = CallExecution { retdata: retdata![value], ..Default::default() }; + let expected_inner_call_info = CallInfo { + call: CallEntryPoint { + class_hash: Some(class_hash!(TEST_CLASS_HASH)), + code_address: Some(contract_address!(TEST_CONTRACT_ADDRESS)), + entry_point_selector: inner_entry_point_selector, + calldata: inner_calldata, + storage_address: contract_address!(TEST_CONTRACT_ADDRESS), + caller_address: contract_address!(TEST_CONTRACT_ADDRESS), + ..trivial_external_entry_point() + }, + execution: expected_execution.clone(), + vm_resources: VmExecutionResources { n_steps: 41, ..Default::default() }, + storage_read_values: vec![StarkFelt::ZERO, stark_felt!(value)], + accessed_storage_keys: HashSet::from([StorageKey(patricia_key!(key))]), + ..Default::default() + }; + let expected_call_info = CallInfo { + inner_calls: vec![expected_inner_call_info], + call: CallEntryPoint { + class_hash: Some(class_hash!(TEST_CLASS_HASH)), + code_address: Some(contract_address!(TEST_CONTRACT_ADDRESS)), + entry_point_selector: outer_entry_point_selector, + calldata, + storage_address: contract_address!(TEST_CONTRACT_ADDRESS), + ..trivial_external_entry_point() + }, + execution: expected_execution, + vm_resources: VmExecutionResources { + n_steps: 79, + builtin_instance_counter: HashMap::from([(RANGE_CHECK_BUILTIN_NAME.to_string(), 1)]), + ..Default::default() + }, + ..Default::default() + }; + + assert_eq!(expected_call_info, call_info); } #[test]