foundry icon indicating copy to clipboard operation
foundry copied to clipboard

More specific error messages for "EvmError"

Open PaulRBerg opened this issue 3 years ago • 5 comments

Component

Forge

Describe the feature you would like

To test certain EVM errors such as block gas limit overflows, we have to expect an empty revert like this:

vm.expectRevert(bytes(""));

This is also documented in the Foundry Book, so it's all clear from a user documentation perspective. But this is not cool from a user experience point of view.

Ideally, Foundry would catch such EVM errors and throw a more specific error message, so that:

  • Users have better guarantees that their tests are passing for the right reason
  • Debugging is easier

Additional context

I can see the following logs in the traces if I pass the -vvvv flag:

Traces:
  [2157781646] CreateWithDeltas__ProTest::testCannotCreateWithDeltas__LoopCalculationOverflowsBlockGasLimit()
    ├─ [0] VM::expectRevert(0x)
    │   └─ ← ()
    └─ ← "EvmError: OutOfGas

Therefore, it should be in principle possible to catch this error and relay it to end users, so that tests could be written like this:

vm.expectRevert(bytes("EvmError: OutOfGas"));

PaulRBerg avatar Jan 03 '23 12:01 PaulRBerg

IIUC there's two things being requested here:

  1. More specific error messages thrown. In https://github.com/foundry-rs/foundry/issues/1387 we aggregated most/all EVM errors to handle and I'm not sure where that left off. @gakonst are we tracking all the possible errors to handle somewhere?
  2. Being able to specify/catch all those errors with vm.expectRevert

I agree both of these are worth implementing

mds1 avatar Jan 03 '23 13:01 mds1

I wasn't strictly requesting your point 1 as a feature - I have sort of taken it as an assumption that Foundry already aggregates most/ all EVM errors internally.

It's point 2 that I was mainly interested in - to be able to catch all of those errors with vm.expectRevert.

PaulRBerg avatar Jan 03 '23 15:01 PaulRBerg

@PaulRBerg is this still of interest? thanks!

grandizzy avatar Oct 15 '24 12:10 grandizzy

@grandizzy yes

PaulRBerg avatar Oct 15 '24 12:10 PaulRBerg

Would love to see this feature

jtfirek avatar Oct 30 '24 18:10 jtfirek