web3-testing

Test Solidity smart contracts using Hardhat and Foundry with unit, fuzz, and mainnet fork tests.

Updated Apr 23, 2026
One-click install
npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill web3-testing-sanketadlak
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: web3-testing
Source: https://github.com/SanketAdlak/PDMProjectDesign/tree/main/.agents/skills/web3-testing
Command: npx skills add https://github.com/SanketAdlak/PDMProjectDesign --skill web3-testing-sanketadlak

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing reliable tests for smart contracts requires knowledge of multiple frameworks, cheatcodes, fixtures, and forking setups, and mistakes can leave critical contract bugs undetected before deployment. ## Core Features & Use Cases - Hardhat Test Suites: Configure hardhat.config.js with gas reporting, coverage, and Etherscan verification, plus unit tests using fixtures, events, and revert assertions. - Foundry/Forge Testing: Write Solidity-native tests with cheatcodes like vm.prank, vm.deal, vm.expectRevert, and property-based fuzz tests. - Mainnet Forking & Impersonation: Fork mainnet at a specific block, interact with live protocols like Uniswap and DAI, and impersonate whale accounts for realistic scenarios. - Use Case: A DeFi developer validating a token contract can generate a full test suite covering transfers, edge cases, gas usage, and forked mainnet integration before deploying. ## Quick Start Write a complete Hardhat and Foundry test suite for my ERC-20 token contract including fuzz tests and mainnet fork tests.

Frequently Asked Questions about web3-testing

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

FAQPage Schema
How do I test smart contracts with Hardhat?

Use Hardhat with Chai and ethers.js to write unit tests organized in describe blocks. Load deployment fixtures with loadFixture, assert state changes with expect, and test events, reverts, and token balance changes.

How to write fuzz tests for Solidity contracts with Foundry?

Write a Forge test function prefixed with testFuzz that accepts random input parameters. Use vm.assume to constrain inputs to valid ranges, then assert invariants like balance correctness after transfers.

Hardhat vs Foundry for smart contract testing?

Hardhat uses JavaScript with Chai and ethers.js, suiting teams already in the Node.js ecosystem. Foundry writes tests in Solidity itself with cheatcodes like vm.prank and vm.deal, offering faster execution and native fuzzing.

How do I test against mainnet contracts without deploying?

Use mainnet forking by configuring a fork URL and block number in hardhat.config.js or calling vm.createSelectFork in Foundry. This lets tests interact with live contracts like Uniswap and DAI at a pinned block.

Why does my Hardhat test fail when impersonating an account?

Impersonation requires calling hardhat_impersonateAccount through the network provider before getting the signer. The impersonated account also needs ETH for gas, which you can set with hardhat_setBalance or vm.deal.

How do I measure gas usage in smart contract tests?

Enable hardhat-gas-reporter in the config to log gas per function call, or capture receipt.gasUsed after awaiting a transaction. Compare gasUsed values between contract implementations to verify optimizations.