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

feat: add github workflow #2

Merged
merged 2 commits into from
Jun 6, 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
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
node_modules
artifacts
artifacts-hardhat
cache
cache-hardhat
coverage
typechain
135 changes: 135 additions & 0 deletions .github/workflows/contracts.yml
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ broadcast

# eslint
.eslintcache

# Visual Studio Code
.vscode
5 changes: 2 additions & 3 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion hardhat-test/PoseidonHash.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions hardhat-test/ZkEvmVerifierV1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading