#!/usr/bin/env bash
# WEIGHT=10
# CHECK: C1.1 walk-back guard uses >= not > at engine.go:~366
# REF: PR #411 (commit 72a264630) set this to >=. HOTFIX ace90b251 regressed to >.
# Pass condition: the walk-back loop's outer guard accepts header.Number == V2.SwitchBlock
set -e
engine="$PATIENT/consensus/XDPoS/engines/engine_v2/engine.go"
[[ -f "$engine" ]] || exit 1
# The walk-back is inside initial(); guard is something like:
#   if header != nil && header.Number.Uint64() >= x.config.V2.SwitchBlock.Uint64() {
# We accept either >= or any pattern that allows the walk-back to start at the switch block.
# Failing pattern (what the regression looks like): "header.Number.Uint64() > x.config.V2.SwitchBlock"
# Passing pattern: ">=" with same operands.
guard_line=$(grep -nE 'header\.Number\.Uint64\(\)\s*[><=]+\s*x\.config\.V2\.SwitchBlock\.Uint64\(\)' "$engine" | head -1)
[[ -z "$guard_line" ]] && exit 1
# Pass if line uses >=
echo "$guard_line" | grep -qE '>='
