मुख्य सामग्री पर जाएँ
Skillpedia
टेस्टिंग41k · #6649

web3-testing

यह क्या करती है

यह टूल ब्लॉकचेन पर चलने वाले स्मार्ट कॉन्ट्रैक्ट प्रोग्राम की टेस्टिंग में मदद करता है। यह Hardhat और Foundry जैसे दूसरे टूल का इस्तेमाल करता है, ताकि बुनियादी फ़ंक्शन से लेकर जटिल स्थितियों तक सब कुछ सही चल रहा है या नहीं, यह जाँचा जा सके।

कब इस्तेमाल करें

  • ✓कॉन्ट्रैक्ट सही काम कर रहा है, यह जाँचने के लिए टेस्ट लिखते समय।
  • ✓किसी कॉन्ट्रैक्ट के कई हिस्सों को एक साथ टेस्ट करने के लिए एनवायरनमेंट सेट करते समय।
  • ✓ज़्यादा असली जैसे टेस्ट के लिए मुख्य ब्लॉकचेन का माहौल बनाते समय।

Skill का लिंक

https://github.com/wshobson/agents/blob/main/plugins/blockchain-web3/skills/web3-testing/SKILL.md

इसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।

कैसे इस्तेमाल करें

सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।

पेस्ट करने के लिए तैयार मैसेज

इस skill से मेरी मदद करो: https://github.com/wshobson/agents/blob/main/plugins/blockchain-web3/skills/web3-testing/SKILL.md इस लिंक की SKILL.md फ़ाइल पढ़ो और मेरे काम में उसके निर्देशों का पालन करो।
क्या आप चाहते हैं कि आपका AI ऐसी skills खुद ढूँढे?मुफ़्त Skillpedia MCP इंस्टॉल करें: बस एक लाइन, और हर काम से पहले यह 15,000+ skills में खोजता है।1 मिनट में इंस्टॉल करें →

AI से क्या माँगें: उदाहरण

“मैं अपने टोकन कॉन्ट्रैक्ट को कैसे टेस्ट करूँ, ताकि पक्का हो कि ट्रांसफ़र सही हों और कोई अपनी जमा रकम से ज़्यादा खर्च न कर सके?”

हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।

यह कैसे काम करती है

यह असली ब्लॉकचेन जैसा दिखने वाला टेस्टिंग एनवायरनमेंट सेट करता है। आप ऐसा कोड लिखते हैं जो टोकन भेजने या बैलेंस जाँचने जैसे काम की नकल करता है, और टूल बताता है कि नतीजा उम्मीद के मुताबिक था या नहीं।

तकनीकी सामग्री (मूल SKILL.md)

लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।

Web3 Smart Contract Testing

Master comprehensive testing strategies for smart contracts using Hardhat, Foundry, and advanced testing patterns.

When to Use This Skill

  • Writing unit tests for smart contracts
  • Setting up integration test suites
  • Performing gas optimization testing
  • Fuzzing for edge cases
  • Forking mainnet for realistic testing
  • Automating test coverage reporting
  • Verifying contracts on Etherscan

Hardhat Testing Setup

// hardhat.config.js
require("@nomicfoundation/hardhat-toolbox");
require("@nomiclabs/hardhat-etherscan");
require("hardhat-gas-reporter");
require("solidity-coverage");

module.exports = {
  solidity: {
    version: "0.8.19",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200,
      },
    },
  },
  networks: {
    hardhat: {
      forking: {
        url: process.env.MAINNET_RPC_URL,
        blockNumber: 15000000,
      },
    },
    goerli: {
      url: process.env.GOERLI_RPC_URL,
      accounts: [process.env.PRIVATE_KEY],
    },
  },
  gasReporter: {
    enabled: true,
    currency: "USD",
    coinmarketcap: process.env.COINMARKETCAP_API_KEY,
  },
  etherscan: {
    apiKey: process.env.ETHERSCAN_API_KEY,
  },
};

Unit Testing Patterns

const { expect } = require("chai");
const { ethers } = require("hardhat");
const {
  loadFixture,
  time,
} = require("@nomicfoundation/hardhat-network-helpers");

