From f520b1deee31287ca2ebe7927b1dacdbb7a5774f Mon Sep 17 00:00:00 2001 From: zimpha Date: Thu, 6 Jun 2024 15:07:51 +0800 Subject: [PATCH 1/2] feat: add github workflow --- .eslintignore | 3 + .github/workflows/contracts.yml | 135 ++++++++++++++++++++++++++++++++ .gitignore | 3 + .prettierignore | 5 +- 4 files changed, 143 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/contracts.yml diff --git a/.eslintignore b/.eslintignore index 85f5562..09c99e4 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,4 +1,7 @@ node_modules artifacts +artifacts-hardhat cache +cache-hardhat coverage +typechain diff --git a/.github/workflows/contracts.yml b/.github/workflows/contracts.yml new file mode 100644 index 0000000..0ef0037 --- /dev/null +++ b/.github/workflows/contracts.yml @@ -0,0 +1,135 @@ +name: Contracts + +on: + push: + branches: + - main + paths: + - '**' + - '.github/workflows/contracts.yaml' + pull_request: + types: + - opened + - reopened + - synchronize + - ready_for_review + paths: + - '**' + - '.github/workflows/contracts.yaml' + +defaults: + run: + working-directory: '.' + +jobs: + foundry: + if: github.event.pull_request.draft == false + runs-on: ubuntu-latest + + steps: + - name: Checkout sources + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly + + - name: Setup LCOV + uses: hrishikesh-kadam/setup-lcov@v1 + + - name: Install Node.js 18 + uses: actions/setup-node@v2 + with: + node-version: '18' + + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + + - name: Cache yarn dependencies + uses: actions/cache@v2 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Cache node_modules + id: npm_cache + uses: actions/cache@v2 + with: + path: node_modules + key: node_modules-${{ hashFiles('yarn.lock') }} + + - name: yarn install + # if: steps.npm_cache.outputs.cache-hit != 'true' + run: yarn install + + - name: Compile with foundry + run: forge build --evm-version cancun + + - name: Run foundry tests + run: forge test --evm-version cancun -vvv + + - name: Run foundry coverage + run : forge coverage --evm-version cancun --report lcov + + - name : Prune coverage + run : lcov --rc branch_coverage=1 --remove ./lcov.info -o ./lcov.info.pruned 'src/mocks/*' 'src/test/*' 'scripts/*' 'node_modules/*' 'lib/*' + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + with: + files: lcov.info.pruned + flags: contracts + + hardhat: + if: github.event.pull_request.draft == false + runs-on: ubuntu-latest + + steps: + - name: Checkout sources + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Install Node.js 18 + uses: actions/setup-node@v2 + with: + node-version: '18' + + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + + - name: Cache yarn dependencies + uses: actions/cache@v2 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Cache node_modules + id: npm_cache + uses: actions/cache@v2 + with: + path: node_modules + key: node_modules-${{ hashFiles('yarn.lock') }} + + - name: yarn install + # if: steps.npm_cache.outputs.cache-hit != 'true' + run: yarn install + + - name: Compile with hardhat + run: npx hardhat compile + + - name: Run hardhat tests + run: npx hardhat test \ No newline at end of file diff --git a/.gitignore b/.gitignore index bf43859..88e59a6 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,6 @@ broadcast # eslint .eslintcache + +# Visual Studio Code +.vscode diff --git a/.prettierignore b/.prettierignore index 290dcbe..2d0a492 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,8 +1,7 @@ node_modules artifacts +artifacts-hardhat cache +cache-hardhat coverage* gasReporterOutput.json -src/libraries/verifier/ZkTrieVerifier.sol -src/libraries/verifier/PatriciaMerkleTrieVerifier.sol -src/L2/predeploys/L1BlockContainer.sol From 2aef1fa952503c4fe85fedc0c2b85d50b1ca778c Mon Sep 17 00:00:00 2001 From: zimpha Date: Thu, 6 Jun 2024 15:18:21 +0800 Subject: [PATCH 2/2] fix naming --- hardhat-test/PoseidonHash.spec.ts | 2 +- hardhat-test/ZkEvmVerifierV1.spec.ts | 4 ++-- package.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hardhat-test/PoseidonHash.spec.ts b/hardhat-test/PoseidonHash.spec.ts index 2138258..e4d70f4 100644 --- a/hardhat-test/PoseidonHash.spec.ts +++ b/hardhat-test/PoseidonHash.spec.ts @@ -74,7 +74,7 @@ describe("PoseidonHash.spec", async () => { }); it("should succeed on random inputs", async () => { - const lines = String(fs.readFileSync("./integration-test/testdata/poseidon_hash_with_domain.data")).split("\n"); + const lines = String(fs.readFileSync("./hardhat-test/testdata/poseidon_hash_with_domain.data")).split("\n"); for (const line of lines) { const [domain, a, b, hash] = line.split(" "); expect(await poseidon["poseidon(uint256[2],uint256)"]([a, b], domain)).to.eq(toBigInt(hash)); diff --git a/hardhat-test/ZkEvmVerifierV1.spec.ts b/hardhat-test/ZkEvmVerifierV1.spec.ts index f20ffa8..ec523e2 100644 --- a/hardhat-test/ZkEvmVerifierV1.spec.ts +++ b/hardhat-test/ZkEvmVerifierV1.spec.ts @@ -25,8 +25,8 @@ describe("ZkEvmVerifierV1", async () => { }); it("should succeed", async () => { - const proof = hexlify(fs.readFileSync("./integration-test/testdata/plonk_verifier_0.9.8_proof.data")); - const instances = fs.readFileSync("./integration-test/testdata/plonk_verifier_0.9.8_pi.data"); + const proof = hexlify(fs.readFileSync("./hardhat-test/testdata/plonk_verifier_0.9.8_proof.data")); + const instances = fs.readFileSync("./hardhat-test/testdata/plonk_verifier_0.9.8_pi.data"); const publicInputHash = new Uint8Array(32); for (let i = 0; i < 32; i++) { diff --git a/package.json b/package.json index 256e7ba..a555a81 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "test": "yarn test:hardhat && yarn test:forge", "solhint": "./node_modules/.bin/solhint -f table 'src/**/*.sol'", "lint:sol": "./node_modules/.bin/prettier --write 'src/**/*.sol'", - "lint:ts": "./node_modules/.bin/prettier --write 'integration-test/**/*.ts' 'scripts/**/*.ts' *.ts", + "lint:ts": "./node_modules/.bin/prettier --write 'hardhat-test/**/*.ts' 'scripts/**/*.ts' *.ts", "lint": "yarn lint:ts && yarn lint:sol", "coverage": "hardhat coverage", "coverage:forge": "forge coverage",