Skillshub solidity-testing
[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.
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/0xlayerghost/solidity-agent-kit/solidity-testing" ~/.claude/skills/comeonoliver-skillshub-solidity-testing && rm -rf "$T"
manifest:
skills/0xlayerghost/solidity-agent-kit/solidity-testing/SKILL.mdsource content
Testing Standards
Language Rule
- Always respond in the same language the user is using. If the user asks in Chinese, respond in Chinese. If in English, respond in English.
Test Organization
- One test contract per source contract:
→MyToken.solMyToken.t.sol - File location: All tests in
directorytest/ - Naming:
for passing tests,test_<feature>_<scenario>
for expected revertstestFail_<feature>_<scenario>- Example:
test_transfer_revertsWhenInsufficientBalance - Example:
test_stake_updatesBalanceCorrectly
- Example:
- Independence: Each test must run in isolation — use
for shared state, no cross-test dependenciessetUp() - Filtering: Support
and--match-test
for targeted runs--match-contract
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 → with correct error |
| Boundary conditions | Zero values, max values (), off-by-one |
| Failure scenarios | Every / / custom error path |
| State changes | Storage updates, balance changes, event emissions () |
| Edge cases | Empty arrays, duplicate calls, self-transfers |
Foundry Cheatcodes Quick Reference
| Cheatcode | Usage |
|---|---|
| Next call from |
| All calls from until |
| Set |
| Set |
| Set ETH balance |
| Next call must revert with specific error |
| Verify event emission (topic checks) |
/ | Track storage reads/writes |
| Create labeled address for readable traces |
Fuzz Testing Rules
- All math-heavy and fund-flow functions must have fuzz tests
- Pattern:
function testFuzz_<name>(uint256 amount) public - Use
to constrain inputs:vm.assume()vm.assume(amount > 0 && amount < MAX_SUPPLY); - Default runs: 256 — increase to 10,000+ for critical functions:
forge test --fuzz-runs 10000
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