Tests dockerization (#48)

* add tests dockerization

* fixed compile with library test

* made Dockerfile dynamic

* removed dockerized coverage

* removed alpine, dockerized coverage

* moved test-docker command to script

* try to improve docker

* update dockerignore

---------

Co-authored-by: Artem Chystiakov <artem.ch31@gmail.com>
This commit is contained in:
Mllw Chrry
2024-11-01 04:44:08 -07:00
committed by GitHub
parent 755e538afe
commit f9009fd280
9 changed files with 95 additions and 42 deletions

36
.dockerignore Normal file
View File

@@ -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

View File

@@ -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
.gitignore vendored
View File

@@ -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
@@ -41,7 +39,5 @@ pids
typings/
**/.storage.json
# Optional npm cache directory
.npm
!src/**/artifacts
# Exclude
!src/**/artifacts

15
Dockerfile Normal file
View File

@@ -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"]

View File

@@ -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"

View File

@@ -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
scripts/test-docker.sh Normal file
View File

@@ -0,0 +1,4 @@
#!/usr/bin/env bash
docker build -t hardhat-zkit --progress=plain .
docker run --rm hardhat-zkit test-local

View File

@@ -1,4 +1,4 @@
import { join, dirname } from "path";
import { join } from "path";
import fsExtra from "fs-extra";
import { resetHardhatContext } from "hardhat/plugins-testing";
@@ -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();

View File

@@ -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";
@@ -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 });
@@ -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 });
});
});