|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# ENV VARIABLES: |
| 4 | +# - RPC_URL |
| 5 | +# - NETWORK |
| 6 | +# - BATCHER_PAYMENT_SERVICE_ADDRESS |
| 7 | +# - PRIVATE_KEY |
| 8 | +# - SLEEP_SECONDS |
| 9 | + |
| 10 | +# Load env file from $1 path |
| 11 | +source "$1" |
| 12 | + |
| 13 | +### FUNCTIONS ### |
| 14 | + |
| 15 | +# Function to log with timestamp and severity |
| 16 | +function log() { |
| 17 | + local severity=$1 |
| 18 | + local message=$2 |
| 19 | + local timestamp=$(date '+%Y-%m-%d %H:%M:%S') |
| 20 | + |
| 21 | + echo "[$timestamp] [$severity] $message" |
| 22 | +} |
| 23 | + |
| 24 | +# Function to send a proof to Aligned |
| 25 | +function send_proof() { |
| 26 | + log "INFO" "⏳ Sending proof to Aligned..." |
| 27 | + |
| 28 | + submit=$(aligned submit \ |
| 29 | + --rpc_url $RPC_URL \ |
| 30 | + --network $NETWORK \ |
| 31 | + --private_key $PRIVATE_KEY \ |
| 32 | + --proving_system CircomGroth16Bn256 \ |
| 33 | + --proof ./scripts/test_files/circom_groth16_bn256_script/proof.json \ |
| 34 | + --public_input ./scripts/test_files/circom_groth16_bn256_script/public.json \ |
| 35 | + --vk ./scripts/test_files/circom_groth16_bn256_script/verification_key.json \ |
| 36 | + --custom_fee_estimate 64 \ |
| 37 | + 2>&1) |
| 38 | + |
| 39 | + # Check if UserFundsUnlocked appears in the output |
| 40 | + if echo "$submit" | grep -q "UserFundsUnlocked"; then |
| 41 | + log "INFO" "✅ Test successful - UserFundsUnlocked event detected" |
| 42 | + else |
| 43 | + log "ERROR" "❌ Test failed - UserFundsUnlocked event not detected" |
| 44 | + log "ERROR" "Submit output: $submit" |
| 45 | + fi |
| 46 | +} |
| 47 | + |
| 48 | + |
| 49 | +# Function to unlock funds |
| 50 | +function unlock_funds() { |
| 51 | + log "INFO" "⏳ Unlocking funds..." |
| 52 | + output=$(cast send $BATCHER_PAYMENT_SERVICE_ADDRESS "unlock()" \ |
| 53 | + --rpc-url $RPC_URL \ |
| 54 | + --private-key $PRIVATE_KEY 2>&1) |
| 55 | + |
| 56 | + if echo "$output" | grep -q "status.*1 (success)"; then |
| 57 | + log "INFO" "✅ Unlock transaction successful" |
| 58 | + else |
| 59 | + log "ERROR" "❌ Unlock transaction failed" |
| 60 | + fi |
| 61 | +} |
| 62 | + |
| 63 | +# Function to lock funds |
| 64 | +function lock_funds() { |
| 65 | + log "INFO" "⏳ Locking funds..." |
| 66 | + output=$(cast send $BATCHER_PAYMENT_SERVICE_ADDRESS "lock()" \ |
| 67 | + --rpc-url $RPC_URL \ |
| 68 | + --private-key $PRIVATE_KEY 2>&1) |
| 69 | + |
| 70 | + if echo "$output" | grep -q "status.*1 (success)"; then |
| 71 | + log "INFO" "✅ Lock transaction successful" |
| 72 | + else |
| 73 | + log "ERROR" "❌ Lock transaction failed" |
| 74 | + fi |
| 75 | +} |
| 76 | + |
| 77 | +### MAIN LOOP ### |
| 78 | +log "INFO" "🚀 Running..." |
| 79 | +lock_funds |
| 80 | +while true |
| 81 | +do |
| 82 | + send_proof & |
| 83 | + sleep 300 |
| 84 | + unlock_funds |
| 85 | + sleep $SLEEP_SECONDS |
| 86 | + lock_funds |
| 87 | +done |
0 commit comments