web3-testing

Write and run smart contract tests using Hardhat and Foundry frameworks.

Updated Jul 31, 2026
One-click install
npx skills add https://github.com/Rasslonely/NexusXRP --skill web3-testing-rasslonely
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: web3-testing
Source: https://github.com/Rasslonely/NexusXRP/tree/main/.agents/skills/web3-testing
Command: npx skills add https://github.com/Rasslonely/NexusXRP --skill web3-testing-rasslonely

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Smart contract bugs can cause irreversible financial loss, yet many developers lack structured testing practices for Solidity code. This Skill provides complete testing patterns for Hardhat and Foundry, covering unit tests, fuzzing, mainnet forking, gas measurement, and coverage reporting. ## Core Features & Use Cases - Hardhat Testing Patterns: Fixtures with loadFixture, event assertions, balance change checks, time manipulation, and snapshot/revert state management. - Foundry (Forge) Testing: Solidity-native tests with cheatcodes like vm.prank, vm.deal, vm.expectRevert, fuzz testing, and mainnet fork simulation. - Gas & Coverage Analysis: Gas usage comparison between implementations, hardhat-gas-reporter setup, and solidity-coverage reporting integrated into CI/CD pipelines. - Use Case: Before deploying an ERC-20 token to mainnet, use this Skill to build a test suite that verifies transfers, access control, edge cases via fuzzing, and contract behavior against real mainnet state, then verify the contract on Etherscan. ## Quick Start Write a Hardhat test suite for my ERC-20 token contract covering deployment, transfers, and insufficient balance reverts.

Frequently Asked Questions about web3-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write unit tests for Solidity smart contracts?

Use Hardhat with Chai and ethers.js to write tests that deploy contracts via fixtures, assert state changes, and verify events. The loadFixture helper avoids redeploying contracts between tests, speeding up execution.

Hardhat vs Foundry for smart contract testing?

Hardhat uses JavaScript/TypeScript tests with a rich plugin ecosystem, while Foundry (Forge) writes tests directly in Solidity with built-in fuzzing and cheatcodes like vm.prank. Foundry runs faster; Hardhat integrates more easily with existing JS tooling.

How do I test smart contracts against mainnet state?

Use Hardhat's forking configuration or Forge's vm.createSelectFork with an RPC URL to clone mainnet state locally. This lets tests interact with real deployed contracts like Uniswap or DAI at a pinned block number.

What is fuzz testing in Foundry?

Fuzz testing in Forge automatically generates random inputs for test functions, such as testFuzzTransfer(uint256 amount). Use vm.assume to constrain inputs to valid ranges and verify properties hold across thousands of generated cases.

How do I measure gas usage in Hardhat tests?

Enable hardhat-gas-reporter in the config to log gas costs per function call, or read receipt.gasUsed from transaction receipts in tests. Compare gas between contract implementations to validate optimization efforts.

When should I not rely only on unit tests for smart contracts?

Unit tests alone miss cross-contract interactions and real network conditions. Combine them with mainnet fork tests, fuzzing, and coverage analysis, and treat test results as one input alongside audits before deployment.