tendermint-ws #10
Workflow file for this run
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: Test API Endpoints | |
on: [push] | |
jobs: | |
setup-websocat: | |
runs-on: ubuntu-latest | |
outputs: | |
artifact-path: ${{ steps.setup.outputs.artifact-path }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Install websocat | |
id: setup | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y websocat | |
echo "::set-output name=artifact-path::$(which websocat)" | |
generate-matrix: | |
needs: setup-websocat | |
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-endpoints: | |
needs: [setup-websocat, 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: | | |
websocat_path=${{ needs.setup-websocat.outputs.artifact-path }} | |
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") | |
elif [ "$type" = "tendermint-ws" ]; then | |
response=$(echo '{ "jsonrpc": "2.0", "method": "subscribe", "params": ["tm.event='\'NewBlock'\'"], "id": 1 }' | $websocat_path -t "$url") | |
status_check=$(echo "$response" | jq -e '.result' &> /dev/null && echo "true" || echo "false") | |
fi | |
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 |