testing

Installation
SKILL.md

Smart Contract Testing with Foundry

Foundry is the standard. Hardhat and Truffle are legacy. If you are writing tests in JavaScript for Solidity contracts, you are adding a language boundary that hides bugs and slows iteration.

What You Probably Got Wrong

  1. Hardhat/Truffle are legacy. Foundry (forge, cast, anvil) is the standard toolchain for Solidity development in 2025-2026. Tests written in Solidity catch type errors at compile time. JavaScript tests do not.
  2. Stop testing getters. If your test is assertEq(vault.owner(), deployer), you are testing OpenZeppelin, not your code. OZ is audited. Your logic is not.
  3. Stop testing the happy path only. The happy path works. The bug is in what happens when amount = 0, when decimals = 2, when the user has no balance, when the oracle returns a stale price.
  4. Fuzz testing is not optional. Every function that does math needs fuzz tests. Foundry makes this trivial — one parameter change turns a unit test into a fuzz test.
  5. Fork testing is not "advanced." If your contract interacts with Uniswap, Aave, or any external protocol, test against real mainnet state. Mocking the protocol is testing your mock, not your integration.
  6. LLMs generate useless tests. They check name() returns "MyToken" and symbol() returns "MTK". Delete those. They add coverage noise and test nothing meaningful.
  7. console.log is not how you debug in Foundry. Use vm.expectEmit, vm.expectRevert, and -vvvv traces. If you need console2.log, use it from forge-std/Test.sol, not Hardhat's console.

Project Setup

Installs
1
First Seen
Jun 19, 2026