diff --git a/examples/justfile b/examples/justfile new file mode 100644 index 00000000..8b16466d --- /dev/null +++ b/examples/justfile @@ -0,0 +1,112 @@ +# Polkadot Bulletin Chain - Just Commands +# Install just: brew install just +# Run `just --list` to see all available commands + +# Default recipe - run the complete PAPI workflow test +default: authorize-and-store + +# Build the bulletin chain node in release mode +build: + cargo build --release -p polkadot-bulletin-chain + +# Install JavaScript dependencies +npm-install: + npm install + +# Test the complete workflow (builds, starts services, runs example, shuts down services) +# Parameters: api=[papi|pjs] - choose between Polkadot API (papi) or Polkadot JS (pjs) +authorize-and-store api="papi": build npm-install + #!/usr/bin/env bash + set -e + + API_TYPE="{{ api }}" + + if [[ "$API_TYPE" != "papi" && "$API_TYPE" != "pjs" ]]; then + echo "โŒ Error: api parameter must be 'papi' or 'pjs'" + exit 1 + fi + + echo "๐Ÿš€ Starting $API_TYPE workflow test..." + echo "" + + # Check if IPFS is available + if ! command -v ipfs &> /dev/null; then + echo "โŒ IPFS not found. Using local kubo binary..." + IPFS_CMD="./kubo/ipfs" + if [ ! -f "$IPFS_CMD" ]; then + echo "โŒ Error: Neither system IPFS nor ./kubo/ipfs found." + echo "Please install IPFS or download kubo to ./kubo/" + exit 1 + fi + else + IPFS_CMD="ipfs" + fi + + # Initialize IPFS if needed + if [ ! -d ~/.ipfs ]; then + echo "๐Ÿ“ฆ Initializing IPFS..." + $IPFS_CMD init + fi + + # Start IPFS daemon in background + echo "๐Ÿ“ก Starting IPFS daemon..." + $IPFS_CMD daemon > /tmp/ipfs-daemon.log 2>&1 & + IPFS_PID=$! + echo " IPFS PID: $IPFS_PID" + sleep 2 + + # Start zombienet in background + echo "โšก Starting Bulletin chain with zombienet..." + POLKADOT_BULLETIN_BINARY_PATH=../target/release/polkadot-bulletin-chain ./$(ls zombienet-*-*) -p native spawn ./zombienet/bulletin-polkadot-local.toml > /tmp/zombienet.log 2>&1 & + ZOMBIENET_PID=$! + echo " Zombienet PID: $ZOMBIENET_PID" + echo " Waiting for chain to start (15 seconds)..." + sleep 15 + + # Start IPFS reconnect script in background + echo "๐Ÿ”„ Starting IPFS reconnect script..." + ./scripts/ipfs-reconnect-solo.sh > /tmp/ipfs-reconnect.log 2>&1 & + RECONNECT_PID=$! + echo " Reconnect PID: $RECONNECT_PID" + sleep 2 + + # Generate PAPI descriptors (only for papi) + if [ "$API_TYPE" == "papi" ]; then + echo "๐Ÿ”ง Generating PAPI descriptors..." + npm run papi:generate + fi + + # Determine which example to run + if [ "$API_TYPE" == "papi" ]; then + EXAMPLE_FILE="authorize_and_store_papi.js" + else + EXAMPLE_FILE="authorize_and_store.js" + fi + + # Run the example + echo "" + echo "๐ŸŽฏ Running $EXAMPLE_FILE example..." + echo "โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”" + node $EXAMPLE_FILE + EXAMPLE_EXIT=$? + + echo "" + echo "โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”" + if [ $EXAMPLE_EXIT -eq 0 ]; then + echo "โœ… Example completed successfully!" + else + echo "โŒ Example failed with exit code $EXAMPLE_EXIT" + fi + + echo "" + echo "๐Ÿ“ Logs available at:" + echo " /tmp/ipfs-daemon.log" + echo " /tmp/zombienet.log" + echo " /tmp/ipfs-reconnect.log" + + # Clean up background processes + echo "๐Ÿงน Cleaning up background processes..." + kill $IPFS_PID $ZOMBIENET_PID $RECONNECT_PID 2>/dev/null || true + + + exit $EXAMPLE_EXIT