foundry icon indicating copy to clipboard operation
foundry copied to clipboard

`forge test` fail on tests that run `create2`

Open ryanli-me opened this issue 3 years ago • 2 comments

Component

Forge

Have you ensured that all of these are up to date?

  • [X] Foundry
  • [X] Foundryup

What version of Foundry are you on?

forge 0.2.0 (63ed109 2022-08-09T00:20:50.211015Z)

What command(s) is the bug in?

forge test

Operating System

macOS (Apple Silicon)

Describe the bug

The same test script has been running fine in CI until the CI picked up a new version of foundry last Wednesday that broke tests that cover code with create2. The code after create2 are not run and the test shows a large gas usage.

CleanShot 2022-08-08 at 20 30 58@2x

ryanli-me avatar Aug 09 '22 03:08 ryanli-me

Can you please give an example code which worked before / stopped working after?

gakonst avatar Aug 09 '22 17:08 gakonst

Hey @gakonst, I did some digging, our test broke 6 days ago. I'm pretty sure it's related to this commit where an empty account gets etched some bytecode. https://github.com/foundry-rs/foundry/commit/3df9536132bd213b5de3a6ebab0825302061b61e.

In my test, I'm mocking a function call on an address that will be the result of create2.

  1. With a mockCall, the test reverts at create2
  2. Without the mockCall the test goes past create2 and breaks because the mock is missing.

Maybe I shouldn't be mocking on that create2 contract address?

ryanli-me avatar Aug 09 '22 22:08 ryanli-me

Yeah, you shouldn't be mocking an empty account if you plan to deploy on top of it, however I'd like to see an example of your test to see if it might make sense? If so we should extend vm.mockCall with a flag to skip the etching

onbjerg avatar Aug 11 '22 18:08 onbjerg

yeah, it was my unit test where the function being tested will lazy deploy a contract and call a function on it. I think it kinda make sense either way. I just stopped mocking it and rely on the contract being actually deployed.

ryanli-me avatar Aug 16 '22 22:08 ryanli-me