Habilidades web3-testing
📦

web3-testing

Seguro ⚙️ Comandos externos🌐 Acesso à rede📁 Acesso ao sistema de arquivos🔑 Variáveis de ambiente

Test smart contracts with Hardhat and Foundry

Também disponível em: wshobson

Smart contract developers need reliable testing frameworks to ensure code security and correctness. This skill provides comprehensive testing patterns using Hardhat and Foundry for unit tests, integration tests, and mainnet forking.

Suporta: Claude Codex Code(CC)
🥉 74 Bronze
1

Baixar o ZIP da skill

2

Upload no Claude

Vá em Configurações → Capacidades → Skills → Upload skill

3

Ative e comece a usar

Testar

A utilizar "web3-testing". Generate a Foundry test for a vault contract that handles deposits and withdrawals

Resultado esperado:

  • Created VaultTest.sol with 8 test functions
  • Tests include: testInitialBalance, testDeposit, testWithdraw, testFailWithdrawMoreThanDeposit, testFuzzDepositAmount, testMultipleUsers, testVaultBalanceTracking, testEmergencyWithdraw
  • Coverage: 95% statement coverage across vault functions
  • Gas report: Average deposit costs 45000 gas, withdrawal costs 38000 gas

A utilizar "web3-testing". Set up mainnet forking to test my lending protocol against Aave

Resultado esperado:

  • Configured hardhat.config.js with mainnet forking settings
  • Created integration test connecting to Aave V2 lending pool at 0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9
  • Test validates borrowing against collateral at current mainnet rates
  • Fork block: 19500000, ETH balance mocked: 100 ETH for test address

Auditoria de Segurança

Seguro
v1 • 2/25/2026

Static analysis flagged 63 patterns across 430 lines, but all findings are false positives. The SKILL.md file is documentation containing code examples in markdown blocks, not executable code. Flagged patterns include standard Hardhat configuration (process.env usage), Solidity import syntax, and blockchain RPC endpoints - all legitimate web3 development practices. No malicious intent detected.

1
Arquivos analisados
430
Linhas analisadas
5
achados
1
Total de auditorias
Problemas de Baixo Risco (1)
Documentation Contains Code Examples
Static analyzer flagged markdown code blocks as executable code. The SKILL.md file contains instructional code examples for Hardhat and Foundry testing frameworks, delimited by markdown backticks. These are documentation, not executable scripts.
Auditado por: claude

Pontuação de qualidade

38
Arquitetura
100
Manutenibilidade
87
Conteúdo
50
Comunidade
100
Segurança
91
Conformidade com especificações

O Que Você Pode Construir

DeFi Protocol Testing

Test decentralized exchange contracts with mainnet forking to verify swaps work correctly with real token contracts before deployment.

NFT Collection Validation

Validate NFT minting, transfer, and royalty distribution logic with comprehensive unit tests and fuzzing for edge cases.

Smart Contract Audit Preparation

Generate comprehensive test suites with high coverage before submitting contracts for professional security audit.

Tente Estes Prompts

Basic Unit Test Setup
Create a Hardhat test file for my ERC20 token contract. Include tests for deployment, transfer functionality, and balance checking. Use the Token.sol contract at src/Token.sol.
Foundry Fuzzing Test
Write a Foundry fuzzing test for my staking contract that validates rewards calculation across different stake amounts and time periods. Use vm.assume to set valid input ranges.
Mainnet Fork Integration Test
Set up a mainnet fork test that interacts with the real Uniswap V2 router and DAI token. Test swapping 1 ETH for DAI and validate the received amount is within expected slippage.
Gas Optimization Comparison
Create a test that compares gas usage between two implementations of the same contract function. Deploy both versions, execute identical operations, and report the gas difference with recommendations.

Melhores Práticas

  • Use fixtures to set up test state and avoid code duplication between tests
  • Test both success paths and failure cases including revert conditions
  • Run tests with coverage enabled and aim for over 90 percent line coverage

Evitar

  • Testing only happy paths without checking edge cases and failure modes
  • Hardcoding private keys or RPC URLs directly in test files instead of using environment variables
  • Skipping mainnet fork tests for contracts that interact with external DeFi protocols

Perguntas Frequentes

What is the difference between Hardhat and Foundry for testing?
Hardhat uses JavaScript/TypeScript for tests with the Chai assertion library. Foundry uses Solidity for tests with built-in assertions. Foundry is faster and supports native fuzzing. Hardhat has a larger plugin ecosystem. Use Foundry for performance-critical testing and Hardhat for complex JavaScript-based test logic.
How do I test contracts that interact with external protocols?
Use mainnet forking to create a local copy of mainnet state. Configure your RPC URL in hardhat.config.js or foundry.toml. Your tests can then interact with real deployed contracts like Uniswap, Aave, or Compound while running on your local network.
What does fuzzing mean in smart contract testing?
Fuzzing automatically generates random inputs to test functions across many possible values. Foundry supports native fuzzing with testFuzz functions. It helps discover edge cases you might miss with manual test cases, such as boundary conditions or unexpected input combinations.
How can I test time-dependent contract functions?
Use Hardhat's time helpers to increase blockchain time or Foundry's vm.warp to set specific timestamps. This allows testing of vesting schedules, timelocks, and other time-based logic without waiting for real time to pass.
Is mainnet forking safe for testing?
Yes, mainnet forking runs entirely locally. No transactions are sent to mainnet. Your test transactions only exist in the local forked environment. However, never use real private keys with significant funds when testing, even locally.
How do I measure test coverage for my smart contracts?
For Hardhat, run npx hardhat coverage to generate an HTML report showing statement, branch, and function coverage. For Foundry, use forge coverage for terminal output or forge coverage --report lcov for detailed reports. Aim for over 90 percent coverage before deployment.

Detalhes do Desenvolvedor

Estrutura de arquivos

📄 SKILL.md