Generally, when writing tests for smart contracts, how comprehensive do the tests have to be? Also, how does one know what to test (e.g., which line in the function in the original contract file the test should target)?

Finally, how should tests generally be set up (e.g., create some dummy constant or variable, then assert or expect those dummy constant or variable is equal to some returned value by calling and feeding some parameters into some function in the original contract file)?

Any help is appreciated. Thank you.

1 Answer 1


Testing, I would argue is the most important aspect of smart contract development. Nothing short of 100% test coverage is enough when large funds or trustworthiness of critical data is on the line.

I personally spend 90% of my development time testing && auditing smart contracts I write. While implementing the solidity code && contract functionality accounts only for 10% of the effort. Writing smart contract is easy, but making sure your smart contract is working as intended is hard

Truffle, Brownie && Hardhat will allow you to write and run basic unit/integration tests, and check the code coverage. You can use Js, Python or TypeSript to write the tests, Solidity is also an option but I would not recommend it, you might have issues with contract sizes etc.

NOTE: You need 100% test coverage no way aroud that if you want to do quality work. However you will also need to learn how to Fuzzing (testing with random data imputs). And also using a security analysis tools like Mythx or some free version of it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.