Skip to content

feat(forge script + anvil): improve ability to run programmatic "tests" against Anvil #5517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Tracked by #8269
Keinberger opened this issue Aug 1, 2023 · 3 comments
Labels
A-reth-anvil Area: reth-anvil C-anvil Command: anvil Cmd-forge-script Command: forge script T-feature Type: feature

Comments

@Keinberger
Copy link

Component

Forge, Anvil

Describe the feature you would like

Background

When running tests using Foundry, it is possible to specify a --rpc-url to the foundry test command. When doing so, Foundry just queries and copies the state of the chain specified at the --rpc-url endpoint to the locally running testing node. Nevertheless, other Smart Contract development frameworks (hardhat) do provide a direct way to publish tests on an actual node, which can be tremendously useful for effective fork and staging testing.

Proposal

Implement test transactions actually being published to anvil when specifying --rpc-url to a local anvil node. This would allow for more accurate fork-testing and external sources being able to use / query transaction data.

This feature could be used to effectively perform fork testing and integrate external sources into the testing environment.

Additional context

Discussed in #5421

@Keinberger Keinberger added the T-feature Type: feature label Aug 1, 2023
@gakonst gakonst added this to Foundry Aug 1, 2023
@github-project-automation github-project-automation bot moved this to Todo in Foundry Aug 1, 2023
@zerosnacks zerosnacks added the C-anvil Command: anvil label Jun 27, 2024
@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 26, 2024
@grandizzy grandizzy removed this from the v1.0.0 milestone Oct 10, 2024
@wavey0x
Copy link

wavey0x commented Oct 23, 2024

Please add this back to the milestones. We rely on Tenderly TestNets (external node) for a shared fork state for devs and UI testing. Currently, foundry scripts are unable to publish contracts or make calls to remote forks.

@zerosnacks
Copy link
Member

zerosnacks commented Oct 23, 2024

Hi @wavey0x, the ticket is still active and being considered but not part of our 1.0 scope as we are planning to build reth-anvil next year which could have this included in the design scope explicitly.

Currently, foundry scripts are unable to publish contracts or make calls to remote forks.

Could you expand on this? Deploying contracts / making calls in Foundry Script inside of vm.startBroadcast / vm.broadcast sections should work as you would expect.

We rely on Tenderly TestNets (external node) for a shared fork state for devs and UI testing

This ticket, to my understanding, is specifically about being able to publish tests. You should be able to fork the testnet URL and locally run tests against it. Scripted interactions through forge script should be possible as previously stated.

@zerosnacks zerosnacks added the A-reth-anvil Area: reth-anvil label Oct 23, 2024
@wavey0x
Copy link

wavey0x commented Oct 24, 2024

thanks @zerosnacks

here's some stuff ive learned in regard to getting a Tenderly fork env spun up and synced with Foundry:

  • all transactions must be within a startBroadcast / endBroadcast code block otherwise the transaction never reaches the rpc provider
  • you can impersonate in broadcasts by passing --unlocked flag to your command and the associated wallet address into vm.startBroadcast()
  • cheatcodes must be manually synced between foundry and fork rpc (e.g. vm.roll() , vm.warp(), vm.deal()) ... this means making RPC calls by hand

i've made a TenderlyHelper script that can be inherited and used to make sure that basic cheat codes are synced between tenderly and local env
https://gist.github.com/wavey0x/e14d44c2d3e9fad4a3fd190791667901

@zerosnacks zerosnacks added the Cmd-forge-script Command: forge script label Feb 13, 2025
@zerosnacks zerosnacks changed the title Implement support for running tests on Anvil feat(forge script + anvil): improve ability to run programmatic "tests" against Anvil Feb 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-reth-anvil Area: reth-anvil C-anvil Command: anvil Cmd-forge-script Command: forge script T-feature Type: feature
Projects
Archived in project
Development

No branches or pull requests

4 participants