From 05271967160aceca7d3e257c7ec0880924fec99d Mon Sep 17 00:00:00 2001 From: Tomasz Rejowski <34059895+Arcticae@users.noreply.github.com> Date: Fri, 7 Oct 2022 18:18:13 +0200 Subject: [PATCH] `send_message_to_l2` docs (#948) Co-authored-by: Arkadiusz --- .../02-cheatcodes/send-message-to-l2.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 website/docs/tutorials/07-testing/02-cheatcodes/send-message-to-l2.md diff --git a/website/docs/tutorials/07-testing/02-cheatcodes/send-message-to-l2.md b/website/docs/tutorials/07-testing/02-cheatcodes/send-message-to-l2.md new file mode 100644 index 0000000000..c91e94ad79 --- /dev/null +++ b/website/docs/tutorials/07-testing/02-cheatcodes/send-message-to-l2.md @@ -0,0 +1,28 @@ +# `send_message_to_l2` + +```python +def send_message_to_l2( + fn_name: str, + from_address: int = 0, + to_address: Optional[int] = None, + payload: Optional[CairoOrPythonData] = None, + ) -> None: + ... +``` + +This cheatcode simulates an incoming message from l1 to l2 executed with `fn_name` at `to_address` contract address. +It can be useful when implementing i.e. a token bridge and wanting to test the message consuming behavior. +This cheatcode requires that the contract at `to_address` address has a `@l1_handler` named `fn_name`. + +- `fn_name` — `@l1_handler` function name. +- `from_address` — An l1 address with which the message will be sent. +- `to_address` — A l2 contract's address - the receiver of the message, which implements the called `@l1_handler`. Defaults to the current contract. +- `payload` — `@l1_handler` function parameters, without `from_address`. This can be passed as a dictionary, or as a flat array of ints. Defaults to empty array. + +:::tip +You can leverage [data transformer](README.md#data-transformer) to pass payload as a dictionary instead of a list of numbers. +::: + +:::warning +Do not provide `from_address` (needed for all l1 handlers in StarkNet) in the function's `payload` - this is passed automatically using `from_address` parameter. +::: \ No newline at end of file