Content
@
0 reply
0 recast
2 reactions
Mo
@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
1 reply
6 recasts
19 reactions
nkemjika.eth
@nkemjika
Just got started on solidity and writing tests, it’s been a struggle, and takes me more time than writing the contract itself. But thanks for sharing this, bookmarked for reference.
2 replies
0 recast
2 reactions