question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refactor the Entire Test Suite (Or Move to Foundry)

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:17
  • Comments:13 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
Zer0dotcommented, Apr 13, 2022

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.

4reactions
joshstevens19commented, Apr 12, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test-driven development - IBM Garage Practices
It makes your code flexible and extensible. The code can be refactored or moved with minimal risk of breaking code. The tests themselves...
Read more >
Red, Green, Refactor | Codecademy
In this article, you will learn about a TDD approach called red, green, refactor, a framework that developers use to build a test...
Read more >
Writing ERC-20 Tests in Solidity with Foundry
Are you annoyed having to write tests for Solidity in JavaScript? Finally there's a viable alternative with Foundry. Let's explore how to implement...
Read more >
Writing good unit tests, Part 2: Follow your nose | InfoWorld
Test code has to be written in the same manner as real production code. That means that you should include a refactoring step...
Read more >
Woke up Sunday morning wondering how easy would it be to ...
STEP 3: Package the application as a .war file -- this is done using the "Export ... Let's try Pivotal Cloud Foundry. ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found