#!/usr/bin/env bash
# Test cross-chain WETH transfers

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../lib/init.sh"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
# Load .env via dotenv (RPC CR/LF trim). Fallback: raw source.
if [[ -f "$SCRIPT_DIR/../lib/deployment/dotenv.sh" ]]; then
  # shellcheck disable=SC1090
  source "$SCRIPT_DIR/../lib/deployment/dotenv.sh"
  load_deployment_env --repo-root "${PROJECT_ROOT:-$REPO_ROOT}"
elif [[ -n "${PROJECT_ROOT:-}" && -f "$PROJECT_ROOT/.env" ]]; then
  set -a
  # shellcheck disable=SC1090
  source "$PROJECT_ROOT/.env"
  set +a
elif [[ -n "${REPO_ROOT:-}" && -f "$REPO_ROOT/.env" ]]; then
  set -a
  # shellcheck disable=SC1090
  source "$REPO_ROOT/.env"
  set +a
fi


log_info "=== Cross-Chain Transfer Test ==="

# Load environment
if [ -f "$PROJECT_ROOT/.env" ]; then
    source "$PROJECT_ROOT/.env"
fi

log_info "Test Checklist:"
echo "1. ✅ Verify bridges are deployed on both chains"
echo "2. ⏳ Configure bridge destinations (addDestination)"
echo "3. ⏳ Fund bridges with LINK for CCIP fees"
echo "4. ⏳ Test WETH9 transfer: Mainnet → Chain-138"
echo "5. ⏳ Test WETH9 transfer: Chain-138 → Mainnet"
echo "6. ⏳ Test WETH10 transfer: Mainnet → Chain-138"
echo "7. ⏳ Test WETH10 transfer: Chain-138 → Mainnet"
log_warn "⚠️  Manual testing required"
echo "Test commands:"
echo "  # On Mainnet:"
echo "  cast send <BRIDGE_ADDRESS> \"sendCrossChain(uint64,address,uint256)\" <CHAIN138_SELECTOR> <RECIPIENT> <AMOUNT> --rpc-url <MAINNET_RPC> --private-key <KEY>"
echo "  # On Chain-138:"
echo "  cast send <BRIDGE_ADDRESS> \"sendCrossChain(uint64,address,uint256)\" <ETH_SELECTOR> <RECIPIENT> <AMOUNT> --rpc-url <CHAIN138_RPC> --private-key <KEY>"
