From 02f551917eb93232df918826bd35c273583deec9 Mon Sep 17 00:00:00 2001 From: Samuel Burnham <45365069+samuelburnham@users.noreply.github.com> Date: Tue, 31 Oct 2023 13:28:14 -0400 Subject: [PATCH 1/3] Enable end2end tests on forked PRs (#37) --- .github/workflows/{test.yml => ci.yml} | 29 ++++++------ .github/workflows/end2end.yml | 65 ++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 13 deletions(-) rename .github/workflows/{test.yml => ci.yml} (84%) create mode 100644 .github/workflows/end2end.yml diff --git a/.github/workflows/test.yml b/.github/workflows/ci.yml similarity index 84% rename from .github/workflows/test.yml rename to .github/workflows/ci.yml index 20e18e0..8596695 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/ci.yml @@ -1,22 +1,25 @@ -name: test - -on: [workflow_dispatch, push, pull_request] - -env: - ANVIL_PRIVATE_KEY: ${{secrets.ANVIL_PRIVATE_KEY}} - ANVIL_URL: ${{secrets.ANVIL_RPC_URL}} +name: Run unit tests +on: + push: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + merge_group: + workflow_dispatch: jobs: integration-tests-e2e: - needs: [unit-tests] - strategy: - fail-fast: true - name: E2E verification + # Run on merge_group and workflow_dispatch only + if: (github.event_name != 'push' && github.event_name != 'pull_request') || github.event.action == 'enqueued' runs-on: [self-hosted] + env: + ANVIL_PRIVATE_KEY: ${{secrets.ANVIL_PRIVATE_KEY}} + ANVIL_URL: ${{secrets.ANVIL_RPC_URL}} + strategy: + fail-fast: true steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive @@ -50,7 +53,7 @@ jobs: name: Unit Tests runs-on: [self-hosted] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: recursive diff --git a/.github/workflows/end2end.yml b/.github/workflows/end2end.yml new file mode 100644 index 0000000..ddabb58 --- /dev/null +++ b/.github/workflows/end2end.yml @@ -0,0 +1,65 @@ +# Run integration tests when a maintainer comments `!test` on a PR +name: End to end integration tests + +on: + issue_comment: + types: [created] + +env: + ANVIL_PRIVATE_KEY: ${{secrets.ANVIL_PRIVATE_KEY}} + ANVIL_URL: ${{secrets.ANVIL_RPC_URL}} + +jobs: + integration-tests-e2e: + strategy: + fail-fast: true + + name: E2E verification + runs-on: [self-hosted] + if: + github.event.issue.pull_request + && github.event.issue.state == 'open' + && contains(github.event.comment.body, '!test') + && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Checkout PR branch + run: gh pr checkout $PR_NUMBER + env: + GH_TOKEN: ${{ github.token }} + PR_NUMBER: ${{ github.event.issue.number }} + + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + with: + version: nightly + + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: 3.8 + + - name: Deploy main contract + run: | + echo "CONTRACT_ADDRESS=$(forge script script/Deployment.s.sol:NovaVerifierDeployer --fork-url $ANVIL_URL --private-key $ANVIL_PRIVATE_KEY --broadcast --non-interactive | sed -n 's/.*Contract Address: //p' | tail -1)" >> $GITHUB_OUTPUT + id: deployment + + - name: Load proof and public parameters + run: | + python loader.py pp-verifier-key.json pp-compressed-snark.json ${{steps.deployment.outputs.CONTRACT_ADDRESS}} $ANVIL_URL $ANVIL_PRIVATE_KEY + + - name: Check proof verification status + run: | + [[ $(cast call ${{steps.deployment.outputs.CONTRACT_ADDRESS}} "verify(uint32,uint256[],uint256[],bool)(bool)" "3" "[1]" "[0]" "true" --private-key $ANVIL_PRIVATE_KEY --rpc-url $ANVIL_URL) == true ]] && exit 0 || exit 1 + + - name: Comment on successful run + uses: peter-evans/create-or-update-comment@v3 + with: + issue-number: ${{ github.event.issue.number }} + body: | + End-to-end `!test` action succeeded! :rocket: + + https://github.com/lurk-lab/ci-lab/actions/runs/${{ github.run_id }} From 9a67892d69537dce99db17ac20226b480a011661 Mon Sep 17 00:00:00 2001 From: Samuel Burnham <45365069+samuelburnham@users.noreply.github.com> Date: Tue, 31 Oct 2023 14:53:13 -0400 Subject: [PATCH 2/3] Test forked PR (#38) --- .github/workflows/ci.yml | 2 +- .github/workflows/end2end.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8596695..132126b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Run unit tests +name: Run tests on: push: diff --git a/.github/workflows/end2end.yml b/.github/workflows/end2end.yml index ddabb58..790c74d 100644 --- a/.github/workflows/end2end.yml +++ b/.github/workflows/end2end.yml @@ -62,4 +62,4 @@ jobs: body: | End-to-end `!test` action succeeded! :rocket: - https://github.com/lurk-lab/ci-lab/actions/runs/${{ github.run_id }} + https://github.com/lurk-lab/solidity-verifier/actions/runs/${{ github.run_id }} From 2b818a221502ddd77be848b410d6ff0ea7c1f9fc Mon Sep 17 00:00:00 2001 From: Samuel Burnham <45365069+samuelburnham@users.noreply.github.com> Date: Mon, 5 Feb 2024 12:21:50 -0500 Subject: [PATCH 3/3] ci: Switch to Buildjet --- .github/workflows/ci.yml | 49 +++++------------------------------ .github/workflows/end2end.yml | 20 +++++++++----- 2 files changed, 20 insertions(+), 49 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 132126b..8b0a6dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,23 +1,15 @@ -name: Run tests +name: Run unit tests on: - push: pull_request: types: [opened, synchronize, reopened, ready_for_review] merge_group: workflow_dispatch: jobs: - integration-tests-e2e: - name: E2E verification - # Run on merge_group and workflow_dispatch only - if: (github.event_name != 'push' && github.event_name != 'pull_request') || github.event.action == 'enqueued' - runs-on: [self-hosted] - env: - ANVIL_PRIVATE_KEY: ${{secrets.ANVIL_PRIVATE_KEY}} - ANVIL_URL: ${{secrets.ANVIL_RPC_URL}} - strategy: - fail-fast: true + unit-tests: + name: Unit Tests + runs-on: buildjet-16vcpu-ubuntu-2204 steps: - uses: actions/checkout@v4 with: @@ -33,43 +25,14 @@ jobs: with: python-version: 3.8 - - name: Deploy main contract - run: | - echo "CONTRACT_ADDRESS=$(forge script script/Deployment.s.sol:NovaVerifierDeployer --fork-url $ANVIL_URL --private-key $ANVIL_PRIVATE_KEY --broadcast --non-interactive | sed -n 's/.*Contract Address: //p' | tail -1)" >> $GITHUB_OUTPUT - id: deployment - - - name: Load proof and public parameters - run: | - python loader.py pp-verifier-key.json pp-compressed-snark.json ${{steps.deployment.outputs.CONTRACT_ADDRESS}} $ANVIL_URL $ANVIL_PRIVATE_KEY - - - name: Check proof verification status - run: | - [[ $(cast call ${{steps.deployment.outputs.CONTRACT_ADDRESS}} "verify(uint32,uint256[],uint256[],bool)(bool)" "3" "[1]" "[0]" "true" --private-key $ANVIL_PRIVATE_KEY --rpc-url $ANVIL_URL) == true ]] && exit 0 || exit 1 - - unit-tests: - strategy: - fail-fast: true - - name: Unit Tests - runs-on: [self-hosted] - steps: - - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: 3.8 - - name: Check formatting run: | forge fmt --check - name: Regenerate Contracts run: | - python src/blocks/poseidon/poseidon-contract-gen.py neptune-constants-U24-pallas.json PoseidonU24Pallas > src/blocks/poseidon/PoseidonNeptuneU24pallas.sol - python src/blocks/poseidon/poseidon-contract-gen.py neptune-constants-U24-vesta.json PoseidonU24Vesta > src/blocks/poseidon/PoseidonNeptuneU24vesta.sol + python src/blocks/poseidon/poseidon-contract-gen.py src/blocks/poseidon/neptune-constants-U24-pallas.json PoseidonU24Pallas > src/blocks/poseidon/PoseidonNeptuneU24pallas.sol + python src/blocks/poseidon/poseidon-contract-gen.py src/blocks/poseidon/neptune-constants-U24-vesta.json PoseidonU24Vesta > src/blocks/poseidon/PoseidonNeptuneU24vesta.sol - name: Run forge fmt on re-generated contracts run: | diff --git a/.github/workflows/end2end.yml b/.github/workflows/end2end.yml index 790c74d..99dc709 100644 --- a/.github/workflows/end2end.yml +++ b/.github/workflows/end2end.yml @@ -1,4 +1,5 @@ -# Run integration tests when a maintainer comments `!test` on a PR +# Run integration tests when a maintainer comments `!test` on a PR to feature branch +# Fails when base branch is `main`, as it doesn't support e2e tests name: End to end integration tests on: @@ -11,17 +12,24 @@ env: jobs: integration-tests-e2e: - strategy: - fail-fast: true - name: E2E verification - runs-on: [self-hosted] + runs-on: buildjet-16vcpu-ubuntu-2204 if: github.event.issue.pull_request && github.event.issue.state == 'open' && contains(github.event.comment.body, '!test') && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') steps: + - uses: xt0rted/pull-request-comment-branch@v2 + id: comment-branch + + - name: Exit if base branch is `main` + if: ${{ steps.comment-branch.outputs.base_ref == 'main' }} + run: | + echo "Cannot run end2end integration tests on PR targeting `main`" + exit 1 + continue-on-error: false + - uses: actions/checkout@v4 with: submodules: recursive @@ -62,4 +70,4 @@ jobs: body: | End-to-end `!test` action succeeded! :rocket: - https://github.com/lurk-lab/solidity-verifier/actions/runs/${{ github.run_id }} + https://github.com/lurk-lab/solidity-verifier/actions/runs/${{ github.run_id }} \ No newline at end of file