Testing and debugging the smart contract
After smart contracts are deployed, we need some approaches to verify whether they work as expected. Luckily, Hardhat provides several useful tools and libraries for us to verify smart contracts, and they can also be easily integrated with popular testing libraries such as Chai (https://www.chaijs.com/).
In this section, we will first learn how to use the Hardhat console to verify smart contracts. Then we will use the chai
testing library and the mocha
testing framework to write and run test cases for the smart contract. Lastly, we will demonstrate how to use the Hardhat console.log
function to debug smart contracts.
Verifying smart contract with the Hardhat console
Before starting the Hardhat console, please make sure the local EVM has been started and the Simple DeFi Token smart contract has been deployed. If not, please refer to the previous sections:
- Now, let’s start the Hardhat console and connect the local EVM by...