#!/usr/bin/env bash # Compare explorer-monorepo Chain 138 keys in address-inventory.json to # config/smart-contracts-master.json (G3 drift guard). # Usage: bash scripts/validation/validate-explorer-chain138-inventory.sh # Requires: jq set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" MASTER="${PROJECT_ROOT}/config/smart-contracts-master.json" INV="${PROJECT_ROOT}/explorer-monorepo/config/address-inventory.json" norm() { echo "$1" | tr '[:upper:]' '[:lower:]'; } if ! command -v jq &>/dev/null; then echo "[WARN] jq not installed; skip explorer Chain 138 inventory alignment check" exit 0 fi if [[ ! -f "$MASTER" ]]; then echo "[ERROR] Missing $MASTER" exit 1 fi if [[ ! -f "$INV" ]]; then echo "[WARN] Missing $INV; skip explorer inventory check" exit 0 fi ERR=0 expect_match() { local key="$1" local jqpath="$2" local exp exp=$(jq -r "$jqpath" "$MASTER") local got got=$(jq -r --arg k "$key" '.inventory[$k] // empty' "$INV") if [[ -z "$got" ]]; then echo "[ERROR] inventory missing key: $key" ERR=$((ERR + 1)) return fi if [[ "$(norm "$exp")" != "$(norm "$got")" ]]; then echo "[ERROR] $key mismatch: inventory=$got master=$exp" ERR=$((ERR + 1)) fi } expect_match "CCIP_ROUTER_138" '.chains["138"].contracts.CCIP_Router' expect_match "CCIP_ROUTER_ADDRESS" '.chains["138"].contracts.CCIP_Router' expect_match "CCIPWETH9_BRIDGE_138" '.chains["138"].contracts.CCIPWETH9_Bridge' expect_match "CCIPWETH9_BRIDGE" '.chains["138"].contracts.CCIPWETH9_Bridge' expect_match "LINK_TOKEN_138" '.chains["138"].contracts.LINK' expect_match "ISO20022_ROUTER" '.chains["138"].contracts.ISO20022Router' if [[ $ERR -gt 0 ]]; then echo "[ERROR] Explorer address-inventory Chain 138 drift ($ERR). Update explorer-monorepo/config/address-inventory.json or smart-contracts-master.json." exit 1 fi echo "[OK] Explorer address-inventory Chain 138 keys match smart-contracts-master.json"