agentleFS
0xlayerghost0xlayerghost/solidity-agent-kit/skills/solidity-testing/SKILL.md

solidity-testing

Skill4 starsChanged 42 days agoMITView on GitHub

[AUTO-INVOKE] MUST be invoked BEFORE writing or modifying Foundry test files (*.t.sol). Covers unit, fuzz, invariant, fork, adversarial, differential, and regression testing. Trigger: any task involving creating or editing Solidity tests.

The file

Show its rules and text

We split this skill into the rules it gives an agent

15 rules. About 0 are common, 11 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈11

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Always respond in the same language the user is using: If the user asks in Chinese, respond in Chinese.

    line 10
  2. Very specific:

    Use solc 0.8.24, OpenZeppelin Contracts 5.0.2, and the Foundry version installed by the repository.

    line 14
  3. Very specific:

    Read foundry.toml before changing test configuration.

    line 15
  4. Distinctive:

    Use OpenZeppelin 5.x APIs and import paths in test fixtures and mocks.

    line 16
  5. Very specific:

    Do not use testFail_*. Assert the intended failure with vm.expectRevert, preferably matching a custom-error selector or fully encoded error.

    line 22
  6. Distinctive:

    Keep helpers and mocks minimal.

    line 24
  7. Distinctive:

    Every core function must have tests covering:

    line 28
  8. Very specific:

    Use StdInvariant with a handler for multi-step protocols and state machines.

    line 74
  9. Distinctive:

    Check system properties such as conservation, solvency, monotonic counters, authorization isolation, and legal state transitions.

    line 77
  10. Distinctive:

    Read references/advanced-testing.md when implementing invariant handlers, deterministic fork tests, adversarial mocks, differential tests, …

    line 80
  11. Distinctive:

    Keep local unit tests for business logic.

    line 87
  12. Distinctive:

    Verify state and balance changes in addition to events and return values.

    line 91
  13. Distinctive:

    Every fixed vulnerability or production incident requires a regression test that fails before the fix.

    line 92
  14. Distinctive:

    Use gas snapshots for regression detection, not brittle exact-gas assertions inside ordinary tests.

    line 94
  15. Distinctive:

    Never broadcast transactions or load production signing keys from tests.

    line 95

≈ “Common” is an estimate: at least 1 in 5 of the 383,637 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Solidity 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.

Toolchain Baseline

  • Use solc 0.8.24, OpenZeppelin Contracts 5.0.2, and the Foundry version installed by the repository.
  • Read foundry.toml before changing test configuration. Preserve existing profiles and raise fuzz or invariant intensity according to risk instead of overwriting project settings.
  • Use OpenZeppelin 5.x APIs and import paths in test fixtures and mocks.

Test Organization

  • Organize tests by behavior and boundary: unit, integration, fuzz, invariant, fork, and regression tests may use separate contracts or directories.
  • Name ordinary tests test_<behavior>_<scenario> and fuzz tests testFuzz_<behavior>.
  • Do not use testFail_*. Assert the intended failure with vm.expectRevert, preferably matching a custom-error selector or fully encoded error.
  • Each test must run independently. Use setUp() for fixtures and never depend on execution order.
  • Keep helpers and mocks minimal. A reference model must be independent from the production implementation it checks.

Behavioral Coverage

Every core function must have tests covering:

ScenarioWhat to verify
Happy pathStandard input → expected output, correct state changes
Permission checksUnauthorized caller → vm.expectRevert with correct error
Boundary conditionsDomain minimum/maximum, zero where valid, and off-by-one values
Failure scenariosSecurity-relevant require, revert, and custom-error paths
State changesStorage and balance deltas; events alone are not proof of correct state
Edge casesEmpty arrays, duplicate calls, self-transfers

Select additional tests from the contract's behavior:

Contract behaviorAdditional tests
External callbacksReentrancy, rejecting receiver, malformed return data
ERC20 integrationNo-return, fee-on-transfer, rebase, and approval-reset behavior
SignaturesReplay, wrong signer, chain, nonce, and expired deadline
Oracle consumptionStale/invalid answers, decimals, deviation, and low-liquidity conditions
Proxy/initializerReinitialization, uninitialized implementation, authorization, storage compatibility
Accounting/vault mathRounding direction, first deposit, donation, solvency, and conservation

Foundry Cheatcodes Quick Reference

CheatcodeUsage
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 the expected selector or encoded 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

  • Fuzz math-heavy, accounting, authorization, and fund-flow boundaries.
  • Map scalar inputs into the valid domain with bound() when possible. Use vm.assume() only for relational or structurally invalid inputs that cannot be mapped cheaply.
  • Assert properties, balance deltas, and postconditions rather than duplicating the implementation line by line.
  • Increase runs for high-value or complex paths based on execution cost and risk; do not prescribe one universal run count.
  • Preserve any minimized failure as a deterministic regression test and record the seed needed to reproduce unresolved failures.

Stateful Invariant Testing

  • Use StdInvariant with a handler for multi-step protocols and state machines.
  • Restrict the action space with targetContract and targetSelector; do not let irrelevant reverts dominate exploration.
  • Track ghost variables when expected totals cannot be derived directly from contract state.
  • Check system properties such as conservation, solvency, monotonic counters, authorization isolation, and legal state transitions.
  • Unexpected reverts are findings. Do not hide them by weakening the invariant or adding broad assumptions.

Read references/advanced-testing.md when implementing invariant handlers, deterministic fork tests, adversarial mocks, differential tests, mutation testing, or gas-regression gates.

Fork Testing

  • Pin the chain and block number. Do not base reproducible tests on the latest block.
  • Assert block.chainid, dependency bytecode, and critical interface bindings before exercising protocol behavior.
  • A missing RPC or archive capability must produce an explicit skip or failure; it must not silently pass the test.
  • Keep local unit tests for business logic. Fork tests validate integration assumptions, not every code path.

Verification Rules

  • Verify state and balance changes in addition to events and return values.
  • Every fixed vulnerability or production incident requires a regression test that fails before the fix.
  • Coverage percentage is diagnostic only. It does not replace branch, adversarial, invariant, or mutation testing.
  • Use gas snapshots for regression detection, not brittle exact-gas assertions inside ordinary tests.
  • Never broadcast transactions or load production signing keys from tests.

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 a risk-appropriate run count
forge test --fuzz-runs <RUNS>

# Run invariant tests
forge test --match-test invariant_ -vvvv

# Check gas snapshots when the repository tracks them
forge snapshot --check

# Test coverage
forge coverage

# Coverage with report
forge coverage --report lcov

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.