Testing Reverts and Events
Assert behavior.
Reverts and Events
Beyond return values, contracts communicate through reverts (transactions that fail and undo state) and events (logs emitted on success).
Good tests assert both: that valid actions emit the right events, and that invalid actions revert with the right reason.
Hardhat Chai Matchers
The Toolbox adds special Chai matchers for Ethereum, available after importing them (the Toolbox does this automatically):
.to.be.revertedWith(...).to.be.revertedWithCustomError(...).to.emit(...).to.changeEtherBalance(...)
All lessons in this course
- Writing Tests
- Testing Reverts and Events
- Coverage and Gas Reports
- Fixtures