From 60b9b18140924eee04e5b304237034492df09310 Mon Sep 17 00:00:00 2001 From: Mudassir Shabbir Date: Wed, 1 Jan 2025 20:25:48 +0500 Subject: [PATCH] chore: add script to check for blocks in chain logs Co-authored-by: Dan Connolly --- contract/package.json | 2 +- contract/scripts/wait-for-chain.sh | 33 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100755 contract/scripts/wait-for-chain.sh diff --git a/contract/package.json b/contract/package.json index 3321479..5d4fa00 100644 --- a/contract/package.json +++ b/contract/package.json @@ -10,7 +10,7 @@ "docker:bash": "docker compose exec agd bash", "docker:make": "docker compose exec agd make -C /workspace/contract", "make:help": "make list", - "start": "yarn docker:make clean start-contract", + "start": "./scripts/wait-for-chain.sh && yarn docker:make clean start-contract", "build": "agoric run scripts/build-contract-deployer.js", "test": "ava --verbose", "lint": "tsc && eslint '**/*.js'", diff --git a/contract/scripts/wait-for-chain.sh b/contract/scripts/wait-for-chain.sh new file mode 100755 index 0000000..314176f --- /dev/null +++ b/contract/scripts/wait-for-chain.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# Function to check if we see a pattern of block commits +check_block_pattern() { + local count=0 + local required_patterns=3 # Number of block patterns we want to see + + while IFS= read -r line; do + echo -n "." # Show progress + + if [[ $line =~ "block-manager: block "[0-9]+" commit" ]]; then + ((count++)) + if [ $count -ge $required_patterns ]; then + echo + echo "$line" + return 0 # Success + fi + fi + done + + return 1 # Pattern not found +} + +echo "Waiting for blockchain to start..." +yarn docker:logs | check_block_pattern + +if [ $? -eq 0 ]; then + echo "Blockchain is running and producing blocks..." + exit 0 +else + echo "Failed to detect blockchain activity\n Run yarn start:docker to start the blockchain first!" + exit 1 +fi