diff --git a/crates/evm/src/context.cairo b/crates/evm/src/context.cairo index b9b442c29..29165432a 100644 --- a/crates/evm/src/context.cairo +++ b/crates/evm/src/context.cairo @@ -314,4 +314,9 @@ impl ExecutionContextImpl of ExecutionContextTrait { fn pc(self: @ExecutionContext) -> u32 { *self.program_counter } + + #[inline(always)] + fn append_event(ref self: ExecutionContext, event: Event) { + self.events.append(event); + } } diff --git a/crates/evm/src/machine.cairo b/crates/evm/src/machine.cairo index fbc08f9ba..3c2008a72 100644 --- a/crates/evm/src/machine.cairo +++ b/crates/evm/src/machine.cairo @@ -189,19 +189,10 @@ impl MachineCurrentContextImpl of MachineCurrentContextTrait { current_call_ctx.read_only() } - #[inline(always)] - fn set_read_only(ref self: Machine, value: bool) { - let mut current_call_ctx = self.call_context(); - let mut current_execution_ctx = self.current_context.unbox(); - current_call_ctx.read_only = value; - current_execution_ctx.call_context = BoxTrait::new(current_call_ctx); - self.current_context = BoxTrait::new(current_execution_ctx); - } - #[inline(always)] fn append_event(ref self: Machine, event: Event) { let mut current_execution_ctx = self.current_context.unbox(); - current_execution_ctx.events.append(event); + current_execution_ctx.append_event(event); self.current_context = BoxTrait::new(current_execution_ctx); } diff --git a/crates/evm/src/tests/test_instructions/test_logging_operations.cairo b/crates/evm/src/tests/test_instructions/test_logging_operations.cairo index 4aa5a97c2..d99ef5843 100644 --- a/crates/evm/src/tests/test_instructions/test_logging_operations.cairo +++ b/crates/evm/src/tests/test_instructions/test_logging_operations.cairo @@ -3,7 +3,7 @@ use evm::instructions::LoggingOperationsTrait; use evm::machine::{Machine, MachineCurrentContextTrait}; use evm::memory::MemoryTrait; use evm::stack::StackTrait; -use evm::tests::test_utils::setup_machine; +use evm::tests::test_utils::{setup_machine, setup_machine_with_read_only}; use integer::BoundedInt; use utils::helpers::u256_to_bytes_array; @@ -180,8 +180,7 @@ fn test_exec_log4() { #[available_gas(20000000)] fn test_exec_log1_read_only_context() { // Given - let mut machine = setup_machine(); - machine.set_read_only(true); + let mut machine = setup_machine_with_read_only(); machine.memory.store(BoundedInt::::max(), 0); diff --git a/crates/evm/src/tests/test_utils.cairo b/crates/evm/src/tests/test_utils.cairo index c79b432c3..c6116db92 100644 --- a/crates/evm/src/tests/test_utils.cairo +++ b/crates/evm/src/tests/test_utils.cairo @@ -148,3 +148,43 @@ fn setup_machine_with_calldata(calldata: Span) -> Machine { storage_journal: Default::default(), } } + +fn setup_machine_with_read_only() -> Machine { + Machine { + current_context: BoxTrait::new(setup_execution_context_with_read_only()), + ctx_count: 1, + stack: Default::default(), + memory: Default::default(), + storage_journal: Default::default(), + } +} + +fn setup_execution_context_with_read_only() -> ExecutionContext { + let context_id = 0; + let call_context = setup_call_context_with_read_only(); + let starknet_address: ContractAddress = starknet_address(); + let evm_address: EthAddress = evm_address(); + let return_data = Default::default(); + + ExecutionContextTrait::new( + context_id, + evm_address, + starknet_address, + call_context, + Default::default(), + Default::default(), + return_data, + ) +} + +fn setup_call_context_with_read_only() -> CallContext { + let bytecode: Span = array![1, 2, 3].span(); + let calldata: Span = array![4, 5, 6].span(); + let value: u256 = callvalue(); + let address = evm_address(); + let read_only = true; + let gas_price = 0xaaaaaa; + let gas_limit = 0xffffff; + + CallContextTrait::new(address, bytecode, calldata, value, read_only, gas_limit, gas_price) +}