From ca5b290b6371973e21ae703d77a82aabead34744 Mon Sep 17 00:00:00 2001 From: Maksymilian Demitraszek Date: Tue, 23 Apr 2024 18:57:08 +0200 Subject: [PATCH 01/12] Updated the interface --- .../tests/integration/l1_handler_executor.rs | 9 ++------- snforge_std/src/cheatcodes/l1_handler.cairo | 20 +++++++++---------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/crates/forge/tests/integration/l1_handler_executor.rs b/crates/forge/tests/integration/l1_handler_executor.rs index cc871ec66a..fcd2511dcc 100644 --- a/crates/forge/tests/integration/l1_handler_executor.rs +++ b/crates/forge/tests/integration/l1_handler_executor.rs @@ -46,10 +46,7 @@ fn l1_handler_execute() { selector!("process_l1_message") ); - l1_handler.from_address = 0x123; - l1_handler.payload = payload.span(); - - l1_handler.execute().unwrap(); + l1_handler.execute(0x123, payload.span()).unwrap(); let dispatcher = IBalanceTokenDispatcher { contract_address }; assert(dispatcher.get_balance() == 42, dispatcher.get_balance()); @@ -69,9 +66,7 @@ fn l1_handler_execute() { selector!("panicking_l1_handler") ); - l1_handler.from_address = 0x123; - l1_handler.payload = array![].span(); - match l1_handler.execute() { + match l1_handler.execute(0x123, array![].span()) { Result::Ok(_) => panic_with_felt252('should have panicked'), Result::Err(panic_data) => { assert(*panic_data.at(0) == 'custom', 'Wrong 1st panic datum'); diff --git a/snforge_std/src/cheatcodes/l1_handler.cairo b/snforge_std/src/cheatcodes/l1_handler.cairo index e85e849f17..5ff54abe35 100644 --- a/snforge_std/src/cheatcodes/l1_handler.cairo +++ b/snforge_std/src/cheatcodes/l1_handler.cairo @@ -5,29 +5,27 @@ use super::super::_cheatcode::handle_cheatcode; #[derive(Drop, Clone)] struct L1Handler { - contract_address: ContractAddress, - function_selector: felt252, - from_address: felt252, - payload: Span::, + target: ContractAddress, + selector: felt252, } trait L1HandlerTrait { - fn new(contract_address: ContractAddress, function_selector: felt252) -> L1Handler; - fn execute(self: L1Handler) -> SyscallResult<()>; + fn new(target: ContractAddress, selector: felt252) -> L1Handler; + fn execute(self: L1Handler, from_address: felt252, payload: Span::) -> SyscallResult<()>; } impl L1HandlerImpl of L1HandlerTrait { - fn new(contract_address: ContractAddress, function_selector: felt252) -> L1Handler { + fn new(target: ContractAddress, selector: felt252) -> L1Handler { L1Handler { - contract_address, function_selector, from_address: 0, payload: array![].span(), + target, selector, } } - fn execute(self: L1Handler) -> SyscallResult<()> { + fn execute(self: L1Handler, from_address: felt252, payload: Span::) -> SyscallResult<()> { let mut inputs: Array:: = array![ - self.contract_address.into(), self.function_selector, self.from_address, + self.target.into(), self.selector, from_address.into(), ]; - self.payload.serialize(ref inputs); + payload.serialize(ref inputs); let mut outputs = handle_cheatcode(cheatcode::<'l1_handler_execute'>(inputs.span())); let exit_code = *outputs.pop_front().unwrap(); From d9d7b36c9e292a0664701113fdf83425beb79cbf Mon Sep 17 00:00:00 2001 From: Maksymilian Demitraszek Date: Mon, 29 Apr 2024 16:13:21 +0200 Subject: [PATCH 02/12] Added docs --- snforge_std/src/cheatcodes/l1_handler.cairo | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/snforge_std/src/cheatcodes/l1_handler.cairo b/snforge_std/src/cheatcodes/l1_handler.cairo index 5ff54abe35..fb69aacc2c 100644 --- a/snforge_std/src/cheatcodes/l1_handler.cairo +++ b/snforge_std/src/cheatcodes/l1_handler.cairo @@ -15,12 +15,19 @@ trait L1HandlerTrait { } impl L1HandlerImpl of L1HandlerTrait { + /// `target` - The target starknet contract address + /// `selector` - Selector of a `#[l1_handler]` function + /// Returns a structure refering to a L1 handler function fn new(target: ContractAddress, selector: felt252) -> L1Handler { L1Handler { target, selector, } } + /// `self` - `L1Handler` structure refering to a L1 handler function + /// `from_address` - Ethereum address of the contract that you want to a emulate message from + /// `payload` - The message payload that may contain any Cairo data structure that can be serialized with + /// Executes the L1 handler with the given data fn execute(self: L1Handler, from_address: felt252, payload: Span::) -> SyscallResult<()> { let mut inputs: Array:: = array![ self.target.into(), self.selector, from_address.into(), From 8fd81a7e5bad3a553a3e6ab23ac5283859131809 Mon Sep 17 00:00:00 2001 From: Maksymilian Demitraszek Date: Wed, 8 May 2024 11:01:20 +0200 Subject: [PATCH 03/12] Updated --- .../l1_handler_execute_checker.cairo | 4 +++ .../tests/integration/l1_handler_executor.rs | 27 +++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/crates/forge/tests/data/contracts/l1_handler_execute_checker.cairo b/crates/forge/tests/data/contracts/l1_handler_execute_checker.cairo index 6ce9b1d270..46a596b068 100644 --- a/crates/forge/tests/data/contracts/l1_handler_execute_checker.cairo +++ b/crates/forge/tests/data/contracts/l1_handler_execute_checker.cairo @@ -47,6 +47,10 @@ mod l1_handler_executor { self.token_id.write(data.token_id); } + fn panicking(ref self: ContractState) { + panic(array!['custom', 'panic']); + } + #[l1_handler] fn panicking_l1_handler(ref self: ContractState, from_address: felt252) { panic(array!['custom', 'panic']); diff --git a/crates/forge/tests/integration/l1_handler_executor.rs b/crates/forge/tests/integration/l1_handler_executor.rs index fcd2511dcc..3a42f63c1a 100644 --- a/crates/forge/tests/integration/l1_handler_executor.rs +++ b/crates/forge/tests/integration/l1_handler_executor.rs @@ -1,7 +1,7 @@ use indoc::indoc; use std::path::Path; use test_utils::runner::{assert_passed, Contract}; -use test_utils::running_tests::run_test_case; +use test_utils::running_tests::run_test_case; use test_utils::test_case; #[test] @@ -25,6 +25,8 @@ fn l1_handler_execute() { use array::{ArrayTrait, SpanTrait}; use core::result::ResultTrait; use snforge_std::{declare, ContractClassTrait, L1Handler, L1HandlerTrait}; + use snforge_std::errors::{ SyscallResultStringErrorTrait, PanicDataOrString }; + use starknet::{ContractAddress, contract_address_const}; #[test] fn l1_handler_execute() { @@ -74,7 +76,28 @@ fn l1_handler_execute() { }, } } - "# + + #[test] + fn l1_handler_function_missing() { + let calldata = array![0x123]; + + let contract = declare("l1_handler_executor").unwrap(); + let (contract_address, _) = contract.deploy(@calldata).unwrap(); + + + let mut l1_handler = L1HandlerTrait::new( + contract_address, + selector!("this_does_not_exist") + ); + + match l1_handler.execute(0x123, array![].span()){ + Result::Ok(_) => panic_with_felt252('should have panicked'), + Result::Err(_) => { + // Would be nice to assert the error here once it is be possible in cairo + }, + } + } + "# ), Contract::from_code_path( "l1_handler_executor".to_string(), From 9e72d61c78abb6b3e813dde39be54668e2af635a Mon Sep 17 00:00:00 2001 From: Maksymilian Demitraszek Date: Wed, 8 May 2024 11:01:39 +0200 Subject: [PATCH 04/12] Update --- .../tests/integration/l1_handler_executor.rs | 1 - docs/src/appendix/cheatcodes/block_number.md | 2 +- .../appendix/cheatcodes/l1_handler_execute.md | 83 ++----------------- snforge_std/src/cheatcodes/l1_handler.cairo | 4 +- 4 files changed, 12 insertions(+), 78 deletions(-) diff --git a/crates/forge/tests/integration/l1_handler_executor.rs b/crates/forge/tests/integration/l1_handler_executor.rs index 3a42f63c1a..f1d6e50186 100644 --- a/crates/forge/tests/integration/l1_handler_executor.rs +++ b/crates/forge/tests/integration/l1_handler_executor.rs @@ -26,7 +26,6 @@ fn l1_handler_execute() { use core::result::ResultTrait; use snforge_std::{declare, ContractClassTrait, L1Handler, L1HandlerTrait}; use snforge_std::errors::{ SyscallResultStringErrorTrait, PanicDataOrString }; - use starknet::{ContractAddress, contract_address_const}; #[test] fn l1_handler_execute() { diff --git a/docs/src/appendix/cheatcodes/block_number.md b/docs/src/appendix/cheatcodes/block_number.md index 6433f2ac87..dc2a9c5376 100644 --- a/docs/src/appendix/cheatcodes/block_number.md +++ b/docs/src/appendix/cheatcodes/block_number.md @@ -15,4 +15,4 @@ Changes the block number for the given target. # `stop_roll` > `fn stop_roll(target: CheatTarget)` -Cancels the `roll` / `start_roll` for the given target. \ No newline at end of file +Cancels the `roll` / `start_roll` for the given target. diff --git a/docs/src/appendix/cheatcodes/l1_handler_execute.md b/docs/src/appendix/cheatcodes/l1_handler_execute.md index 189a5dcacd..3ec416aae6 100644 --- a/docs/src/appendix/cheatcodes/l1_handler_execute.md +++ b/docs/src/appendix/cheatcodes/l1_handler_execute.md @@ -1,81 +1,16 @@ # `l1_handler_execute` -> `fn execute(self: L1Handler) -> SyscallResult<()>` - -Executes a `#[l1_handler]` function to mock a -[message](https://docs.starknet.io/documentation/architecture_and_concepts/L1-L2_Communication/messaging-mechanism/) -arriving from Ethereum. - -> 📝 **Note** -> -> Execution of the `#[l1_handler]` function may panic like any other function. -> It works like a regular `SafeDispatcher` would with a function call. -> For more info about asserting panic data check out [handling panic errors](../../testing/contracts.md#handling-errors) - - -```rust -struct L1Handler { - contract_address: ContractAddress, - function_selector: felt252, - from_address: felt252, - payload: Span::, -} -``` - -where: - -- `contract_address` - The target contract address -- `function_selector` - Selector of the `#[l1_handler]` function -- `from_address` - Ethereum address of the contract that sends the message -- `payload` - The message payload that may contain any Cairo data structure that can be serialized with -[Serde](https://book.cairo-lang.org/appendix-03-derivable-traits.html?highlight=serde#serializing-with-serde) - -It is important to note that when executing the `l1_handler`, -the `from_address` may be checked as any L1 contract can call any L2 contract. +> `fn new(target: ContractAddress, selector: felt252) -> L1Handler` -For a contract implementation: +`target` - The target starknet contract address +`selector` - Selector of a `#[l1_handler]` function -```rust -// ... -#[storage] -struct Storage { - l1_allowed: felt252, - //... -} +Returns a structure referring to a L1 handler function. -//... - -#[l1_handler] -fn process_l1_message(ref self: ContractState, from_address: felt252, data: Span) { - assert(from_address == self.l1_allowed.read(), 'Unauthorized l1 contract'); -} -// ... -``` - -We can use `execute` method to test the execution of the `#[l1_handler]` function that is -not available through contracts dispatcher: - -```rust -use snforge_std::L1Handler; - -#[test] -fn test_l1_handler_execute() { - // ... - let data: Array = array![1, 2]; - - let mut payload_buffer: Array = ArrayTrait::new(); - // Note the serialization here. - data.serialize(ref payload_buffer); - - let mut l1_handler = L1HandlerTrait::new( - contract_address, - selector!("process_l1_message") - ); +> `fn execute(self: L1Handler) -> SyscallResult<()>` - l1_handler.from_address = 0x123; - l1_handler.payload = payload.span(); +`self` - `L1Handler` structure refering to a L1 handler function +`from_address` - Ethereum address of the contract that you want to a emulate message from +`payload` - The message payload that may contain any Cairo data structure that can be serialized with - l1_handler.execute().unwrap(); - //... -} -``` +Mocks a L1 -> L2 message from Ethereum handled by the given L1 handler function. diff --git a/snforge_std/src/cheatcodes/l1_handler.cairo b/snforge_std/src/cheatcodes/l1_handler.cairo index fb69aacc2c..9475c7779d 100644 --- a/snforge_std/src/cheatcodes/l1_handler.cairo +++ b/snforge_std/src/cheatcodes/l1_handler.cairo @@ -17,7 +17,7 @@ trait L1HandlerTrait { impl L1HandlerImpl of L1HandlerTrait { /// `target` - The target starknet contract address /// `selector` - Selector of a `#[l1_handler]` function - /// Returns a structure refering to a L1 handler function + /// Returns a structure referring to a L1 handler function fn new(target: ContractAddress, selector: felt252) -> L1Handler { L1Handler { target, selector, @@ -27,7 +27,7 @@ impl L1HandlerImpl of L1HandlerTrait { /// `self` - `L1Handler` structure refering to a L1 handler function /// `from_address` - Ethereum address of the contract that you want to a emulate message from /// `payload` - The message payload that may contain any Cairo data structure that can be serialized with - /// Executes the L1 handler with the given data + /// Mocks a L1 -> L2 message from Ethereum handled by the given L1 handler function. fn execute(self: L1Handler, from_address: felt252, payload: Span::) -> SyscallResult<()> { let mut inputs: Array:: = array![ self.target.into(), self.selector, from_address.into(), From 55202abe384ad915aa59b6f59bd32e56e561debe Mon Sep 17 00:00:00 2001 From: Maksymilian Demitraszek Date: Wed, 8 May 2024 11:46:14 +0200 Subject: [PATCH 05/12] Removed dead code --- .../tests/data/contracts/l1_handler_execute_checker.cairo | 4 ---- 1 file changed, 4 deletions(-) diff --git a/crates/forge/tests/data/contracts/l1_handler_execute_checker.cairo b/crates/forge/tests/data/contracts/l1_handler_execute_checker.cairo index 46a596b068..6ce9b1d270 100644 --- a/crates/forge/tests/data/contracts/l1_handler_execute_checker.cairo +++ b/crates/forge/tests/data/contracts/l1_handler_execute_checker.cairo @@ -47,10 +47,6 @@ mod l1_handler_executor { self.token_id.write(data.token_id); } - fn panicking(ref self: ContractState) { - panic(array!['custom', 'panic']); - } - #[l1_handler] fn panicking_l1_handler(ref self: ContractState, from_address: felt252) { panic(array!['custom', 'panic']); From bb1138851414f48772b0c2c0f09eb43f21b7ebf2 Mon Sep 17 00:00:00 2001 From: Maksymilian Demitraszek Date: Wed, 8 May 2024 20:16:11 +0200 Subject: [PATCH 06/12] updated --- CHANGELOG.md | 5 +++++ .../tests/data/trace_resources/tests/test_l1_handler.cairo | 5 +---- crates/forge/tests/integration/gas.rs | 5 +---- crates/forge/tests/integration/l1_handler_executor.rs | 4 ++-- crates/forge/tests/integration/trace.rs | 5 +---- 5 files changed, 10 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42fb6e1793..a3bdc5f29c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Forge +#### Changed + +### Forge +- `L1HandlerTrait::execute()` takes source address and payloads as arguments [MORE](https://foundry-rs.github.io/starknet-foundry/appendix/cheatcodes/l1_handler_execute.html) + #### Removed - `event_name_hash` removal, in favour of `selector!` usage diff --git a/crates/forge/tests/data/trace_resources/tests/test_l1_handler.cairo b/crates/forge/tests/data/trace_resources/tests/test_l1_handler.cairo index 4d75c00181..927671244e 100644 --- a/crates/forge/tests/data/trace_resources/tests/test_l1_handler.cairo +++ b/crates/forge/tests/data/trace_resources/tests/test_l1_handler.cairo @@ -15,8 +15,5 @@ fn test_l1_handler() { let mut l1_handler = L1HandlerTrait::new(checker_address, selector!("handle_l1_message")); - l1_handler.from_address = 123; - l1_handler.payload = array![proxy_address.into(), empty_hash.into(), 2].span(); - - l1_handler.execute().unwrap(); + l1_handler.execute(123, array![proxy_address.into(), empty_hash.into(), 2].span()).unwrap(); } diff --git a/crates/forge/tests/integration/gas.rs b/crates/forge/tests/integration/gas.rs index aac1380179..6a3cfd6879 100644 --- a/crates/forge/tests/integration/gas.rs +++ b/crates/forge/tests/integration/gas.rs @@ -675,10 +675,7 @@ fn l1_handler_cost() { let mut l1_handler = L1HandlerTrait::new(contract_address, selector!("handle_l1_message")); - l1_handler.from_address = 123; - l1_handler.payload = array![].span(); - - l1_handler.execute().unwrap(); + l1_handler.execute(123, array![].span()).unwrap(); } "# ), diff --git a/crates/forge/tests/integration/l1_handler_executor.rs b/crates/forge/tests/integration/l1_handler_executor.rs index f1d6e50186..e47a08a615 100644 --- a/crates/forge/tests/integration/l1_handler_executor.rs +++ b/crates/forge/tests/integration/l1_handler_executor.rs @@ -1,7 +1,7 @@ use indoc::indoc; use std::path::Path; use test_utils::runner::{assert_passed, Contract}; -use test_utils::running_tests::run_test_case; +use test_utils::running_tests::run_test_case; use test_utils::test_case; #[test] @@ -96,7 +96,7 @@ fn l1_handler_execute() { }, } } - "# + "# ), Contract::from_code_path( "l1_handler_executor".to_string(), diff --git a/crates/forge/tests/integration/trace.rs b/crates/forge/tests/integration/trace.rs index 8774203032..cb91ea7cee 100644 --- a/crates/forge/tests/integration/trace.rs +++ b/crates/forge/tests/integration/trace.rs @@ -896,10 +896,7 @@ fn trace_l1_handler() { let mut l1_handler = L1HandlerTrait::new(checker_address, selector!("handle_l1_message")); - l1_handler.from_address = 123; - l1_handler.payload = array![proxy_address.into()].span(); - - l1_handler.execute().unwrap(); + l1_handler.execute(123, array![proxy_address.into()].span()).unwrap(); assert_trace(get_call_trace(), proxy_address, checker_address); } From cf0ff41b0b9faab13128d249457b6ec0fb721ba6 Mon Sep 17 00:00:00 2001 From: Maksymilian Demitraszek Date: Wed, 8 May 2024 20:36:59 +0200 Subject: [PATCH 07/12] Fixes --- snforge_std/src/cheatcodes/l1_handler.cairo | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/snforge_std/src/cheatcodes/l1_handler.cairo b/snforge_std/src/cheatcodes/l1_handler.cairo index 9475c7779d..81be08d0cc 100644 --- a/snforge_std/src/cheatcodes/l1_handler.cairo +++ b/snforge_std/src/cheatcodes/l1_handler.cairo @@ -11,7 +11,9 @@ struct L1Handler { trait L1HandlerTrait { fn new(target: ContractAddress, selector: felt252) -> L1Handler; - fn execute(self: L1Handler, from_address: felt252, payload: Span::) -> SyscallResult<()>; + fn execute( + self: L1Handler, from_address: felt252, payload: Span:: + ) -> SyscallResult<()>; } impl L1HandlerImpl of L1HandlerTrait { @@ -19,16 +21,16 @@ impl L1HandlerImpl of L1HandlerTrait { /// `selector` - Selector of a `#[l1_handler]` function /// Returns a structure referring to a L1 handler function fn new(target: ContractAddress, selector: felt252) -> L1Handler { - L1Handler { - target, selector, - } + L1Handler { target, selector, } } - /// `self` - `L1Handler` structure refering to a L1 handler function + /// `self` - `L1Handler` structure referring to a L1 handler function /// `from_address` - Ethereum address of the contract that you want to a emulate message from /// `payload` - The message payload that may contain any Cairo data structure that can be serialized with /// Mocks a L1 -> L2 message from Ethereum handled by the given L1 handler function. - fn execute(self: L1Handler, from_address: felt252, payload: Span::) -> SyscallResult<()> { + fn execute( + self: L1Handler, from_address: felt252, payload: Span:: + ) -> SyscallResult<()> { let mut inputs: Array:: = array![ self.target.into(), self.selector, from_address.into(), ]; From 6219da7da5abc4f7a52b7be7aacc6cc4cc685acd Mon Sep 17 00:00:00 2001 From: Maksymilian Demitraszek Date: Wed, 8 May 2024 20:56:06 +0200 Subject: [PATCH 08/12] fix --- docs/src/appendix/cheatcodes/l1_handler_execute.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/appendix/cheatcodes/l1_handler_execute.md b/docs/src/appendix/cheatcodes/l1_handler_execute.md index 3ec416aae6..581e4933e4 100644 --- a/docs/src/appendix/cheatcodes/l1_handler_execute.md +++ b/docs/src/appendix/cheatcodes/l1_handler_execute.md @@ -9,7 +9,7 @@ Returns a structure referring to a L1 handler function. > `fn execute(self: L1Handler) -> SyscallResult<()>` -`self` - `L1Handler` structure refering to a L1 handler function +`self` - `L1Handler` structure referring to a L1 handler function `from_address` - Ethereum address of the contract that you want to a emulate message from `payload` - The message payload that may contain any Cairo data structure that can be serialized with From d9d19707454689ad89b88059fd80f5464392d763 Mon Sep 17 00:00:00 2001 From: Maksymilian Demitraszek Date: Fri, 10 May 2024 10:15:59 +0200 Subject: [PATCH 09/12] Requested changes --- docs/src/appendix/cheatcodes/l1_handler_execute.md | 9 --------- snforge_std/src/cheatcodes/l1_handler.cairo | 6 +++--- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/docs/src/appendix/cheatcodes/l1_handler_execute.md b/docs/src/appendix/cheatcodes/l1_handler_execute.md index 581e4933e4..3de2670756 100644 --- a/docs/src/appendix/cheatcodes/l1_handler_execute.md +++ b/docs/src/appendix/cheatcodes/l1_handler_execute.md @@ -1,16 +1,7 @@ # `l1_handler_execute` > `fn new(target: ContractAddress, selector: felt252) -> L1Handler` - -`target` - The target starknet contract address -`selector` - Selector of a `#[l1_handler]` function - Returns a structure referring to a L1 handler function. > `fn execute(self: L1Handler) -> SyscallResult<()>` - -`self` - `L1Handler` structure referring to a L1 handler function -`from_address` - Ethereum address of the contract that you want to a emulate message from -`payload` - The message payload that may contain any Cairo data structure that can be serialized with - Mocks a L1 -> L2 message from Ethereum handled by the given L1 handler function. diff --git a/snforge_std/src/cheatcodes/l1_handler.cairo b/snforge_std/src/cheatcodes/l1_handler.cairo index 81be08d0cc..81dddcd173 100644 --- a/snforge_std/src/cheatcodes/l1_handler.cairo +++ b/snforge_std/src/cheatcodes/l1_handler.cairo @@ -18,7 +18,7 @@ trait L1HandlerTrait { impl L1HandlerImpl of L1HandlerTrait { /// `target` - The target starknet contract address - /// `selector` - Selector of a `#[l1_handler]` function + /// `selector` - Selector of a `#[l1_handler]` function. Can be acquired with `selector!("function_handler_name")` marco /// Returns a structure referring to a L1 handler function fn new(target: ContractAddress, selector: felt252) -> L1Handler { L1Handler { target, selector, } @@ -26,8 +26,8 @@ impl L1HandlerImpl of L1HandlerTrait { /// `self` - `L1Handler` structure referring to a L1 handler function /// `from_address` - Ethereum address of the contract that you want to a emulate message from - /// `payload` - The message payload that may contain any Cairo data structure that can be serialized with - /// Mocks a L1 -> L2 message from Ethereum handled by the given L1 handler function. + /// `payload` - The handlers' function arguments serialized with `Serde` + /// Mocks a L1 -> L2 message from Ethereum handled by the given L1 handler function fn execute( self: L1Handler, from_address: felt252, payload: Span:: ) -> SyscallResult<()> { From 9a0814d5798f82ad567222c9f771a6024e4f7b03 Mon Sep 17 00:00:00 2001 From: Maksymilian Demitraszek Date: Fri, 10 May 2024 13:20:30 +0200 Subject: [PATCH 10/12] adjusted doc --- snforge_std/src/cheatcodes/l1_handler.cairo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snforge_std/src/cheatcodes/l1_handler.cairo b/snforge_std/src/cheatcodes/l1_handler.cairo index 81dddcd173..67506d9112 100644 --- a/snforge_std/src/cheatcodes/l1_handler.cairo +++ b/snforge_std/src/cheatcodes/l1_handler.cairo @@ -25,7 +25,7 @@ impl L1HandlerImpl of L1HandlerTrait { } /// `self` - `L1Handler` structure referring to a L1 handler function - /// `from_address` - Ethereum address of the contract that you want to a emulate message from + /// `from_address` - Ethereum address of the contract that you want to be the message sender /// `payload` - The handlers' function arguments serialized with `Serde` /// Mocks a L1 -> L2 message from Ethereum handled by the given L1 handler function fn execute( From 991a868850317e10aead3c1cdcd13c667fc435de Mon Sep 17 00:00:00 2001 From: Maksymilian Demitraszek Date: Fri, 10 May 2024 14:30:09 +0200 Subject: [PATCH 11/12] fix changelog --- CHANGELOG.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e637eae8b5..440c6a9385 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,16 +13,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - New required flag `--type` to `account add` command -## [0.23.0] - 2024-05-08 - ### Forge #### Changed -### Forge - `L1HandlerTrait::execute()` takes source address and payloads as arguments [MORE](https://foundry-rs.github.io/starknet-foundry/appendix/cheatcodes/l1_handler_execute.html) +## [0.23.0] - 2024-05-08 + +### Forge + #### Removed - `event_name_hash` removal, in favour of `selector!` usage From 1acd6d3de4c7c90f0774cb0cb8a9f47bbb685f09 Mon Sep 17 00:00:00 2001 From: Maksymilian Demitraszek Date: Tue, 14 May 2024 15:05:46 +0200 Subject: [PATCH 12/12] fixes --- CHANGELOG.md | 2 +- docs/src/SUMMARY.md | 2 +- docs/src/appendix/cheatcodes.md | 2 +- .../cheatcodes/{l1_handler_execute.md => l1_handler.md} | 2 +- snforge_std/src/cheatcodes/l1_handler.cairo | 5 +++-- 5 files changed, 7 insertions(+), 6 deletions(-) rename docs/src/appendix/cheatcodes/{l1_handler_execute.md => l1_handler.md} (91%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 440c6a9385..7e6a0de054 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #### Changed -- `L1HandlerTrait::execute()` takes source address and payloads as arguments [MORE](https://foundry-rs.github.io/starknet-foundry/appendix/cheatcodes/l1_handler_execute.html) +- `L1HandlerTrait::execute()` takes source address and payloads as arguments [Read more here](https://foundry-rs.github.io/starknet-foundry/appendix/cheatcodes/l1_handler.html) ## [0.23.0] - 2024-05-08 diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index 1ae817552d..bdeda7e8dc 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -66,7 +66,7 @@ * [sequencer_address](appendix/cheatcodes/sequencer_address.md) * [get_class_hash](appendix/cheatcodes/get_class_hash.md) * [replace_bytecode](appendix/cheatcodes/replace_bytecode.md) - * [l1_handler_execute](appendix/cheatcodes/l1_handler_execute.md) + * [l1_handler](appendix/cheatcodes/l1_handler.md) * [spy_events](appendix/cheatcodes/spy_events.md) * [store](appendix/cheatcodes/store.md) * [load](appendix/cheatcodes/load.md) diff --git a/docs/src/appendix/cheatcodes.md b/docs/src/appendix/cheatcodes.md index 9ad4613349..e121b7aa32 100644 --- a/docs/src/appendix/cheatcodes.md +++ b/docs/src/appendix/cheatcodes.md @@ -22,7 +22,7 @@ - [`stop_mock_call`](cheatcodes/mock_call.md#stop_mock_call) - cancels the `mock_call` / `start_mock_call` for an entry point - [`get_class_hash`](cheatcodes/get_class_hash.md) - retrieves a class hash of a contract - [`replace_bytecode`](cheatcodes/replace_bytecode.md) - replace the class hash of a contract -- [`l1_handler_execute`](cheatcodes/l1_handler_execute.md) - executes a `#[l1_handler]` function to mock a message arriving from Ethereum +- [`l1_handler`](cheatcodes/l1_handler.md) - executes a `#[l1_handler]` function to mock a message arriving from Ethereum - [`spy_events`](cheatcodes/spy_events.md) - creates `EventSpy` instance which spies on events emitted by contracts - [`store`](cheatcodes/store.md) - stores values in targeted contact's storage - [`load`](cheatcodes/load.md) - loads values directly from targeted contact's storage diff --git a/docs/src/appendix/cheatcodes/l1_handler_execute.md b/docs/src/appendix/cheatcodes/l1_handler.md similarity index 91% rename from docs/src/appendix/cheatcodes/l1_handler_execute.md rename to docs/src/appendix/cheatcodes/l1_handler.md index 3de2670756..5e7c7e9376 100644 --- a/docs/src/appendix/cheatcodes/l1_handler_execute.md +++ b/docs/src/appendix/cheatcodes/l1_handler.md @@ -1,4 +1,4 @@ -# `l1_handler_execute` +# `l1_handler` > `fn new(target: ContractAddress, selector: felt252) -> L1Handler` Returns a structure referring to a L1 handler function. diff --git a/snforge_std/src/cheatcodes/l1_handler.cairo b/snforge_std/src/cheatcodes/l1_handler.cairo index 67506d9112..4c0a19f9cd 100644 --- a/snforge_std/src/cheatcodes/l1_handler.cairo +++ b/snforge_std/src/cheatcodes/l1_handler.cairo @@ -18,16 +18,17 @@ trait L1HandlerTrait { impl L1HandlerImpl of L1HandlerTrait { /// `target` - The target starknet contract address - /// `selector` - Selector of a `#[l1_handler]` function. Can be acquired with `selector!("function_handler_name")` marco + /// `selector` - Selector of a `#[l1_handler]` function. Can be acquired with `selector!("function_handler_name")` macro /// Returns a structure referring to a L1 handler function fn new(target: ContractAddress, selector: felt252) -> L1Handler { L1Handler { target, selector, } } + /// Mocks L1 -> L2 message from Ethereum handled by the given L1 handler function /// `self` - `L1Handler` structure referring to a L1 handler function /// `from_address` - Ethereum address of the contract that you want to be the message sender /// `payload` - The handlers' function arguments serialized with `Serde` - /// Mocks a L1 -> L2 message from Ethereum handled by the given L1 handler function + /// Returns () or panic data if it failed fn execute( self: L1Handler, from_address: felt252, payload: Span:: ) -> SyscallResult<()> {