Solidity testing

From ComeOnOliver/skillshub · View interactive version

Solidity testing is an AI agent skill from the GitHub repository ComeOnOliver/skillshub. [AUTO-INVOKE] MUST be invoked BEFORE writing or modifying any test files (*.t.sol). Covers test structure, naming conventions, coverage requirements, fuzz testing, and Foundry cheatcodes. Trigger: any task involving creating, editing, or running Solidity tests.

How to use this skill

Skill file

Testing Standards

Language Rule

Test Organization

Coverage Requirements

Every core function must have tests covering:

| Scenario | What to verify |

|----------|---------------|

| Happy path | Standard input → expected output, correct state changes |

| Permission checks | Unauthorized caller → vm.expectRevert with correct error |

| Boundary conditions | Zero values, max values (type(uint256).max), off-by-one |

| Failure scenarios | Every require / revert / custom error path |

| State changes | Storage updates, balance changes, event emissions (vm.expectEmit) |

| Edge cases | Empty arrays, duplicate calls, self-transfers |

Foundry Cheatcodes Quick Reference

| Cheatcode | Usage |

|-----------|-------|

| vm.prank(addr) | Next call from addr |

| vm.startPrank(addr) | All calls from addr until vm.stopPrank() |

| vm.warp(timestamp) | Set block.timestamp |

| vm.roll(blockNum) | Set block.number |

| vm.deal(addr, amount) | Set ETH balance |

| vm.expectRevert(error) | Next call must revert with specific error |

| vm.expectEmit(true,true,false,true) | Verify event emission (topic checks) |

| vm.record() / vm.accesses() | Track storage reads/writes |

| makeAddr("name") | Create labeled address for readable traces |

Fuzz Testing Rules

Common Commands

# Run all tests
forge test

# Run specific test function
forge test --match-test test_transfer

# Run specific test contract
forge test --match-contract MyTokenTest

# Verbose output with full trace
forge test -vvvv

# Gas report
forge test --gas-report

# Fuzz with more runs
forge test --fuzz-runs 10000

# Test coverage
forge coverage

# Coverage with report
forge coverage --report lcov
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.