foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.31k stars 1.76k forks source link

Implement support for running tests on Anvil #5517

Open Keinberger opened 1 year ago

Keinberger commented 1 year ago

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 https://github.com/foundry-rs/foundry/discussions/5421

wavey0x commented 3 weeks ago

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 commented 3 weeks ago

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.

wavey0x commented 3 weeks ago

thanks @zerosnacks

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

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