Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests dockerization #48

Merged
merged 8 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
node_modules
.DS_Store
.idea
.vscode
.npm
.eslintcache
Dockerfile
.git
.gitignore
.env

# Compilation output
/build-test/
/dist

# Coverage
.nyc_output
coverage.json
coverage

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# node-waf configuration
.lock-wscript
23 changes: 8 additions & 15 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,14 @@ jobs:
- 18
- 20
steps:
- uses: actions/setup-node@v3
with:
node-version: '${{ matrix.node }}'
- name: Checkout the repository
uses: actions/checkout@v3

- uses: actions/checkout@v3
- name: 'Cache node_modules'
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-v${{ matrix.node }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-node-v${{ matrix.node }}
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Install Dependencies
run: npm install
- name: Build Docker image
run: docker build --build-arg NODE_VERSION=${{ matrix.node }} -t hardhat-zkit-node${{ matrix.node }} --progress=plain .

- name: Run All Tests
run: npm run test
- name: Run tests
run: docker run --rm hardhat-zkit-node${{ matrix.node }} test-local
20 changes: 8 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
node_modules
.DS_Store
.idea
.vscode
.eslintcache
.env
.npm

# Hardhat files
artifacts
coverage.json
coverage

publish
!publish/package.json

# Compilation output
/build-test/
/dist

# Coverage
.nyc_output

# Below is Github's node gitignore template,
# ignoring the node_modules part, as it'd ignore every node_modules, and we have some for testing
coverage.json
coverage

# Logs
logs
Expand All @@ -41,7 +39,5 @@ pids
typings/
**/.storage.json

# Optional npm cache directory
.npm

!src/**/artifacts
# Exclude
!src/**/artifacts
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ARG NODE_VERSION=20

FROM node:${NODE_VERSION} AS base
WORKDIR /hardhat-zkit

FROM base AS install
RUN mkdir -p /temp/dev
COPY package.json package-lock.json /temp/dev/
RUN cd /temp/dev && npm ci

FROM base AS dev
COPY --from=install /temp/dev/node_modules node_modules
COPY . .

ENTRYPOINT ["npm", "run"]
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@
"compile": "npm run prepare-tests && npm run build",
"build": "tsc --build .",
"prepare-tests": "npm run compile --workspaces",
"test": "mocha --recursive 'test/**/*.ts' --exit",
"coverage": "nyc mocha --recursive 'test/**/*.ts' --exit",
"test": "npm run test-docker",
"test-docker": "bash scripts/test-docker.sh",
"test-local": "mocha --recursive 'test/**/*.ts' --exit",
"coverage": "npm run coverage-docker",
"coverage-docker": "bash scripts/coverage-docker.sh",
"coverage-local": "nyc mocha --recursive 'test/**/*.ts' --exit",
"clean-tests": "npm run clean --workspaces",
"lint-fix": "prettier --write \"./**/*.ts\" && eslint \"{src,test}/**/*.{js,ts}\" --cache --fix",
"publish-to-npm": "npm run build && npm run lint-fix && npm publish ./ --access public"
Expand Down
4 changes: 4 additions & 0 deletions scripts/coverage-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

docker build -t hardhat-zkit --progress=plain .
docker run --rm -v $(pwd)/coverage:/hardhat-zkit/coverage hardhat-zkit coverage-local
4 changes: 4 additions & 0 deletions scripts/test-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

docker build -t hardhat-zkit --progress=plain .
docker run --rm hardhat-zkit test-local
6 changes: 1 addition & 5 deletions test/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join, dirname } from "path";
import { join } from "path";
import fsExtra from "fs-extra";

import { resetHardhatContext } from "hardhat/plugins-testing";
Expand Down Expand Up @@ -32,10 +32,6 @@ export function useEnvironment(fixtureProjectName: string, withCleanUp: boolean
});
}

export function getProjectRootPath(): string {
return dirname(__dirname);
}

export function cleanUp(rootPath: string) {
resetCircuitsCompileCache();
resetCircuitsSetupCache();
Expand Down
21 changes: 13 additions & 8 deletions test/unit/core/compile/circom-compiler.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import fsExtra from "fs-extra";
import { execSync } from "child_process";

import { expect } from "chai";

import { getProjectRootPath, useEnvironment } from "@test-helpers";
import { useEnvironment } from "@test-helpers";
import { getNormalizedFullPath } from "@src/utils/path-utils";
import { CircomCompilerFactory, createCircomCompilerFactory, WASMCircomCompiler } from "@src/core";

Expand Down Expand Up @@ -159,14 +160,15 @@ describe("WASMCircomCompiler", () => {
});

it("should correctly compile circuit with library include", async function () {
const circuitFullPath: string = getNormalizedFullPath(this.hre.config.paths.root, "circuits/hash2.circom");
const artifactsFullPath: string = getNormalizedFullPath(
this.hre.config.paths.root,
"zkit/artifacts/test/hash2.circom",
);
const root = this.hre.config.paths.root;

execSync("npm install --no-workspaces", { cwd: root });

const circuitFullPath: string = getNormalizedFullPath(root, "circuits/hash2.circom");
const artifactsFullPath: string = getNormalizedFullPath(root, "zkit/artifacts/test/hash2.circom");
const errorFileFullPath: string = getNormalizedFullPath(artifactsFullPath, "errors.log");
const typesDir: string = getNormalizedFullPath(this.hre.config.paths.root, "generated-types/zkit");
const nodeModulesPath: string = getNormalizedFullPath(getProjectRootPath(), NODE_MODULES);
const typesDir: string = getNormalizedFullPath(root, "generated-types/zkit");
const nodeModulesPath: string = getNormalizedFullPath(root, NODE_MODULES);

fsExtra.rmSync(artifactsFullPath, { recursive: true, force: true });
fsExtra.mkdirSync(artifactsFullPath, { recursive: true });
Expand All @@ -185,6 +187,9 @@ describe("WASMCircomCompiler", () => {
expect(fsExtra.readdirSync(artifactsFullPath)).to.be.deep.eq(["hash2.r1cs", "hash2.sym", "hash2_js"]);

fsExtra.rmSync(typesDir, { recursive: true, force: true });

fsExtra.rmSync(`${root}/node_modules`, { recursive: true, force: true });
fsExtra.rmSync(`${root}/package-lock.json`, { recursive: true, force: true });
});
});

Expand Down
Loading