npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

test-hardhat-testgen

v1.0.7

Published

Hardhat 3 plugin that helps you auto-generate unit tests for your Hardhat Solidity smart contracts

Readme

Hardhat TestGen

Hardhat TestGen is a Hardhat 3 plugin that automatically generates basic unit test templates for your Solidity smart contracts.

  • https://hardhat.org/docs/getting-started#solidity-tests

Community plugin. Not affiliated with the Nomic Foundation. Demo version.

Features

  • Generate Solidity tests using the testgen command based on the contract ABI

  • Generate Solidity tests using the aitestgen command powered by Claude AI

Overview

Hardhat TestGen accelerates your testing workflow by generating starter test files for your Solidity contracts. It is built primarily for hackathon and prototyping use and is not yet battle-tested for complex production contracts.

  • Generates initial test structures to save setup time

  • Developers should extend and refine generated tests

  • May contain bugs or limitations

  • Currently assumes default Hardhat directory structure (does not yet support custom paths)

Installation

pnpm i -D test-hardhat-testgen
# or
pnpm i --save-dev test-hardhat-testgen

In your hardhat.config.ts, for example:

import { HardhatUserConfig } from "hardhat/config";
import hardhatTestGenPlugin from "test-hardhat-testgen";

export default {
  plugins: [hardhatTestGenPlugin],
  solidity: "0.8.28",
  testGenConfig: {
    anthropicApiKey: "sk-..." // Needed only for aitestgen task
  },
} satisfies HardhatUserConfig;

Usage

From your project root:

pnpm hardhat testgen --run

CLI Options:

| Flag | Description | Default | | ------------ | ------------------------------------ | ------- | | --suppress | Suppress debug logs | false | | --run | Run tests after generation | false | | --skip | Skip overwriting existing test files | false |

Example:

pnpm hardhat testgen --suppress --run --skip

You can also run tests after generation:

pnpm hardhat test solidity
# or
pnpm hardhat test

AI Mode

New Feature: generate Solidity Tests with Claude AI (Anthropic)!

Currently supported model: claude-3-5-sonnet-latest.

Setup

  • Obtain Anthropic API key from: https://console.anthropic.com/settings/keys

Add it to hardhat.config.ts:

testGenConfig: {
    anthropicApiKey: "sk-..."
},

Usage

From your project root, run:

pnpm hardhat aitestgen --run

The CLI options are the same as for the testgen task (--run, --suppress, --skip).

Example

Contract:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

contract Counter {
    uint public x;

    event Increment(uint by);

    function inc() public {
        x++;
        emit Increment(1);
    }

    function incBy(uint by) public {
        require(by > 0, "incBy: increment should be positive");
        x += by;
        emit Increment(by);
    }
}

Generated Test:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

import { Counter } from "./Counter.sol";
import { Test } from "forge-std/Test.sol";

contract CounterTest is Test {
  Counter testContract;

  function setUp() public {
    testContract = new Counter();
  }

  function test_InitialValue() public view {
    require(testContract.x() == 0, "Initial value should be 0");
  }

  function test_inc_Call() public {
    testContract.inc();
  }

  function testFuzz_Inc(uint8 n) public {
    for (uint8 i = 0; i < n; i++) {
      testContract.inc();
    }
    require(testContract.x() == n, "Value after calling inc n times should be n");
  }

  function test_incBy_ByZero() public {
    vm.expectRevert();
    testContract.incBy(0);
  }

  function test_incBy_Call() public {
    testContract.incBy(1);
  }
}

Development

pnpm install
pnpm build

Publish:

cd packages/plugin
npm publish

Run locally using the example project:

cd packages/example-project
pnpm hardhat testgen

For more information:

  • https://github.com/NomicFoundation/hardhat3-plugin-template
  • https://hardhat.org/plugin-development

Disclaimer

This software is provided “as is”, without any warranties or guarantees regarding stability, security, or suitability for production use. Use at your own risk.

If you encounter issues, please report them on GitHub.