0PricingLogin
Web3 & DApp Development Fundamentals · Lesson

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

  1. Writing Tests
  2. Testing Reverts and Events
  3. Coverage and Gas Reports
  4. Fixtures
← Back to Web3 & DApp Development Fundamentals