#!/usr/bin/env bash
# WEIGHT=10
# CHECK: BroadcastVote / BroadcastTimeout / BroadcastSyncInfo actually call p2p.Send (W-4/5/6)
set -e
handler="$PATIENT/eth/handler_xdc.go"
[[ -f "$handler" ]] || exit 1
# At minimum, p2p.Send (or peer.Send-style call) must appear in each broadcast function body.
# Test all three broadcasts together: each must NOT be just `_ = p` stub.
for fn in BroadcastVote BroadcastTimeout BroadcastSyncInfo; do
  body=$(awk -v f="$fn" '$0 ~ "func.*"f"\\(" {flag=1; next} flag && /^}/{flag=0; next} flag' "$handler")
  echo "$body" | grep -qE '(p2p\.Send|\.Send\()' || exit 1
  # Must NOT contain only `_ = p` placeholder
  echo "$body" | grep -qE '_\s*=\s*p[[:space:]]*//' && exit 1 || true
done
