From 64abaaf8c4e2b1909da2110cd24d5f4dfd0e5b84 Mon Sep 17 00:00:00 2001 From: sunchengzhu <36075573+sunchengzhu@users.noreply.github.com> Date: Fri, 20 Oct 2023 12:08:46 +0800 Subject: [PATCH] ci: add `hardfork_test` workflow (#1487) add hardfork test --- .github/workflows/hardfork_test.yml | 108 ++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 .github/workflows/hardfork_test.yml diff --git a/.github/workflows/hardfork_test.yml b/.github/workflows/hardfork_test.yml new file mode 100644 index 000000000..04f690363 --- /dev/null +++ b/.github/workflows/hardfork_test.yml @@ -0,0 +1,108 @@ +name: Hardfork test + +on: + push: + pull_request: + merge_group: + workflow_dispatch: + +jobs: + hardfork-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 }} + steps: + - uses: actions/checkout@v4 + + - 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: cargo build + + - name: Start multiple Axon nodes + env: + LOG_PATH: ${{ runner.temp }}/${{ matrix.os }}/multi-axon-nodes + run: | + echo "LOG_PATH: ${{ env.LOG_PATH }}" + mkdir -p ${{ env.LOG_PATH }} + + target/debug/axon --version + + sed -i 's/hardforks = \[\]/hardforks = ["None"]/g' devtools/chain/specs/multi_nodes/chain-spec.toml + grep "hardforks" devtools/chain/specs/multi_nodes/chain-spec.toml + + for id in 1 2 3 4; do + target/debug/axon init \ + --config devtools/chain/nodes/node_${id}.toml \ + --chain-spec devtools/chain/specs/multi_nodes/chain-spec.toml \ + > ${{ env.LOG_PATH }}/node_${id}.log + done + + for id in 1 2 3 4; do + target/debug/axon run \ + --config devtools/chain/nodes/node_${id}.toml \ + >> ${{ env.LOG_PATH }}/node_${id}.log & + done + + npx zx <<'EOF' + import { waitXBlocksPassed } from './devtools/ci/scripts/helper.js' + await Promise.all([ + waitXBlocksPassed('http://127.0.0.1:8001', 4), + waitXBlocksPassed('http://127.0.0.1:8002', 4), + waitXBlocksPassed('http://127.0.0.1:8003', 4), + waitXBlocksPassed('http://127.0.0.1:8004', 4), + ]) + EOF + timeout-minutes: 1 + + - name: Checkout sunchengzhu/axon-hardfork-test + uses: actions/checkout@v4 + with: + repository: sunchengzhu/axon-hardfork-test + path: axon-hardfork-test + + - name: Run test cases before hardfork + working-directory: axon-hardfork-test + run: | + npm install + npx hardhat test --grep "deploy a normal contract" + npx hardhat test --grep "deploy a big contract larger than max_contract_limit" + npx hardhat test --grep "check hardfork info before hardfork" + + - name: Hardfork + working-directory: axon-hardfork-test + run: | + bash hardfork.sh ../ + + - name: Run test cases after hardfork + working-directory: axon-hardfork-test + run: | + npx hardhat test --grep "check hardfork info after hardfork" + + node_ids=(1 2 3 4) + random_value=$(( (RANDOM % ${#node_ids[@]}) + 1 )) + echo "Invoke system contract via node_"$random_value + npx hardhat test --grep "update max_contract_limit" --network "node_"$random_value + npx hardhat test --grep "deploy a big contract smaller than max_contract_limit" + + - name: Archive logs + if: failure() + uses: actions/upload-artifact@v3 + with: + name: multi-axon-nodes-logs + path: | + ${{ runner.temp }}/${{ matrix.os }}/multi-axon-nodes/