Foundry and solidity best practices were recently released, strongly recommended reading through them
Ethereum development changes quickly so I suspect these will evolve over time. Feedback is definitely welcome
A few highlights below, read them all at: book.getfoundry.sh/tutorials/best-practices
This seems to be getting more popular anyway, but always prefer named input syntax instead of importing full files. It helps avoid issues, especially as your project grows.
Potential hot take: Use fork tests liberally, always prefer them to mocks.
Mocks are required in web2 development, where you have no choice but to mock API responses. But in web3 development everything is on-chain, so just fork the chain instead of risking a buggy mock.
When organizing tests, I like treating each contract as a describe block. And be sure to give your tests and harnesses clear, consistent naming conventions.
Some more examples of good test names in @PaulRBerg's tweet.
twitter.com/PaulRBerg/status/1616068157088714765
Some tips in there from @samczsun's How Do You Even Write Secure Code Anyways talk
And finally, some tips and footguns to be aware of with `forge script`
This writeup of best practices was a collaboration between:
- @odysseas_eth from @nomadxyz_
- @lucasmanuel_eth from @maplefinance
- And a few of us at @ScopeLift
So thanks to all for their help reviewing.
As mentioned above, this will likely evolve and feedback is welcome!