Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vm.getCode doesn't find artifacts by name #7569

Closed
2 tasks done
martinvol opened this issue Apr 5, 2024 · 5 comments · Fixed by #7572
Closed
2 tasks done

vm.getCode doesn't find artifacts by name #7569

martinvol opened this issue Apr 5, 2024 · 5 comments · Fixed by #7572
Assignees
Labels
T-bug Type: bug

Comments

@martinvol
Copy link

martinvol commented Apr 5, 2024

Component

Forge

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (1281421 2024-04-05T00:21:15.963758000Z)

What command(s) is the bug in?

forge script

Operating System

macOS (Apple Silicon)

Describe the bug

In a project I have a contract called ProxyFactory. It gets compiled and its artifacts written to out/ProxyFactory.sol/ProxyFactory.json.

However vm.getCode("ProxyFactory") fails with

    ├─ [0] VM::getCode("ProxyFactory.sol") [staticcall]
    │   └─ ← [Revert] No matching artifact found
    └─ ← [Revert] No matching artifact found

But the following call does work: vm.getCode("./out/ProxyFactory.sol/ProxyFactory.json")

I've started noticing this issue since upgrading from version forge 0.2.0 (7b45265 2023-11-21T00:18:30.267248000Z) to forge 0.2.0 (1281421 2024-04-05T00:21:15.963758000Z).

I think this issue is highly related to #6572, but as the the error messages don't match I though it was worth opening a different one.

@martinvol martinvol added the T-bug Type: bug label Apr 5, 2024
@klkvr klkvr self-assigned this Apr 5, 2024
@klkvr
Copy link
Member

klkvr commented Apr 5, 2024

@martinvol we've inroduced smarter compilation for forge test in #7334 which does not recompile entire project when running tests.

Because of that, we can't anymore guarantee that all artifacts would be fresh when running tests and we've also inroduced additional vaildation of getCode/getDeployedCode calls - #7334 (comment)

Can you confirm that this issue occurs on running a forge test without filters and that none of your test contracts import ProxyFactory.sol source directly? If so, you can simply add an import of that file to any of the test contracts and getCode should be working normally.

If you have import of that file somewhere in tests then this is a bug, and would be great if you could provide some kind of repro

@klkvr
Copy link
Member

klkvr commented Apr 5, 2024

After a second thought I think a better UX would be to always recompile all files under src when running tests, will create a PR for that soon

@martinvol
Copy link
Author

martinvol commented Apr 5, 2024 via email

@klkvr
Copy link
Member

klkvr commented Apr 5, 2024

ah, I see, yeah in that case you can't have it imported anywhere because your contracts wouldn't compile otherwise.

if this contract is in src, then #7572 should resolve this for you

otherwise, you can either move it to src or enable unchecked_cheatcode_artifacts

@martinvol
Copy link
Author

Wow Tha was fast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants