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

[DRAFT] Test using vault compiled with Hardhat in Forge tests #558

Closed
wants to merge 4 commits into from

Conversation

joaobrunoah
Copy link
Contributor

@joaobrunoah joaobrunoah commented May 9, 2024

Description

Complex contracts, such as BatchRouter and Vault, often trigger 'stack too deep' errors upon modification. These errors, coupled with the need for workarounds, result in difficult-to-understand code.

If we compile the code with the via-ir flag, we can avoid "stack too deep". However, when we develop tests with Forge, they're also compiled with the via-ir flag and take forever to compile. Currently, there's no way to natively use the contracts folder compiled with via-ir and the test folder compiled without it.

To bypass this issue, as mentioned by @elshan-eth, we can import the JSON file that was generated from hardhat/forge build using --via-ir, and with modifications in the foundry.toml file we prevent forge from compiling all contracts from contracts folder when running forge test.

NOTE: This PR breaks the coverage tests in forge, but they're already broken in hardhat since the code is compiled with via-ir too.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Dependency changes
  • Code refactor / cleanup
  • Documentation or wording changes
  • Other

Checklist:

  • The diff is legible and has no extraneous changes
  • Complex code has been commented, including external interfaces
  • Tests have 100% code coverage
  • The base branch is either main, or there's a description of how to merge

Copy link
Collaborator

@EndymionJkb EndymionJkb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worked for me! I even deleted the artifacts, node modules, etc., and tried running test:forge only, to make sure hardhat didn't have to be run first. And the dramatic snap file reduction indicates it's functioning.

Copy link
Contributor

@jubeira jubeira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Well let's keep this in mind; maybe let's not merge it yet. It's great to know that it's not that hard to move away from the current pipeline.

If we wanted to have coverage tests, we'd need to deploy the vault in the regular way and compile with a different profile like the project referenced in #539 does right?

"test:forge": "forge test -vvv --no-match-test Fork",
"test:fork": "forge test -vvv --match-test Fork",
"test:forge": "yarn build; FOUNDRY_PROFILE=test forge test -vvv --no-match-test Fork",
"test:fork": "yarn build; FOUNDRY_PROFILE=test forge test -vvv --match-test Fork",
"test:stress": "FOUNDRY_PROFILE=intense forge test -vvv",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this probably needs to be updated right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.. We need to specify the test profile, so src is set to 'test/foundry' and the Vault binaries are not compiled by the forge test, which would trigger the "Stack too deep" error

@joaobrunoah
Copy link
Contributor Author

Nice! Well let's keep this in mind; maybe let's not merge it yet. It's great to know that it's not that hard to move away from the current pipeline.

If we wanted to have coverage tests, we'd need to deploy the vault in the regular way and compile with a different profile like the project referenced in #539 does right?

@jubeira We'd need to rewrite VaultMockDeployer, deploying the VaultMock with the actual contract instead of using the compiled json.

@joaobrunoah joaobrunoah self-assigned this May 10, 2024
@jubeira jubeira assigned elshan-eth and unassigned joaobrunoah Sep 9, 2024
@elshan-eth elshan-eth closed this Sep 16, 2024
@joaobrunoah joaobrunoah deleted the test-via-ir branch September 25, 2024 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants