cairo-testing
Skill2 starsChanged 9 months agoMITView on GitHub
Cairo smart-contract testing with snforge. Trigger on "write tests", "add unit tests", "fuzz test", "integration test", "test this contract", "regression test". Guides test strategy, cheatcode usage, and coverage.
1 other project uses a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- keep-starknet-strange/starknet-agenticedited, first seen May 18, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 1
- keep-starknet-strange/starknet-agentic★ 8179% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository14 other files it gives its agents.
- repo-agent-instructionsAGENTS.md
- CLAUDE.mdCLAUDE.md
- cursor-starknet-skillsCursor rule
- llms.txtllms.txt
- account-abstractionSkill
- cairo-auditorSkill
- cairo-contract-authoringSkill
- cairo-optimizationSkill
- cairo-toolchainSkill
- audit-localSkill
- benchmarkSkill
- validateSkill
- starknet-skillsSkill
- starknet-network-factsSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
22 rules. About 0 are common, 10 are distinctive, and 12 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈10
Distinctive · estimate
This author's own choices. Worth a look.
12
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 35
Verify coverage: every external tested?
- Very specific: line 47
unit: Test individual functions using contract_state_for_testing().
- Distinctive: line 48
integration: Test deployed contracts via dispatchers.
- Very specific: line 50
fork: Test against live Starknet state with #[fork].
- Very specific: line 60
All storage-mutating #[abi(embed_v0)] impl functions and #[external(v0)] functions (these must be tested).
- Distinctive: line 80
Turn 2 — Plan: Before writing any test code, output a brief plan:
- Distinctive: line 89
Keep the plan under 30 lines.
- Distinctive: line 91
Turn 3 — Implement: Write tests following these rules:
- Very specific: line 94
Use #[cfg(test)] mod tests { ...
- Very specific: line 95
Create a shared helpers module for deploy_contract(), address constants (OWNER(), USER(), ZERO()).
- Very specific: line 99
Every storage-mutating #[abi(embed_v0)] impl function and #[external(v0)] function MUST have both a success test and a revert test.
- Distinctive: line 100
Every access-controlled function MUST be tested with: (1) authorized caller succeeds, (2) unauthorized caller panics with expected message.
- Very specific: line 102
Every event-emitting function MUST verify the event with spy_events + assert_emitted.
- Very specific: line 105
Use start_cheat_caller_address / stop_cheat_caller_address to impersonate callers.
- Very specific: line 106
Use start_cheat_block_timestamp for timelock tests — never hardcode timestamps.
- Very specific: line 107
Always call the matching stop_cheat_* after assertions to avoid leaking state.
- Very specific: line 110
Use #[fuzzer(runs: 256, seed: 12345)] with a fixed seed for reproducibility.
- Very specific: line 113
After writing tests, run snforge test to verify they pass.
- Distinctive: line 115
Turn 4 — Verify: After tests pass:
- Distinctive: line 135
Every storage-mutating external function has both a positive and negative test.
- Distinctive: line 136
Every access-controlled function is tested with authorized and unauthorized callers.
- Distinctive: line 154
When testing/security rules in this skill or its references change, update at least one case in:
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 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.
Files
Cairo Testing
You are a Cairo testing assistant. Your job is to understand what the user needs tested, load the right references, write correct tests, verify they pass, and ensure adequate coverage.
When to Use
- Writing unit, integration, fuzz, or fork tests for Cairo contracts.
- Designing regression tests for known findings.
- Validating event emission, failure semantics, or access control.
- Improving test coverage on an existing contract.
When NOT to Use
- Contract architecture decisions (
cairo-contract-authoring). - Performance tuning (
cairo-optimization). - Deployment operations (
cairo-toolchain). - Security audit of existing code (
cairo-auditor).
Quick Start
- Classify what needs testing: new contract, specific function, regression, or coverage gap.
- Load references based on test type — see the table in Orchestration.
- Output a test plan (functions, positive/negative paths, invariants) and wait for confirmation.
- Implement tests following snforge patterns, then run
snforge test. - Verify coverage: every external tested? auth paths? negative cases? events?
- Emit a handoff block using
../references/skill-handoff.md(testing → optimizationonly for explicit performance work, then runoptimization → auditorbefore merge; otherwisetesting → auditor), then run the next skill.
Rationalizations to Reject
- "We only need happy-path tests."
- "Access control tests are unnecessary — the contract handles it."
- "Fuzz tests are overkill for this contract."
- "We'll add regression tests after the next audit."
Mode Selection
- unit: Test individual functions using
contract_state_for_testing(). No deployment needed. - integration: Test deployed contracts via dispatchers. Multi-contract interactions.
- fuzz: Property-based tests with
#[fuzzer]for arithmetic, bounds, invariants. - fork: Test against live Starknet state with
#[fork]. - regression: Turn a known finding into a failing-before/fixed-after test pair.
Orchestration
Turn 1 — Understand. Classify the request:
(a) Determine mode: unit, integration, fuzz, fork, or regression.
(b) Read the contract under test. Use Glob to find .cairo files, then Read to inspect them. Identify:
- All storage-mutating
#[abi(embed_v0)]impl functions and#[external(v0)]functions (these must be tested). - Storage fields and their types.
- Events that should be emitted.
- Access control patterns (owner checks, role checks).
(c) Check for existing tests. Use Glob to find tests/ directories and test files.
(d) Load references based on what's needed:
| Request involves | Load reference |
| Basic test structure, deployment, assertions | {skill_dir}/references/legacy-full.md (Basic Test Structure, Contract Deployment) |
| Cheatcodes (caller, timestamp, block number) | {skill_dir}/references/legacy-full.md (Cheatcodes section) |
| Event testing, spy_events | {skill_dir}/references/legacy-full.md (Event Testing section) |
| Fuzz / property tests | {skill_dir}/references/legacy-full.md (Fuzzing section) |
| Fork testing against mainnet | {skill_dir}/references/legacy-full.md (Fork Testing section) |
| Security regression recipes | ../datasets/distilled/test-recipes/ |
Where {skill_dir} is the directory containing this SKILL.md. Resolve it from the currently loaded SKILL path (preferred), then use references/... relative paths from that directory.
Turn 2 — Plan. Before writing any test code, output a brief plan:
- Functions to test — list each external function and whether it gets a positive test, negative test, or both.
- Access control tests — for each guarded function, test: authorized caller succeeds, unauthorized caller reverts.
- Event tests — list events that should be verified with
spy_events. - Edge cases — zero values, max values, duplicate calls, reentrancy attempts.
- Fuzz targets — identify functions with numeric inputs that should get
#[fuzzer]tests. - Regression tests — if fixing a known finding, describe the failing-before scenario.
Keep the plan under 30 lines. Wait for user confirmation before implementing.
Turn 3 — Implement. Write tests following these rules:
Structure rules:
- Use
#[cfg(test)] mod tests { ... }for unit tests in the same file, or separatetests/directory for integration tests. - Create a shared
helpersmodule fordeploy_contract(), address constants (OWNER(),USER(),ZERO()). - Name tests descriptively:
test_<function>_<scenario>(e.g.,test_transfer_non_owner_rejected).
Coverage rules (mandatory):
- Every storage-mutating
#[abi(embed_v0)]impl function and#[external(v0)]function MUST have both a success test and a revert test. - Every access-controlled function MUST be tested with: (1) authorized caller succeeds, (2) unauthorized caller panics with expected message.
- Constructor MUST be tested: correct initial state, zero-address rejection.
- Every event-emitting function MUST verify the event with
spy_events+assert_emitted.
Cheatcode rules:
- Use
start_cheat_caller_address/stop_cheat_caller_addressto impersonate callers. - Use
start_cheat_block_timestampfor timelock tests — never hardcode timestamps. - Always call the matching
stop_cheat_*after assertions to avoid leaking state.
Fuzz rules:
- Use
#[fuzzer(runs: 256, seed: 12345)]with a fixed seed for reproducibility. - Constrain inputs with guard clauses or bounded types, not by ignoring invalid inputs.
After writing tests, run snforge test to verify they pass. If any fail, fix and re-run.
Turn 4 — Verify. After tests pass:
(a) Coverage checklist — mentally walk through every external function:
- Has a success-path test?
- Has a failure-path test (wrong caller, bad input, overflow)?
- Emits correct events?
- Fuzz target if numeric inputs?
(b) Report any untested functions or missing edge cases to the user.
(c) If the user's project uses cairo-auditor, suggest running it to find additional test targets.
(d) Suggest next steps:
- "Run
cairo-auditorfor a security review — it may surface additional test cases." - "Consider adding fork tests if this contract interacts with deployed protocols."
Security-Critical Rules
These are non-negotiable. Every test suite you write must satisfy all of them:
- Every storage-mutating external function has both a positive and negative test.
- Every access-controlled function is tested with authorized and unauthorized callers.
- Expected panic messages are asserted with
#[should_panic(expected: '...')]— not bare#[should_panic]. - Event assertions use
spy_events+assert_emittedwith full event data — not just event count. - Fuzz tests use fixed seeds for reproducibility.
References
- Testing patterns and snforge API: legacy-full.md
- Cross-skill handoff format:
../references/skill-handoff.md - Module index: references/README.md
- Security regression recipes:
../datasets/distilled/test-recipes/
Workflow
- Main testing flow: default workflow
Eval Gate
When testing/security rules in this skill or its references change, update at least one case in:
evals/cases/contract_skill_benchmark.jsonlevals/cases/contract_skill_generation_eval.jsonl
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
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.

