Skip to content

Commit

Permalink
Major Refactors (#82)
Browse files Browse the repository at this point in the history
* migrate tests under their own folder

* more refactors + `pkgroll` added

* todo commander

* migrate CLI to `commander`

* fixed proof tester types

* added `list` command

* use jest, use pnpm, more refactors & renames & typings

* remove redundant hardhats, better jest

* up version
  • Loading branch information
erhant authored May 18, 2024
1 parent c9f951a commit f210e06
Show file tree
Hide file tree
Showing 66 changed files with 8,767 additions and 6,460 deletions.
12 changes: 11 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@
}
]
},
"ignorePatterns": ["build", "node_modules", "ptau", "circuits", "inputs", "dist", ".vscode", ".github"],
"ignorePatterns": [
"build",
"node_modules",
"ptau",
"circuits",
"inputs",
"dist",
".vscode",
".github",
"jest.config.js"
],
"overrides": [
{
"files": ["**/*.ts", "**/*.tsx"],
Expand Down
23 changes: 17 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Publish to NPM
name: npm

on:
release:
Expand All @@ -8,16 +8,27 @@ jobs:
publish:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20]

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v3
- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: 9

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- run: yarn
- run: yarn build
- uses: JS-DevTools/npm-publish@v3
id: publish
with:
Expand Down
22 changes: 17 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20]

steps:
- uses: actions/checkout@v4

Expand All @@ -31,11 +35,19 @@ jobs:
- name: Print Circom version
run: circom --version

- name: Install dependencies
run: yarn
- name: Install pnpm
uses: pnpm/action-setup@v3
with:
version: 9

- name: Build everything
run: yarn build
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Run tests
run: yarn test
run: pnpm test
9 changes: 1 addition & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,6 @@ dist
# is this still a thing lol
.DS_Store

