DEV Community

Cover image for How to Unit Test a Smart Contract.
AbhayPatel98
AbhayPatel98

Posted on

How to Unit Test a Smart Contract.

Guide Requirements
Hardhat: Hardhat is an Ethereum development platform that provides all the tools needed to build, debug and deploy smart contracts.

Image description

Useful JS + Solidity Testing Resources
We will use these resources throughout this guide but bookmark these for any other testing you do!
**
ChaiJS**
Chai BDD Styled
Chai Assert
Mocha Hooks
Solidity Chai Matchers

Step 1: Hardhat Project Structure Setup

In a directory of your choice, run npm init -y
Run npm install --save-dev hardhat
Run npx hardhat and you will get the following UI on your terminal:

*Select Create a JavaScript project
*Select YES to all of these options!

Your project should now contain the following:

Files: node_modules, package.json, hardhat.config.js, package-lock.json, README.md
Folders: scripts, contracts, test

*Run npx hardhat test in your terminal
*

Image description

Top comments (0)