Prerequisites
You should already have a Hardhat project set up, and have compiled your smart contract successfully. See the set up Hardhat and compile a smart contract tutorial for how to do so.Edit the test specifications
As the smart contract we are testing is minimal, so are the test cases that it needs. Before testing, we need to deploy the smart contract. This happens in thebefore block.
This is because smart contracts cannot execute in isolation, they must be within the EVM to execute.
In Hardhat, by default, the tests will execute in an emulated in-memory EVM instance, which is transient, so the deployment is perfunctory.
Open the file: test/Counter.test.js
- Check the initial
value(). - Invoke
increment(num)and then check that thevalue()has updated. - Invoke
increment(num)again, and then check that thevalue()has updated again.