Courses

Testing and Debugging Smart Contracts
Ethereum · Chapter 12

Testing and Debugging Smart Contracts

A test describes an expected result and checks that the contract produces it. Small, repeatable tests are easier to understand than repeatedly clicking through a wallet.

The basics

  • For Counter, test that a new deployment starts at zero and that two increments produce two.
  • When you introduce permissions, test both the allowed account and a rejected account.
  • Use a local network for quick tests. For a failed public-testnet transaction, inspect the receipt and error before trying again.

Try it yourself

Write three test cases in plain English for Counter. Re-run them after every change. If you use Foundry or Hardhat later, turn each sentence into an automated assertion.

Read more in the official documentation

@ Daniel Burlacu