Skip to content

🗞️ foundry scripts for LayerZero - #1334

Merged
ravinagill15 merged 17 commits into
mainfrom
feat/foundry-scripts
Jul 10, 2025
Merged

🗞️ foundry scripts for LayerZero#1334
ravinagill15 merged 17 commits into
mainfrom
feat/foundry-scripts

Conversation

@shankars99

@shankars99 shankars99 commented Feb 28, 2025

Copy link
Copy Markdown
Collaborator

Scripting in foundry

Across LayerZero we have a bunch of scripts -
Krak's Gas Profiling - https://github.com/LayerZero-Labs/devtools/tree/main/examples/oft/scripts
Dan's lzReceive Simulate - https://github.com/DanL0/integrations-foundry-tooling

Some of these scripts are baked into examples or are stand alone repositories. This PR aims to fix that by:

  1. Creating a new package @layerzerolabs/script-devtools-evm-foundry located at /packages/script-devtools-evm-foundry (following what we do with TestHelper)
  2. Create a new level 1 script - LZScripts that exports scripts internal to it
  3. Internal scripts (level 2 scripts) - (GasProfile and SimulateReceive) these actually implement the foundry script.

Doing this not only gives developers the ability to import these helpful scripts into their packages

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;

import { console } from "forge-std/console.sol";

import { LZScripts } from "@layerzerolabs/script-devtools-evm-foundry/script/LZScripts.s.sol";

contract LZScript is LZScripts {
    function run() public pure override {
        console.log("Hello, World!");
    }
}

But also run them from the terminal due to the compilation of script/LZScript.s.sol generating the artifacts for all the Scripts with a run() function.

$ forge script SimulateReceive
[⠊] Compiling...
No files changed, compilation skipped
Traces:
  [1406766] → new SimulateReceive@0x9f7cF1d1F558E57ef88a59ac3D47214eF25B6A06
    └─ ← [Return] 6916 bytes of code

  [6585] SimulateReceive::run()
    ├─ [0] VM::ffi(["curl", "-X", "GET", "https://scan.layerzero-api.com/v1/messages/tx/0x88a79d59222628aba22c5c616580212c80beae353aaa8ffbd3976dd5aa5d12f8", "-H 'accept: application/json'"])
    │   └─ ← [Revert] vm.ffi: FFI is disabled; add the `--ffi` flag to allow tests to call external commands
    └─ ← [Revert] vm.ffi: FFI is disabled; add the `--ffi` flag to allow tests to call external commands


Gas used: 27649
Error: script failed: vm.ffi: FFI is disabled; add the `--ffi` flag to allow tests to call external commands

(This fails because I didn't use the right flags)

Note: This works for scripts that have run() implemented. So if it is a custom implementation like Gas Profiler you should be creating a new script under script/

Comment thread packages/script-devtools-evm-foundry/CHANGELOG.md
@St0rmBr3w

Copy link
Copy Markdown
Contributor

Question I have is should we change the lower level scripts structure to make them more easily callable at the top level via this import?

@St0rmBr3w

Copy link
Copy Markdown
Contributor

I think this is the best way to go, we should prioritize implementing this package.

Comment thread packages/script-devtools-evm-foundry/script/LZScripts.s.sol
@shankars99
shankars99 marked this pull request as ready for review March 7, 2025 20:46

@ryandgoulding ryandgoulding left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requires rebase

@shankars99
shankars99 marked this pull request as draft March 28, 2025 15:47
shankars99 and others added 11 commits July 7, 2025 14:28
Signed-off-by: shankar <shankar@layerzerolabs.org>
Signed-off-by: shankar <shankar@layerzerolabs.org>
Signed-off-by: shankar <shankar@layerzerolabs.org>
…ride it in foundry.toml

Signed-off-by: shankar <shankar@layerzerolabs.org>
Signed-off-by: shankar <shankar@layerzerolabs.org>
Signed-off-by: shankar <shankar@layerzerolabs.org>
Signed-off-by: shankar <shankar@layerzerolabs.org>
Signed-off-by: shankar <shankar@layerzerolabs.org>
Signed-off-by: shankar <shankar@layerzerolabs.org>
@ravinagill15
ravinagill15 force-pushed the feat/foundry-scripts branch from 5ccd540 to c0efbc7 Compare July 7, 2025 21:28
@ravinagill15
ravinagill15 marked this pull request as ready for review July 8, 2025 18:14
@ravinagill15
ravinagill15 requested a review from St0rmBr3w July 8, 2025 18:14
Comment thread packages/toolbox-foundry/src/forge-std
Comment thread tests-user/lib/bats-assert

@St0rmBr3w St0rmBr3w left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ravinagill15
ravinagill15 requested a review from a team July 10, 2025 17:15

@ItsAdel ItsAdel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit, but everything looks good to me

@ravinagill15
ravinagill15 merged commit 37f8cf0 into main Jul 10, 2025
11 checks passed
@ravinagill15
ravinagill15 deleted the feat/foundry-scripts branch July 10, 2025 19:05
shankars99 added a commit that referenced this pull request Jul 20, 2025
Signed-off-by: shankar <shankar@layerzerolabs.org>
Co-authored-by: ravinagill15 <ravina@layerzerolabs.org>
mattsse pushed a commit to mattsse/devtools that referenced this pull request Aug 12, 2025
Signed-off-by: shankar <shankar@layerzerolabs.org>
Co-authored-by: ravinagill15 <ravina@layerzerolabs.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants