Web3 Compatible Tests #2993
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Web3 Compatible Tests | |
on: | |
merge_group: | |
workflow_dispatch: | |
inputs: | |
# used by regression_testing.yml and entry_workflow.yml | |
dispatch: | |
type: string | |
description: "'regression' or the JSON of a PR's context" | |
required: false | |
jobs: | |
web3-compatible-test: | |
strategy: | |
matrix: | |
# Supported GitHub-hosted runners and hardware resources | |
# see https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners#supported-runners-and-hardware-resources | |
os: [ubuntu-22.04] | |
fail-fast: false | |
runs-on: ${{ matrix.os }} | |
env: | |
IS_DISPATCH: ${{ github.event_name == 'workflow_dispatch' }} | |
IS_REGRESSION: ${{ github.event.inputs.dispatch == 'regression' }} | |
# When the permissions key is used, all unspecified permissions are set to no access, with the exception of the metadata scope, which always gets read access. | |
# See https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token | |
permissions: | |
statuses: write | |
steps: | |
- name: Get the git ref of Axon | |
uses: actions/github-script@v7 | |
id: axon_git_ref | |
with: | |
script: | | |
if (`${{ env.IS_DISPATCH }}` == 'true' && `${{ env.IS_REGRESSION }}` == 'false' && `${{ github.event.inputs.dispatch }}`) { | |
const dispatch = JSON.parse(`${{ github.event.inputs.dispatch }}`); | |
const prNum = dispatch.issue.number; | |
const { data: pullRequest } = await github.rest.pulls.get({ | |
owner: dispatch.repo.owner, | |
repo: dispatch.repo.repo, | |
pull_number: dispatch.issue.number, | |
}); | |
return pullRequest.head.sha; | |
} | |
return `${{ github.sha }}`; | |
result-encoding: string | |
# The `statuses: write` permission is required in this step. | |
- name: Update the commit Status | |
if: always() | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
if (`${{ env.IS_DISPATCH }}` == 'true' && `${{ env.IS_REGRESSION }}` == 'false') { | |
github.rest.repos.createCommitStatus({ | |
state: 'pending', | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
context: '${{ github.workflow }}', | |
sha: '${{ steps.axon_git_ref.outputs.result}}', | |
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' | |
}); | |
} | |
- name: Checkout Axon ${{ steps.axon_git_ref.outputs.result}} | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ steps.axon_git_ref.outputs.result}} | |
- name: Cache of Cargo | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cargo/bin/ | |
~/.cargo/registry/index/ | |
~/.cargo/registry/cache/ | |
~/.cargo/git/db/ | |
target/ | |
key: ${{ matrix.os }}-${{ runner.os }}-${{ runner.arch }}-cargo-build-${{ hashFiles('**/Cargo.lock') }} | |
restore-keys: | | |
${{ matrix.os }}-${{ runner.os }}-${{ runner.arch }}-cargo-build | |
- name: Build Axon in the development profile | |
run: | | |
# check for AVX2 support by inspecting `/proc/cpuinfo` or running `lscpu` | |
# related issue: https://github.com/axonweb3/axon/issues/1387 | |
lscpu | |
# PORTABLE=1 USE_SSE=1 tell rocksdb to target AVX2 | |
PORTABLE=1 USE_SSE=1 cargo build | |
- name: Deploy Local Network of Axon | |
run: | | |
./target/debug/axon init \ | |
--config devtools/chain/config.toml \ | |
--chain-spec devtools/chain/specs/single_node/chain-spec.toml \ | |
> /tmp/log 2>&1 | |
./target/debug/axon run \ | |
--config devtools/chain/config.toml \ | |
>> /tmp/log 2>&1 & | |
- name: Check Axon Status Before Test | |
run: | | |
MAX_RETRIES=10 | |
for i in $(seq 1 $MAX_RETRIES); do | |
sleep 10 | |
response=$(curl -s -w "\n%{http_code}" http://localhost:8000 -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"web3_clientVersion","params": [],"id":1}') | |
http_code=$(echo "$response" | tail -n1) | |
response_body=$(echo "$response" | sed '$d') | |
if [[ "$http_code" -eq 200 ]]; then | |
echo "$response_body" | |
exit 0 | |
else | |
echo "Axon status check failed with HTTP status code: $http_code, retrying ($i/$MAX_RETRIES)" | |
if [[ "$i" -eq $MAX_RETRIES ]]; then | |
echo "Axon status check failed after $MAX_RETRIES attempts." | |
exit 1 | |
fi | |
fi | |
done | |
- name: Checkout axonweb3/axon-test | |
uses: actions/checkout@v4 | |
with: | |
repository: axonweb3/axon-test | |
ref: 5b50a5382604812e5aba1d27e1eef2e941ef55ad | |
path: axon-test | |
- uses: actions/setup-node@v4 | |
with: | |
node-version: "18" | |
- name: Get yarn cache directory | |
id: yarn-cache-dir | |
run: echo "dir=$(yarn cache dir)" >> ${GITHUB_OUTPUT} | |
- name: Get npm cache directory | |
id: npm-cache-dir | |
shell: bash | |
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT} | |
- name: Node Cache | |
uses: actions/cache@v3 | |
id: npm-and-yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) | |
with: | |
path: | | |
${{ steps.yarn-cache-dir.outputs.dir }} | |
${{ steps.npm-cache-dir.outputs.dir }} | |
key: ${{ runner.os }}-node_modules-${{ hashFiles('**/package-lock.json', '**/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-node_modules- | |
- name: Run axon-test | |
working-directory: axon-test | |
run: | | |
npm install | |
npm run test:test --network=axon_test --grep="" | |
- name: Check Axon Status | |
if: success() || failure() | |
run: | | |
npx zx <<'EOF' | |
import { waitXBlocksPassed } from './devtools/ci/scripts/helper.js' | |
await retry(3, '6s', () => waitXBlocksPassed('http://127.0.0.1:8000', 2)) | |
EOF | |
- name: Publish reports | |
if: success() || failure() | |
uses: actions/upload-artifact@v4 | |
with: | |
name: jfoa-build-reports-${{ runner.os }} | |
path: axon-test/mochawesome-report/ | |
# The `statuses: write` permission is required in this step. | |
- name: Update the commit Status | |
if: always() | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
if (`${{ env.IS_DISPATCH }}` == 'true' && `${{ env.IS_REGRESSION }}` == 'false') { | |
github.rest.repos.createCommitStatus({ | |
state: '${{ job.status }}', | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
context: '${{ github.workflow }}', | |
sha: '${{ steps.axon_git_ref.outputs.result}}', | |
target_url: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}' | |
}); | |
} |