Smart contract testing is the discipline of proving a Solidity contract behaves correctly before it goes on-chain, using the test runners built into Hardhat and Foundry plus specialized fuzzers and symbolic execution engines. It matters more here than in most software: a deployed contract is immutable, so a bug caught in a test costs nothing while the same bug caught by an attacker can drain a protocol. A useful mental model is that no single technique is sufficient on its own β unit tests verify intended behavior, fuzzing and invariant testing hunt for behavior you never intended, and coverage tells you which of these you haven't even tried yet β so a mature contract repo layers all three rather than treating 100% line coverage as "done."
What This Cheat Sheet Covers
This topic spans 15 focused tables and 106 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
A jump-to index of every table row in this cheat sheet.
An interactive map of every table and concept in this topic.
Table 1: Testing Fundamentals and Methodology
Before touching a framework, it helps to know the vocabulary and structure that every mature contract test suite shares β the same layers used in general software testing, adapted to a world where deployed code cannot be patched.
| Concept | Example | Description |
|---|---|---|
function test_Increment() public { counter.increment(); assertEq(counter.number(), 1); } | Tests a single function's behavior in isolation, covering every valid and invalid parameter combination it can be called with. | |
Deploy a vault and a token together, then call vault.deposit() and assert the token balance moved | Verifies that two or more deployed contracts interact correctly, catching bugs that only appear when components are wired together. | |
Assert a bid below the minimum reverts | Confirms the contract correctly rejects invalid inputs and unauthorized calls, not just that it accepts valid ones. | |
Simulate a full user journey: connect wallet β approve β deposit β withdraw | Exercises the whole system the way a real user would, confirming every component works together from a cold start. |