Skip to content

Commit

Permalink
chain sync test
Browse files Browse the repository at this point in the history
  • Loading branch information
ermalkaleci committed Jun 7, 2024
1 parent a64276f commit d15dd21
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/chain-sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Chain Sync

on:
push:
branches: ["master"]
tags:
- v[0-9]+.[0-9]+.[0-9]+*
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
chain-sync:
continue-on-error: true
timeout-minutes: 60
runs-on: ubuntu-latest

steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Install deps
run: sudo apt -y install protobuf-compiler

- name: Install & display rust toolchain
run: rustup show

- name: Check targets are installed correctly
run: rustup target list --installed

- name: Build
run: cargo build --release --locked

- name: Test astar sync
run: ./scripts/sync.sh astar

- name: Test shiden sync
run: ./scripts/sync.sh shiden

- name: Test shibuya sync
run: ./scripts/sync.sh shibuya
39 changes: 39 additions & 0 deletions scripts/sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

set -e

# first argument is chain
chain="$@"

# run node
./target/release/astar-collator --chain $chain --no-telemetry --no-prometheus --tmp & CHAIN_PID=$!

printf "Waiting for RPC to be ready"
attempts=12 # 1 minutes
until nc -z localhost 9944; do
attempts=$((attempts - 1))
if [ $attempts -eq 0 ]; then
echo "Chain RPC failed to start"
exit 1
fi
sleep 5
done

printf "Waiting for 30 seconds to sync at least 1000 blocks"
sleep 30

number=$(curl --location http://localhost:9944 \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "chain_getHeader",
"params": [],
"id": 1
}' | jq '.result.number' | xargs | { read hex_number; printf "%d\n" $hex_number; })

if [ "$number" -lt 1000 ]; then
echo "Chain failed to sync 1000 blocks in 30 seconds"
exit 1
fi

kill $CHAIN_PID

0 comments on commit d15dd21

Please sign in to comment.