web3-testing
Test smart contracts with Hardhat and Foundry
Également disponible depuis: 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.
Télécharger le ZIP du skill
Importer dans Claude
Allez dans Paramètres → Capacités → Skills → Importer un skill
Activez et commencez à utiliser
Tester
Utilisation de "web3-testing". Generate a Foundry test for a vault contract that handles deposits and withdrawals
Résultat attendu:
- 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
Utilisation de "web3-testing". Set up mainnet forking to test my lending protocol against Aave
Résultat attendu:
- 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
Audit de sécurité
SûrStatic 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.
Problèmes à risque faible (1)
Facteurs de risque
⚙️ Commandes externes (22)
🌐 Accès réseau (3)
📁 Accès au système de fichiers (1)
🔑 Variables d’environnement (6)
Score de qualité
Ce que vous pouvez construire
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.
Essayez ces prompts
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.
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.
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.
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.
Bonnes pratiques
- 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
Éviter
- 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