Refactor the Entire Test Suite (Or Move to Foundry)
See original GitHub issueThe repository uses Hardhat as a development environment as it fit our needs perfectly and has a plethora of plugins. Unfortunately, we’ve run into some issues as we’ve reached 500+ tests.
Firstly, the test suite takes quite a while to run. This can significantly reduce productivity and increase development time-- even when running a quick-test
which does not wipe and re-compile if it isn’t needed, the setup time can be quite long.
Secondly, and this is largely my mistake in hindsight, the tests we’ve built lack in consistency. For instance, some tests create a profile in a beforeEach()
hook, others do it individually on a per-test as-needed basis, etc. This makes working on tests a bit of a drag because extra effort needs to be done to validate the specific testing environment. This isn’t enough of a problem on its own, but with the next point it can lead to some confusion.
Lastly, the tests lack in clarity. This again is largely my mistake, but because I opted for particularly verbose direct-to-contract calling in most cases, we’re left with large difficult-to-read code blocks. As an example, look at the amount of times profile creation happens in the tests!
In order to improve the codebase’s overall readability, I recommend either a large-scale refactor of test functions using helper functions (e.g: have helper functions like createProfile()
with default values that can be overriden and call those instead of directly calling the contracts explicitly) or migrating the test suite over to Foundry.
Migrating to Foundry has the very likely benefit of speeding up tests significantly, in addition to the increased readability of tests written in solidity. This is a solution I’m pretty excited about, although it’s very much a longer-term endeavor.
I’d love some input from integrators and everyone building atop the Lens Protocol, what do you think, folks?
Issue Analytics
- State:
- Created a year ago
- Reactions:17
- Comments:13 (1 by maintainers)
Thank you all for your input folks, happy to see the consensus is towards implementing Foundry! Will write up on next steps, this is now definitely something we want in the near term post-launch.
In full support for migrating to foundry… been using foundry for a few personal projects and it’s a dream and so much faster! With the codebase only growing this is worth taking the hit sooner then later
With deploy coming soon and solidity scripts it’s the only going to get better.
I’ve seen benchmarks go from 5 minutes 30 seconds with hardhat to 25 seconds! 🦀 your never going to improve this much even with a refactor of the tests using JavaScript. (Foundry built in rust which has benchmarks of 1800% faster over node in internal benchmark tests hence why it can be beast mode!)
On top of this you have fuzzers built in and just a lot of other awesome tools.
I’m sure it can be migrated slowly keeping both side by side as ofc refactoring 500+ tests may take a while.