lens-protocol/core

Refactor the Entire Test Suite (Or Move to Foundry)

Zer0dot opened this issue · 14 comments

The 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?

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.

Highly support moving to Foundry, @joshstevens19 already made a great case. I'm more than happy to help port the tests to Foundry, I'm sure there are many others willing to help too!

Foundry 💯
I'd be up for helping out porting some as well

qd-qd commented

Same here, I would be happy to help!

I am more than happy to help!

Definitely, moving to Foundry will be 👌

+1 to migrate to Foundry.
As an integrator (#101) i also would like some kind of guidelines about how we should integrate other protocols in Lens (i.e. testing, deploying). 😁

Right choice .Foundry testing is a lot easier and fast . Also has pretty cool cheatcodes .
I will contribute in the foundry tests for lens protocol

Same, more than happy to help!

+1 to migrate to Foundry. As an integrator (#101) i also would like some kind of guidelines about how we should integrate other protocols in Lens (i.e. testing, deploying). 😁

Hey yeah totally makes sense! We're working on setting up a system for contributions. We definitely don't want to add all the new modules and all to this core repo so there's some refactoring on the roadmap in the near term, props to @donosonaumczuk on that front!

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.

I just find out about the lens protocol and would love to contribute, give me shout when you are ready for migration. Definitely would like to be part of this group, I loved what you have built so far!

Hi frens, I am the main contributor to Foundry's hardhat template and I also want to start building a project on Lens.

So, of course before I start actually building my project, I wanted to get Lens running on Foundry. I've got it working to the point where:

  • tests can now be written with either forge or hardhat (I have ported the FreeCollectModule tests so far)
  • the deployment scripts are also in Solidity and can be run with forge script + anvil to get a local environment (although that still requires a bit more polish)
  • CI is also updated to run forge test

Would you like to already take this upstream? memester-xyz#1 - Obviously none of the Hardhat tests / tasks should be impacted.

Or do you have any specific feedback already? Happy to open a PR in this repo to continue the conversation if you are interested. Thanks!