from __future__ import annotations

from market_universe import MarketUniverseFilter, select_scan_coins
from config import BotConfig


def test_market_universe_filter_rejects_internal_symbols_and_blacklist() -> None:
    cfg = BotConfig(blacklist=("BAD",), min_volume_24h=10_000_000)
    filt = MarketUniverseFilter(cfg)

    assert filt.allowed("BTC", 50_000_000) is True
    assert filt.allowed("@123", 50_000_000) is False
    assert filt.allowed("BAD", 50_000_000) is False
    assert filt.allowed("LOW", 1_000_000) is False
    assert filt.allowed("USDC", 50_000_000) is False


def test_select_scan_coins_uses_whitelist_then_volume_cap() -> None:
    cfg = BotConfig(
        min_volume_24h=10_000_000,
        allowed_coins=("ETH", "BTC", "SOL"),
        max_scan_coins=2,
    )
    volumes = {"BTC": 100_000_000, "ETH": 200_000_000, "SOL": 150_000_000, "@1": 999_000_000, "DOGE": 300_000_000}

    assert select_scan_coins(volumes, cfg) == ["ETH", "SOL"]


def test_select_scan_coins_without_whitelist_sorts_by_volume_and_filters_noise() -> None:
    cfg = BotConfig(min_volume_24h=10_000_000, allowed_coins=(), max_scan_coins=3, blacklist=("BAD",))
    volumes = {"BTC": 9_000_000, "ETH": 30_000_000, "@2": 999_000_000, "USDT": 900_000_000, "SOL": 20_000_000, "BAD": 40_000_000, "HYPE": 25_000_000}

    assert select_scan_coins(volumes, cfg) == ["ETH", "HYPE", "SOL"]