# ignore auto generated test circuits
**/test/*.circom

# for init tests
tmptest
inputs/multiplier_3/test-input.json

# Hardhat files
/cache
/artifacts
/artifacts
7 changes: 0 additions & 7 deletions .mocharc.json

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"recommendations": ["iden3.circom"]
"recommendations": ["iden3.circom", "firsttris.vscode-jest-runner"]
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"inputs": "Json",
"ptau": "Secure",
"zkey": "Functions",
"ejs": "JavaScript"
"ejs": "JavaScript",
"testers": "Test"
},
// https://raw.githubusercontent.com/PKief/vscode-material-icon-theme/main/images/fileIcons.png
"material-icon-theme.files.associations": {
Expand Down
24 changes: 13 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ Circomkit can be installed via:
npm install circomkit
pnpm install circomkit
yarn add circomkit
bun add circomkit
```

You will also need [Circom](https://docs.circom.io), which can be installed following the instructions [here](https://docs.circom.io/getting-started/installation/).

## Usage

You can setup a new project with the following:
You can see available commands with:

```sh
npx circomkit init
npx circomkit help
```

You can check out examples at the [circomkit-examples](https://github.com/erhant/circomkit-examples) repository.
Expand Down Expand Up @@ -169,7 +170,7 @@ describe('witness tester', () => {
// this makes all functions type-safe!
let circuit: WitnessTester<['in'], ['out']>;

before(async () => {
beforeAll(async () => {
const circomkit = new Circomkit();
circuit = await circomkit.WitnessTester(CIRCUIT_NAME, CIRCUIT_CONFIG);
});
Expand Down Expand Up @@ -250,7 +251,7 @@ describe('proof tester', () => {
// this makes all functions type-safe!
let circuit: ProofTester<['in']>;
before(async () => {
beforeAll(async () => {
const circomkit = new Circomkit({
protocol: 'plonk',
});
Expand Down Expand Up @@ -324,24 +325,25 @@ circomkit
Run all tests via:

```sh
yarn test
pnpm test
```

> [!TIP]
>
> You can also use the CLI while developing Circomkit locally via `yarn cli` as if you are using `npx circomkit`. This is useful for hands-on testing stuff.
> You can also use the CLI while developing Circomkit locally via `pnpm cli` as if you are using `npx circomkit`. This is useful for hands-on testing stuff.
## Styling

Circomkit uses [Google TypeScript Style Guide](https://google.github.io/styleguide/tsguide.html).

```sh
# check the formatting
yarn format
pnpm format

# lint everything
yarn lint

# do both at once
yarn style
pnpm lint
```

## Acknowledgements

We wholeheartedly thank [BuidlGuild](https://buidlguidl.com/) & [Austin Griffith](https://twitter.com/austingriffith) for providing Circomkit with an [Ecosystem Impact Grant](https://grants.buidlguidl.com/)!
7 changes: 6 additions & 1 deletion circomkit.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,10 @@
"verbose": true,
"prime": "bn128",
"optimization": 1,
"protocol": "groth16"
"protocol": "groth16",
"circuits": "./tests/circuits.json",
"dirPtau": "./tests/ptau",
"dirCircuits": "./tests/circuits",
"dirInputs": "./tests/inputs",
"dirBuild": "./tests/build"
}
17 changes: 17 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
verbose: true,
rootDir: './tests',
globalTeardown: '<rootDir>/hooks/teardown.js',
forceExit: true,
transform: {
'^.+\\.test.(ts|js)$': [
'ts-jest',
{
tsconfig: './tsconfig.test.json',
},
],
},
};
86 changes: 45 additions & 41 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
{
"name": "circomkit",
"version": "0.1.0",
"version": "0.2.0",
"description": "A Circom testing & development environment",
"author": "erhant",
"license": "MIT",
"scripts": {
"build": "pkgroll",
"prebuild": "rm -rf dist/",
"cli:nb": "node ./dist/cli.cjs",
"cli": "pnpm build && pnpm cli:nb",
"test": "jest",
"check": "npx tsc --noEmit",
"lint": "npx eslint '**/*.ts' && echo 'All good!'",
"format": "npx prettier --check ./src/**/*.ts ./tests/**/*.ts"
},
"engines": {
"node": ">=12.0.0"
},
Expand All @@ -12,43 +22,38 @@
"LICENSE",
"README.md"
],
"bin": "dist/bin/index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"homepage": "https://github.com/erhant/circomkit#readme",
"repository": {
"type": "git",
"url": "https://github.com/erhant/circomkit.git"
"bin": "./dist/cli.js",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.cts",
"exports": {
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
},
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
}
},
"bugs": {
"url": "https://github.com/erhant/circomkit/issues/"
"peerDependencies": {
"@types/snarkjs": "^0.7.x",
"snarkjs": "^0.7.x"
},
"scripts": {
"build": "npx tsc -p tsconfig.build.json",
"prebuild": "rimraf dist/",
"cli": "yarn build && node ./dist/bin",
"test": "npx mocha",
"pretest": "rimraf build/",
"check": "npx tsc --noEmit",
"style": "yarn format && yarn lint",
"lint": "npx eslint '**/*.ts' && echo 'All good!'",
"format": "npx prettier --check ./src/**/*.ts ./tests/**/*.ts"
"dependencies": {
"circom_tester": "^0.0.19",
"commander": "^12.0.0",
"loglevel": "^1.8.1"
},
"devDependencies": {
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
"@commander-js/extra-typings": "^12.0.1",
"@nomicfoundation/hardhat-ethers": "^3.0.0",
"@nomicfoundation/hardhat-ignition": "^0.15.0",
"@nomicfoundation/hardhat-ignition-ethers": "^0.15.0",
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"@nomicfoundation/hardhat-verify": "^2.0.0",
"@typechain/ethers-v6": "^0.5.0",
"@typechain/hardhat": "^9.0.0",
"@types/chai": "^4.3.4",
"@types/mocha": "^10.0.1",
"@types/mocha-each": "^2.0.0",
"@types/jest": "^29.5.12",
"@types/node": "^18.11.18",
"@types/snarkjs": "^0.7.8",
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"eslint": "^8.54.0",
Expand All @@ -57,23 +62,14 @@
"eslint-plugin-prettier": "^5.0.1",
"ethers": "^6.4.0",
"hardhat": "^2.14.0",
"hardhat-gas-reporter": "^1.0.8",
"mocha": "^10.2.0",
"mocha-each": "^2.0.1",
"jest": "^29.7.0",
"pkgroll": "^2.0.2",
"prettier": "^3.1.0",
"rimraf": "^5.0.1",
"solc": "^0.8.25",
"solidity-coverage": "^0.8.0",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.1",
"typechain": "^8.3.0",
"typescript": "^5.3.2"
},
"dependencies": {
"chai": "^4.3.7",
"circom_tester": "^0.0.19",
"loglevel": "^1.8.1",
"snarkjs": "^0.7.0"
},
"prettier": {
"bracketSpacing": false,
"singleQuote": true,
Expand All @@ -89,5 +85,13 @@
"cli",
"tooling",
"blockchain"
]
],
"homepage": "https://github.com/erhant/circomkit#readme",
"repository": {
"type": "git",
"url": "https://github.com/erhant/circomkit.git"
},
"bugs": {
"url": "https://github.com/erhant/circomkit/issues/"
}
}
Loading

0 comments on commit f210e06

Please sign in to comment.