
Security News
Axios Maintainer Confirms Social Engineering Attack Behind npm Compromise
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.
hardhat-testgen
Advanced tools
Hardhat 3 plugin that helps you auto-generate unit tests for your Hardhat Solidity smart contracts
Hardhat TestGen is a Hardhat 3 plugin that automatically generates basic unit test templates for your Solidity smart contracts.
Community plugin. Not affiliated with the Nomic Foundation. Demo version.
Generate Solidity tests using the testgen command based on the contract ABI
Generate Solidity tests using the aitestgen command powered by Claude AI
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)
pnpm i -D hardhat-testgen
# or
pnpm i --save-dev hardhat-testgen
In your hardhat.config.ts, for example:
import { HardhatUserConfig } from "hardhat/config";
import hardhatTestGenPlugin from "hardhat-testgen";
export default {
plugins: [hardhatTestGenPlugin],
solidity: "0.8.28",
testGenConfig: {
anthropicApiKey: "sk-..." // Needed only for aitestgen task
},
} satisfies HardhatUserConfig;
From your project root:
pnpm hardhat testgen --run
| 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
New Feature: generate Solidity Tests with Claude AI (Anthropic)!
Currently supported model: claude-3-5-sonnet-latest.
Add it to hardhat.config.ts:
testGenConfig: {
anthropicApiKey: "sk-..."
},
From your project root, run:
pnpm hardhat aitestgen --run
The CLI options are the same as for the testgen task (--run, --suppress, --skip).
// 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);
}
}
// 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);
}
}
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:
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.
FAQs
Hardhat 3 plugin that helps you auto-generate unit tests for your Hardhat Solidity smart contracts
We found that hardhat-testgen demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.