utsavsavani08/rain-skill-main/foundry-hardhat-testing

Claude Code and agent skill by utsavsavani08/rain-skill-main

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Testing EVM smart contracts with Foundry and Hardhat. Use when writing contract tests, fuzz/invariant tests, fork tests, gas snapshots, or coverage for .sol code. Covers forge test, cheatcodes, fuzzing, invariants, mainnet forking, and Hardhat (mocha/chai/ethers).

Install

npx vskill@latest install utsavsavani08/rain-skill-main/foundry-hardhat-testing

SKILL.md

The same SKILL.md was published earlier as utsavsavani08/rain-skill-main/foundry-hardhat-testing.

You write thorough contract tests. For smart contracts, tests are the primary defense — aim for high coverage plus fuzzing and invariants, not just happy-path units.

Use this skill when

  • Writing or running tests for Solidity contracts
  • Adding fuzz, invariant, or fork tests
  • Measuring coverage or gas

Default to Foundry

Foundry is the modern default (fast, Solidity-native tests, built-in fuzzing). Use Hardhat when the repo already uses it or needs heavy JS/TS tooling.

Foundry

bash
forge test # run
forge test -vvv # verbose traces on failure
forge test --match-test testFoo
forge coverage # coverage
forge snapshot # gas snapshot (commit .gas-snapshot)
forge test --fork-url $RPC_URL # fork mainnet
Unit + cheatcodes
solidity
import {Test} from "forge-std/Test.sol";
contract VaultTest is Test {
Vault vault;
address user = makeAddr("user");
function setUp() public { vault = new Vault(); }
function test_deposit() public {
vm.deal(user, 1 ether);
vm.prank(user);
vault.deposit{value: 1 ether}();
assertEq(vault.balanceOf(user), 1 ether);
}
function test_RevertWhen_zero() public {
vm.expectRevert(Vault.ZeroAmount.selector);
vault.deposit{value: 0}();
}
}

Key cheatcodes: vm.prank/startPrank, vm.deal, vm.warp/vm.roll, vm.expectRevert, vm.expectEmit, vm.mockCall, makeAddr.

Fuzzing
solidity
function testFuzz_deposit(uint96 amount) public {
vm.assume(amount > 0);
vm.deal(user, amount); vm.prank(user);
vault.deposit{value: amount}();
assertEq(vault.balanceOf(user), amount);
}
Invariant testing

Express properties that must ALWAYS hold (e.g., sum(balances) == totalAssets). Use handler-based invariants for realistic call sequences:

solidity
function invariant_solvency() public {
assertGe(address(vault).balance, vault.totalDeposited());
}
Fork testing

Test against real mainnet state (real tokens, oracles, pools) with --fork-url + vm.createSelectFork.

Hardhat (when required)

js
const { expect } = require("chai");
const { ethers } = require("hardhat");
describe("Vault", () => {
it("accepts deposits", async () => {
const [user] = await ethers.getSigners();
const vault = await (await ethers.getContractFactory("Vault")).deploy();
await vault.connect(user).deposit({ value: ethers.parseEther("1") });
expect(await vault.balanceOf(user.address)).to.equal(ethers.parseEther("1"));
});
});

Use @nomicfoundation/hardhat-network-helpers (time, loadFixture, impersonate) and hardhat-gas-reporter.

Coverage bar for contracts

  • Every external/public function: success + each revert branch
  • Every privileged function: unauthorized-caller test
  • At least one fuzz test per value-handling function
  • Invariants for core protocol guarantees
  • Fork test for any integration with real tokens/oracles/pools

Anti-patterns

  • ❌ Only happy-path unit tests on a value-handling contract
  • ❌ No fuzzing / no invariants
  • ❌ Mocking the very integration (oracle/pool) whose behavior is the risk — fork instead
  • ❌ Asserting state without also asserting emitted events

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/utsavsavani08/rain-skill-main/foundry-hardhat-testing/badge)](https://verified-skill.com/skills/utsavsavani08/rain-skill-main/foundry-hardhat-testing)

Something wrong with this skill or its page? Tell us.