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
  • Loading branch information
amessbee committed Jan 3, 2025
1 parent d6bae0c commit e5904f6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ videos

# contract tx
contract/,tx.json
contract/start-offer-up-plan.json
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
31 changes: 31 additions & 0 deletions contract/scripts/wait-for-chain.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/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 "$line" # Show the log output

if [[ $line =~ "block-manager: block "[0-9]+" commit" ]]; then
((count++))
if [ $count -ge $required_patterns ]; then
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 e5904f6

Please sign in to comment.