describe("Token Contract", function () {
  // Fixture for test setup
  async function deployTokenFixture() {
    const [owner, addr1, addr2] = await ethers.getSigners();

    const Token = await ethers.getContractFactory("Token");
    const token = await Token.deploy();

    return { token, owner, addr1, addr2 };
  }

  describe("Deployment", function () {
    it("Should set the right owner", async function () {
      const { token, owner } = await loadFixture(deployTokenFixture);
      expect(await token.owner()).to.equal(owner.address);
    });

    it("Should assign total supply to owner", async function () {
      const { token, owner } = await loadFixture(deployTokenFixture);
      const ownerBalance = await token.balanceOf(owner.address);
      expect(await token.totalSupply()).to.equal(ownerBalance);
    });
  });

  describe("Transactions", function () {
    it("Should transfer tokens between accounts", async function () {
      const { token, owner, addr1 } = await loadFixture(deployTokenFixture);

      await expect(token.transfer(addr1.address, 50)).to.changeTokenBalances(
        token,
        [owner, addr1],
        [-50, 50],
      );
    });

    it("Should fail if sender doesn't have enough tokens", async function () {
      const { token, addr1 } = await loadFixture(deployTokenFixture);
      const initialBalance = await token.balanceOf(addr1.address);

      await expect(
        token.connect(addr1).transfer(owner.address, 1),
      ).to.be.revertedWith("Insufficient balance");
    });

    it("Should emit Transfer event", async function () {
      const { token, owner, addr1 } = await loadFixture(deployTokenFixture);

      await expect(token.transfer(addr1.address, 50))
        .to.emit(token, "Transfer")
        .withArgs(owner.address, addr1.address, 50);
    });
  });

  describe("Time-based tests", function () {
    it("Should handle time-locked operations", async function () {
      const { token } = await loadFixture(deployTokenFixture);

      // Increase time by 1 day
      await time.increase(86400);

      // Test time-dependent functionality
    });
  });

  describe("Gas optimization", function () {
    it("Should use gas efficiently", async function () {
      const { token } = await loadFixture(deployTokenFixture);

      const tx = await token.transfer(addr1.address, 100);
      const receipt = await tx.wait();

      expect(receipt.gasUsed).to.be.lessThan(50000);
    });
  });
});

Foundry Testing (Forge)

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "forge-std/Test.sol";
import "../src/Token.sol";

contract TokenTest is Test {
    Token token;
    address owner = address(1);
    address user1 = address(2);
    address user2 = address(3);

    function setUp() public {
        vm.prank(owner);
        token = new Token();
    }

    function testInitialSupply() public {
        assertEq(token.totalSupply(), 1000000 * 10**18);
    }

    function testTransfer() public {
        vm.prank(owner);
        token.transfer(user1, 100);


…
अक्सर पूछे जाने वाले सवाल

स्मार्ट कॉन्ट्रैक्ट क्या होते हैं?

ये ब्लॉकचेन पर चलने वाले प्रोग्राम हैं। जब कुछ शर्तें पूरी होती हैं, तो ये अपने-आप काम कर देते हैं, जैसे किसी समझौते के पूरा होने पर पैसे ट्रांसफ़र करना।

Hardhat और Foundry क्या हैं?

ये दोनों लोकप्रिय टूल हैं, जो डेवलपर्स को ब्लॉकचेन के लिए स्मार्ट कॉन्ट्रैक्ट बनाने, टेस्ट करने और मैनेज करने में मदद करते हैं।

'forking the mainnet' का क्या मतलब है?

इसका मतलब है मुख्य ब्लॉकचेन (जैसे Ethereum) की एक अस्थायी कॉपी बनाना, ताकि आप अपने कॉन्ट्रैक्ट को असली जैसे माहौल में टेस्ट कर सकें, बिना असली सिस्टम पर कोई असर डाले।

जानकारी

लेखक का मूल विवरण

Test smart contracts comprehensively using Hardhat and Foundry with unit tests, integration tests, and mainnet forking. Use when testing Solidity contracts, setting up blockchain test suites, or validating DeFi protocols.

repo: wshobson/agents

लोकप्रियता

GitHub स्टार
41k
रैंकिंग में स्थान
#6649
लाइसेंस
MIT
अपडेट की गई
15/10/2026

क्या यह skill काम की है?

0

लॉग इन करें वोट करने के लिए।

कमेंट

  • …

इस repository की और skills

मिलती-जुलती skills