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.75k forks source link

feat(`forge script`): add ability to replay failed transaction on a local anvil fork #2673

Open mattsse opened 2 years ago

mattsse commented 2 years ago

Component

Forge, Cast

Describe the feature you would like

As described here https://github.com/mds1/forge-trace-and-script-issue#issue-1-more-verbose-failure-messages-in-scripts

the tx failure error could be more verbose, we already have cast run which we could use to get the revert reason with some refactoring

Additional context

No response

fahimahmedx commented 2 years ago

First time contributing to open-source code or looking at Foundry's code so my apologies for my ignorance. I took a look at the Foundry documentation book and found cast run, but what is cast RunArgs?

onbjerg commented 2 years ago

@fahimahmedx RunArgs is an internal struct in our code base, it's not user facing, it defines the arguments for the command cast run

onbjerg commented 2 years ago

For context, this should also solve #2686

fahimahmedx commented 2 years ago

Still stuck on attempting this issue. My current understanding of the first task is that the structure RunArgs is wanting to be changed into it's own function. Is this the same as standalone function?

If not, is there any place I can find examples of what it means to refactor a struct into a standalone function? Am very confused on what that line even means.

fahimahmedx commented 2 years ago

Is there a discord server with foundry developers that I can direct these questions to? no responses on telegram chat unfortunately

mattsse commented 2 years ago

Hey, happy to give some pointers What we need here is a way to replay a block or individual tx.

We need this for several things, the cast run command for example, but also would be useful for anvil.

So ideally we put all the logic in the evm crate and provide something like a struct ReplayExecutor or smth that the RunArgs would then use

naddison36 commented 2 years ago

Any progress on this?

Being able to trace past transactions using Anvil will be super useful https://github.com/foundry-rs/foundry/issues/2686

ghost commented 2 years ago

@mattsse Hello, could I pick up this issue, please? If on one is working on this

joaquinlpereyra commented 1 year ago

@timofeli did you end taking this up? i'm looking for something to work on but don't want to duplicate efforts.

ghost commented 1 year ago

@joaquinlpereyra yes I am working on it

0xBaconPancakes commented 1 year ago

@joaquinlpereyra Is this still being worked on?

naddison36 commented 1 year ago

Any progress on this? Being able to trace transactions before the fork block will be super helpful. https://github.com/foundry-rs/foundry/issues/2686

mattsse commented 1 year ago

checking in, is anyone currently working on this or started working on this and has a draft?

joaquinlpereyra commented 1 year ago

pinging @timofeli. i haven't worked on it yet but might be able to.

naddison36 commented 1 year ago

This issue is now 6 months old but is extremely useful. The ability to run a locally forked Anvil node and trace transactions from before the fork is super powerful. See https://github.com/foundry-rs/foundry/issues/2686.

This is not something either Hardhat or Truffle can do.

naddison36 commented 1 year ago

For anyone else looking at this issue, I've built a copy command in tx2uml that replays a transaction to a local Anvil node. That way transactions can be traced on a local Anvil node.

Here are the tx2uml copy command docs https://github.com/naddison36/tx2uml#copy-command

Here's an example where an Anvil node is forked from the previous block and the tx is copied so local traces can be executed. https://github.com/naddison36/tx2uml/blob/98d238867c4f9c9d0231521f2167164f6d6d72b9/tests/tests.sh#L37

naddison36 commented 1 year ago

This is still a valuable feature to have