package track1

import (
	"testing"

	"github.com/stretchr/testify/require"
)

func TestBridgeFundingStatus(t *testing.T) {
	require.Equal(t, "funded", bridgeFundingStatus("2000000000000000000", "1000000000000000000"))
	require.Equal(t, "degraded", bridgeFundingStatus("500000000000000000", "1000000000000000000"))
	require.Equal(t, "unfunded", bridgeFundingStatus("0", "1000000000000000000"))
}

func TestAggregateLaneStatus(t *testing.T) {
	require.Equal(t, "unfunded", aggregateLaneStatus("unfunded", "funded", "proof-recorded"))
	require.Equal(t, "degraded", aggregateLaneStatus("degraded", "funded", "proof-recorded"))
	require.Equal(t, "proof-pending", aggregateLaneStatus("funded", "funded", "proof-pending"))
	require.Equal(t, "funded", aggregateLaneStatus("funded", "funded", "proof-recorded"))
}

func TestProofStatusForLane(t *testing.T) {
	proofs := map[string]interface{}{
		"gnosis": []interface{}{
			map[string]interface{}{"tx_hash": "0xabc"},
		},
	}
	require.Equal(t, "proof-recorded", proofStatusForLane("gnosis", proofs))
	require.Equal(t, "proof-pending", proofStatusForLane("cronos", proofs))
}

func TestLoadBridgeLanesConfigDefault(t *testing.T) {
	t.Setenv("MISSION_CONTROL_BRIDGE_LANES_JSON", "")
	cfg := loadBridgeLanesConfig()
	require.NotEmpty(t, cfg.Lanes)
	require.NotEmpty(t, cfg.MinLinkWei)
}
