CTF is a command-line tool that helps you generate comprehensive test cases for Solidity smart contracts using AI. It analyzes your contract functions and generates TypeScript test files using Hardhat and ethers.js.
- π Automatic contract function analysis
- π€ AI-powered test case generation
- β¨ TypeScript support with proper type annotations
- π§ͺ Hardhat and ethers.js integration
- π Comprehensive test coverage
- π Easy to use CLI interface
You can install CTF in two ways:
Download the appropriate binary for your system:
- Linux (AMD64):
ctf_linux_amd64 - macOS (ARM64/M1/M2):
ctf_darwin_arm64
Make the binary executable:
chmod +x ctf_linux_amd64 # or ctf_darwin_arm64git clone https://github.com/your-username/contract-test-forge.git
cd contract-test-forgenpm installnpm run buildnpm linkcd examples/eth
ctf initmodel: "gpt-4o" # or your preferred model
api_key: "your-api-key-here"Generate test cases for a specific contract:
ctf gent -f Faucet.solGenerate test cases for a specific method:
ctf gent -f Faucet.sol -m withdrawAuto-confirm test cases:
ctf gent -f Faucet.sol -yThen the test cases will be generated in the test directory.
your-project/
βββ contracts/ # Your Solidity contracts
βββ test/ # Generated test files
βββ .ctf/ # CTF configuration
β βββ project.yaml # Project configuration
β βββ ai.yaml # AI configuration
Generated test files follow this structure:
- Import statements for required dependencies
- Contract deployment fixtures
- Test cases grouped by method
- Proper TypeScript types and async/await syntax
Example:
import { expect } from "chai";
import { ethers } from "hardhat";
import { Contract, SignerWithAddress } from "ethers";
describe("YourContract", () => {
let contract: Contract;
let owner: SignerWithAddress;
beforeEach(async () => {
// Setup code...
});
describe("methodName", () => {
it("should handle valid input", async () => {
// Test implementation...
});
});
});npm installnpm run buildnpm run pkgsrc/
βββ command/ # CLI commands
βββ lib/ # Core functionality
βββ types.ts # TypeScript types
βββ constants.ts # Constants
βββ index.ts # Entry point
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
