Chuyển đến nội dung
Skillpedia
Kiểm thử48k · #6162

web3-testing

Skill này làm gì

Skill này giúp kiểm thử smart contract tiền điện tử. Nó dùng các công cụ như Hardhat và Foundry để đảm bảo mã hoạt động đúng và an toàn.

Khi nào nên dùng

  • ✓Khi bạn đang viết mã cho một smart contract.
  • ✓Để xác minh hợp đồng hoạt động đúng trong các tình huống khác nhau.
  • ✓Để tìm và sửa lỗi trước khi ra mắt hợp đồng.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/web3-testing/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/web3-testing/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Làm sao để kiểm thử hợp đồng token của tôi, đảm bảo việc chuyển token hoạt động đúng?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill dùng các môi trường kiểm thử như Hardhat và Foundry để mô phỏng hành vi của hợp đồng. Nó chạy các bài kiểm thử đã định sẵn, kiểm tra kết quả có đúng như mong đợi không, và báo cáo mọi vấn đề.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Supporting material availability

This catalog copy contains the inline guidance below, but does not include the following supporting paths. They are external prerequisites, not bundled files:

  • <support-root>/references/hardhat-setup.md
  • <support-root>/references/foundry-setup.md
  • <support-root>/references/test-patterns.md
  • <support-root>/references/mainnet-forking.md
  • <support-root>/references/contract-verification.md
  • <support-root>/assets/hardhat-config.js
  • <support-root>/assets/test-suite.js
  • <support-root>/assets/foundry.toml
  • <support-root>/scripts/test-contract.sh

Ask for the original supporting material or an existing installation before using a step that depends on these paths; this catalog does not identify a verified download source for them. Resolve each path relative to that installation, inspect its contents, and verify any applicable license and execution prerequisites. Do not run a command or claim a referenced procedure was followed until its required file exists. Do not fabricate the missing scripts or treat an unrelated file with the same name as equivalent. Independent steps fully documented here can proceed within the user’s authorized scope; report any dependent step as unavailable.

Web3 Smart Contract Testing

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

Do not use this skill when

  • The task is unrelated to web3 smart contract testing
  • You need a different domain or tool outside this scope

Instructions

  • Clarify goals, constraints, and required inputs.
  • Apply relevant best practices and validate outcomes.
  • Provide actionable steps and verification.

Use this skill when

  • 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),

…
Câu hỏi thường gặp

Smart contract là gì?

Đó là các chương trình chạy trên mạng blockchain và tự động thực hiện hành động khi các điều kiện nhất định được đáp ứng, như chuyển tiền điện tử.

Hardhat và Foundry là gì?

Đó là các công cụ phổ biến giúp lập trình viên xây dựng, kiểm thử và quản lý smart contract.

Vì sao kiểm thử smart contract quan trọng?

Smart contract xử lý giá trị và rất khó thay đổi sau khi triển khai. Kiểm thử đảm bảo chúng an toàn và hoạt động đúng như thiết kế, tránh thiệt hại tài chính.

Chi tiết

Mô tả gốc của tác giả

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

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#6162
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự