test
npx machina-cli add skill HCS412/contractkit/test --openclawContractKit: Test
Format and run tests for the current Foundry project.
Process
1. Verify Project
Check that foundry.toml exists in the current directory. If not, ask the user to navigate to a Foundry project.
2. Format Code
forge fmt
3. Run Tests
forge test -vvv
4. Report Results
If all tests pass:
- Report number of tests passed
- Suggest next steps:
/contractkit:deploy local
If tests fail:
- Show which tests failed
- Show the failure reason
- Offer to help fix the issue
Options
| Flag | Description |
|---|---|
--match-test <pattern> | Run only tests matching pattern |
--match-contract <pattern> | Run only contracts matching pattern |
-vvvv | Maximum verbosity for debugging |
Example Usage
User: /contractkit:test
Running forge fmt...
Running forge test -vvv...
[PASS] test_Name() (gas: 5432)
[PASS] test_Symbol() (gas: 5478)
[PASS] test_MinterCanMint() (gas: 54321)
...
All 10 tests passed.
Next: /contractkit:deploy local
Troubleshooting
Missing Dependencies
If tests fail with import errors:
forge install OpenZeppelin/openzeppelin-contracts --no-commit
forge install foundry-rs/forge-std --no-commit
Compilation Errors
Run forge build first to see detailed compilation errors.
Source
git clone https://github.com/HCS412/contractkit/blob/main/plugins/contractkit/skills/test/SKILL.mdView on GitHub Overview
Format and run tests for Foundry projects using forge fmt and forge test -vvv. It verifies you’re in a Foundry project (foundry.toml), formats code, executes tests, and reports results with actionable next steps.
How This Skill Works
The skill first checks for a Foundry project by locating foundry.toml. It then formats the code with forge fmt and runs tests with forge test -vvv, finally reporting pass/fail status and next steps; you can refine which tests run with --match-test, --match-contract, or -vvvv for deeper debugging.
When to Use It
- You want to format and validate a Foundry project before committing changes.
- You need to confirm you are in a Foundry project by locating foundry.toml.
- You want verbose test output to debug failures and inspect gas usage.
- You want to run only a subset of tests or contracts using --match-test or --match-contract.
- You need troubleshooting steps for missing dependencies or compilation errors (forge install, forge build).
Quick Start
- Step 1: Ensure you're in a Foundry project with a foundry.toml file.
- Step 2: Run forge fmt to format the code.
- Step 3: Run forge test -vvv to execute tests with verbose output.
Best Practices
- Always run forge fmt before testing to catch formatting issues.
- Use forge test -vvv for detailed test output and diagnostics.
- Leverage --match-test and --match-contract to isolate problematic tests.
- Ensure foundry.toml exists in the current directory before starting.
- If tests fail, review failure reasons and consider running forge build to surface compilation errors.
Example Use Cases
- A dev formats and tests after adding a new contract in a Foundry project.
- QA runs all tests for the contract kit plugin to validate changes before release.
- A teammate uses --match-test to run a failing test only and speed up debugging.
- A reviewer inspects verbose output to analyze gas usage per test case.
- All tests pass and the next step is deploying locally with /contractkit:deploy local.