foundry icon indicating copy to clipboard operation
foundry copied to clipboard

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

Open mattsse opened this issue 3 years ago • 17 comments

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

  • [ ] refactor cast RunArgs so it can be used as a standalone function
  • [ ] use it to retrieve script errors in https://github.com/foundry-rs/foundry/blob/57d28db4d03a379823ba8a24d6ac6e2bdd227a9b/cli/src/cmd/forge/script/receipts.rs#L46-L62

Additional context

No response

mattsse avatar Aug 09 '22 14:08 mattsse

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?

fahimahmedx avatar Aug 11 '22 03:08 fahimahmedx

@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 avatar Aug 11 '22 17:08 onbjerg

For context, this should also solve #2686

onbjerg avatar Aug 11 '22 17:08 onbjerg

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 avatar Aug 13 '22 05:08 fahimahmedx

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

fahimahmedx avatar Aug 15 '22 03:08 fahimahmedx

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

mattsse avatar Aug 15 '22 13:08 mattsse

Any progress on this?

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

naddison36 avatar Sep 05 '22 05:09 naddison36

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

ghost avatar Nov 08 '22 18:11 ghost

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

joaquinlpereyra avatar Nov 18 '22 23:11 joaquinlpereyra

@joaquinlpereyra yes I am working on it

ghost avatar Nov 19 '22 11:11 ghost

@joaquinlpereyra Is this still being worked on?

0xBaconPancakes avatar Dec 22 '22 14:12 0xBaconPancakes

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

naddison36 avatar Jan 16 '23 08:01 naddison36

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

mattsse avatar Jan 27 '23 14:01 mattsse

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

joaquinlpereyra avatar Feb 02 '23 13:02 joaquinlpereyra

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 avatar Feb 09 '23 22:02 naddison36

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 avatar Apr 13 '23 23:04 naddison36

This is still a valuable feature to have

naddison36 avatar Aug 03 '23 02:08 naddison36