Skip to content

Commit

Permalink
Add a sanity test for running container
Browse files Browse the repository at this point in the history
- connnect to a running network and
- make sure it starts synchronzing
  • Loading branch information
atodorov committed Jan 18, 2024
1 parent 4a4f27e commit 333c6ac
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
39 changes: 39 additions & 0 deletions .github/check-health.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

set -xeuo pipefail

# Assert on the health of a freshly started container pointing to mainnet!
#
# IMPORTANT:
# In the initial 30 mins or so the node will be syncing blocks and the assertions
# below will PASS. Afterwards they will fail!

HEALTH=$(curl --silent http://127.0.0.1:9944/health)
IS_SYNCING=$(jq -r '.isSyncing' <<< "$HEALTH")
SHOULD_HAVE_PEERS=$(jq -r '.shouldHavePeers' <<< "$HEALTH")
PEERS=$(jq -r '.peers' <<< "$HEALTH")

# WARNING: will fail once the node is within 5 blocks of tip
if [ "$IS_SYNCING" != "true" ]; then
echo "FAIL"
exit 1
fi

# WARNING: will fail if we're a boot node or haven't specified any --bootnodes
if [ "$SHOULD_HAVE_PEERS" != "true" ]; then
echo "FAIL"
exit 2
fi

# WARNING: will fail if running a local --dev node
if [[ ! "$PEERS" -gt 0 ]]; then
echo "FAIL"
exit 2
fi

# no assertion here, in case of error jq should fail
ROTATE_KEYS=$(curl --silent -X POST http://127.0.0.1:9944 -H 'Content-Type: application/json' -d '{ "jsonrpc": "2.0", "method": "author_rotateKeys", "params": [], "id": 1 }')
jq -r '.result' <<< "$ROTATE_KEYS"

echo "PASS"
exit 0
16 changes: 14 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,26 @@ jobs:
run: |
docker build -t gluwa/creditcoin3 .
# TODO: properly start a node once work on CSUB-857 starts
- name: Start a container from image
run: |
# see https://opensource.com/article/18/5/how-find-ip-address-linux
IP_ADDRESS=$(curl https://ifconfig.me)
echo "INFO: IP_ADDRESS=$IP_ADDRESS"
docker run --rm --name creditcoin-validator -d gluwa/creditcoin3
docker run --rm --name creditcoin-validator -d -p 9944:9944 -p 30333:30333 gluwa/creditcoin3 \
--validator --chain testnet \
--name "test-node-$GITHUB_RUN_ID-attempt-$GITHUB_RUN_ATTEMPT" \
--public-addr "/dns4/$IP_ADDRESS/tcp/30333" \
--prometheus-external \
--telemetry-url "wss://telemetry.polkadot.io/submit/ 0" \
--telemetry-url "wss://telemetry.creditcoin.network/submit/ 0" \
--bootnodes "/dns4/cc3-test-bootnode.creditcoin.network/tcp/30333/p2p/12D3KooWAxmsWr6iEjFyLqQBzfLvbCRTAhYBeszyr8UWgQx6Zu7K" \
--port 30333 --unsafe-rpc-external
- name: Healtcheck
run: |
sleep 60
.github/check-health.sh
- name: Sanity test creditcoin3 inside the container
run: |
Expand Down

0 comments on commit 333c6ac

Please sign in to comment.