Skip to content

Commit

Permalink
chore: add script to check for blocks in chain logs
Browse files Browse the repository at this point in the history
Co-authored-by: Dan Connolly <[email protected]>
  • Loading branch information
amessbee and dckc committed Jan 9, 2025
1 parent d6bae0c commit 60b9b18
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand Down
33 changes: 33 additions & 0 deletions contract/scripts/wait-for-chain.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 60b9b18

Please sign in to comment.