ホーム
  • キャンバス
  • 画像
  • 動画
  • 音声
  • MCP / CLI
  • モデル
  • スキル
  • ツール
料金プランログイン新規登録

作成

  • AI 動画
  • AI 画像
  • 画像から動画
  • テキストから動画
  • AI 動画編集
  • 画像アップスケール
  • 画像編集

画像作成・編集

  • 画像を作成

画像モデル

  • GPT Image 2.6 Sunburst
  • GPT Image 2.6 Flare
  • GPT Image 2.5 Sunburst
  • GPT Image 2.5 Flare
  • Nano Banana 2.1

動画作成・編集

  • 動画を作成
  • エフェクト
  • 画像から動画生成
  • テキストから動画生成
  • 動画を編集
  • 動画アップスケール
  • ミックスメディア
  • 顔の入れ替え

動画モデル

  • Seedance 2.5
  • Kling 4.0
  • Kling 4.0 Flash
  • Gemini Omni Flash 1.2
  • FLUX.3 Video

オーディオ

  • テキスト読み上げ
  • ボイスチェンジ
  • 翻訳

オーディオモデル

  • Seed Audio 1.0
  • Eleven v4
  • Eleven v4 Turbo
  • Eleven v3
  • Qwen Audio 3.0

スタジオ

  • マーケティングスタジオ
  • リップシンク
  • キャンバス

プラットフォーム

  • MCP
  • CLI
  • モデル
  • モデルプロバイダー
  • スキル
  • ツール
  • ツールプロバイダー

会社情報

  • エージェントインストラクション
  • ヘルプセンター
  • 利用規約
  • プライバシー
  • 脆弱性を報告

開発者

  • ドキュメント
  • API リファレンス
  • 開発者プラットフォーム
  • AI サイトマップ
© 2026 ドットメディア株式会社 すべての権利を留保します。
すべてのスキルランキングマイリスト
業務領域
リポジトリ
スキル開発者
作業
成果物
連携サービス
呼び出し方
  1. ホーム
  2. スキル
  1. ホーム
  2. スキル
  3. SKILL.md
ファイル
wshobson
agents
.agents
.claude-plugin
.cursor
.cursor-plugin
.github
docs
evals
plugins
accessibility-compliance
agent-orchestration
agent-teams
api-scaffolding
api-testing-observability
application-performance
arm-cortex-microcontrollers
avoid-ai-writing
backend-api-security
backend-development
before-you-build
block-no-verify
blockchain-web3
.claude-plugin
.codex-plugin
agents
skills
defi-protocol-templates
nft-standards
solidity-security
web3-testing
references
SKILL.md
brand-landingpage
business-analytics
c4-architecture
cicd-automation
cloud-infrastructure
code-documentation
code-refactoring
codebase-cleanup
comprehensive-review
conductor
content-marketing
ブランチタグ
c96b5f6原文を開く
Wwshobson·2026/11/24
未翻訳
311 行(空行を除く 246 行) · 7.72 KB·原文
name: web3-testing
description: 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.

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);
​
        assertEq(token.balanceOf(user1), 100);
        assertEq(token.balanceOf(owner), token.totalSupply() - 100);
    }
​
    function testFailTransferInsufficientBalance() public {
        vm.prank(user1);
        token.transfer(user2, 100); // Should fail
    }
​
    function testCannotTransferToZeroAddress() public {
        vm.prank(owner);
        vm.expectRevert("Invalid recipient");
        token.transfer(address(0), 100);
    }
​
    // Fuzzing test
    function testFuzzTransfer(uint256 amount) public {
        vm.assume(amount > 0 && amount <= token.totalSupply());
​
        vm.prank(owner);
        token.transfer(user1, amount);
​
        assertEq(token.balanceOf(user1), amount);
    }
​
    // Test with cheatcodes
    function testDealAndPrank() public {
        // Give ETH to address
        vm.deal(user1, 10 ether);
​
        // Impersonate address
        vm.prank(user1);
​
        // Test functionality
        assertEq(user1.balance, 10 ether);
    }
​
    // Mainnet fork test
    function testForkMainnet() public {
        vm.createSelectFork("https://eth-mainnet.alchemyapi.io/v2/...");
​
        // Interact with mainnet contracts
        address dai = 0x6B175474E89094C44Da98b954EedeAC495271d0F;
        assertEq(IERC20(dai).symbol(), "DAI");
    }
}

Advanced Testing Patterns

Snapshot and Revert

describe("Complex State Changes", function () {
  let snapshotId;
​
  beforeEach(async function () {
    snapshotId = await network.provider.send("evm_snapshot");
  });
​
  afterEach(async function () {
    await network.provider.send("evm_revert", [snapshotId]);
  });
​
  it("Test 1", async function () {
    // Make state changes
  });
​
  it("Test 2", async function () {
    // State reverted, clean slate
  });
});

Mainnet Forking

describe("Mainnet Fork Tests", function () {
  let uniswapRouter, dai, usdc;
​
  before(async function () {
    await network.provider.request({
      method: "hardhat_reset",
      params: [
        {
          forking: {
            jsonRpcUrl: process.env.MAINNET_RPC_URL,
            blockNumber: 15000000,
          },
        },
      ],
    });
​
    // Connect to existing mainnet contracts
    uniswapRouter = await ethers.getContractAt(
      "IUniswapV2Router",
      "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D",
    );
​
    dai = await ethers.getContractAt(
      "IERC20",
      "0x6B175474E89094C44Da98b954EedeAC495271d0F",
    );
  });
​
  it("Should swap on Uniswap", async function () {
    // Test with real Uniswap contracts
  });
});

Impersonating Accounts

it("Should impersonate whale account", async function () {
  const whaleAddress = "0x...";
​
  await network.provider.request({
    method: "hardhat_impersonateAccount",
    params: [whaleAddress],
  });
​
  const whale = await ethers.getSigner(whaleAddress);
​
  // Use whale's tokens
  await dai
    .connect(whale)
    .transfer(addr1.address, ethers.utils.parseEther("1000"));
});

Additional patterns and templates

More detailed templates and worked examples live in details.md. Read that file for the full pattern library.