Writing Tests
Mocha and Chai.
Why Test Contracts
Smart contracts are immutable once deployed and often hold real value. A single bug can be unrecoverable, so thorough testing is essential.
- Catch logic errors before deployment.
- Document expected behavior.
- Guard against regressions when refactoring.
Mocha and Chai
Hardhat uses Mocha as the test runner and Chai for assertions, both included in the Toolbox.
describegroups related tests.itdefines a single test case.expectmakes assertions about values.
Tests live in the test/ folder.