@meb
A guide on writing smart contract unit tests.
Bottom line; Aim for 100% coverage of your methods. Test what changes, who can call methods, events that are emitted and any validations you have.
There’s more, but this provides a great foundation and forces you to think through things in a structured way.
4 categories of smart contract unit tests
1. effects
- what state changed in the smart contract
- did any balances change for related wallets or contracts?
2. permissions
- which roles can call method?
- who cannot call a method?
- is this method callable if the contract is paused?
3. events
- what events should be emitted and do they have the expected values?
4. validations
- if a given set of conditions are not fulfilled, does the contract revert with a specific error? Be sure to check for the specific error, not just a revert