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

ci: automated testing of API/RPC endpoints #28

Merged
merged 16 commits into from
Nov 20, 2023
Merged
66 changes: 66 additions & 0 deletions .github/workflows/api.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: API

on:
push:
schedule:
- cron: "0 0 * * *" # Runs every day at midnight
workflow_dispatch:

jobs:
generate-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v2
- name: Install jq
run: sudo apt-get install jq
- name: Generate matrix
id: set-matrix
run: |
MATRIX=$(jq -c '[.[] | .api[] | {url: .url, type: .type}]' data/networks.json)
echo "{ \"include\": $MATRIX }" > matrix.json
echo "::set-output name=matrix::$(cat matrix.json)"

test:
needs: generate-matrix
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix: ${{fromJson(needs.generate-matrix.outputs.matrix)}}
steps:
- uses: actions/checkout@v2
- name: Test Endpoint
run: |
url="${{ matrix.url }}"
type="${{ matrix.type }}"
response=""
status_check="false"

if [ "$type" = "evm" ]; then
response=$(curl -s -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' "$url")
status_check=$(echo "$response" | jq -e '.id' &> /dev/null && echo "true" || echo "false")
elif [ "$type" = "tendermint-http" ]; then
response=$(curl -s "${url}/status")
status_check=$(echo "$response" | jq -e '.jsonrpc' &> /dev/null && echo "true" || echo "false")
elif [ "$type" = "tendermint-rpc" ]; then
response=$(curl -s --header "Content-Type: application/json" --request POST --data '{"method": "status", "params": [], "id": 1}' "$url")
status_check=$(echo "$response" | jq -e '.id' &> /dev/null && echo "true" || echo "false")
elif [ "$type" = "cosmos-http" ]; then
response=$(curl -s "${url}/cosmos/base/tendermint/v1beta1/blocks/latest")
status_check=$(echo "$response" | jq -e '.block_id.hash' &> /dev/null && echo "true" || echo "false")
else
echo "⏭️ Skipping unsupported endpoint type: $type"
status_check="skip"
fi

if [ "$status_check" = "true" ]; then
echo "✅ $url - Successful"
elif [ "$status_check" = "false" ]; then
echo "❌ $url - Failed"
echo "test_failed=true" >> $GITHUB_ENV
fi

- name: Check Test Results
if: ${{ env.test_failed == 'true' }}
run: exit 1
24 changes: 2 additions & 22 deletions data/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,17 +249,13 @@
"type": "tendermint-ws"
},
{
"url": "https://zetachain-testnet.nodejumper.io:443",
"url": "https://rpc.nodejumper.io:443/zetachaintestnet",
"type": "tendermint-rpc"
},
{
"url": "https://zetachain-testnet.nodejumper.io:1317",
"url": "https://rest.nodejumper.io/zetachaintestnet",
"type": "cosmos-http"
},
{
"url": "https://zetachain-testnet.nodejumper.io:9090",
"type": "cosmos-grpc"
},
{
"url": "https://rpc.ankr.com/zetachain_evm_athens_testnet",
"type": "evm"
Expand All @@ -276,22 +272,6 @@
"url": "https://rpc.ankr.com/http/zetachain_athens_testnet",
"type": "cosmos-http"
},
{
"url": "https://zetachain-evm-athens-testnet-public.unifra.io",
"type": "evm"
},
{
"url": "https://zetachain-tendermint-rpc-athens-testnet-public.unifra.io",
"type": "tendermint-rpc"
},
{
"url": "https://zetachain-tendermint-http-athens-testnet-public.unifra.io",
"type": "tendermint-http"
},
{
"url": "https://zetachain-cosmos-sdk-http-athens-testnet-public.unifra.io",
"type": "cosmos-http"
},
{
"url": "https://zetachain-testnet-rpc.itrocket.net",
"type": "tendermint-rpc"
Expand Down
Loading