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
- 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.
- 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. - Stop testing the happy path only. The happy path works. The bug is in what happens when
amount = 0, whendecimals = 2, when the user has no balance, when the oracle returns a stale price. - 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.
- 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.
- LLMs generate useless tests. They check
name()returns"MyToken"andsymbol()returns"MTK". Delete those. They add coverage noise and test nothing meaningful. console.logis not how you debug in Foundry. Usevm.expectEmit,vm.expectRevert, and-vvvvtraces. If you needconsole2.log, use it fromforge-std/Test.sol, not Hardhat's console.