import {
  isWalletWatchAssetEligible,
  isWalletWatchEligibleTokenAddress,
  dedupeWatchAssetEntriesBySymbol,
} from './wallet-watch-eligible';

describe('wallet-watch-eligible', () => {
  it('excludes deterministic placeholder addresses', () => {
    expect(isWalletWatchEligibleTokenAddress('0xcaaa00000000000000000000000000000000008a')).toBe(false);
    expect(isWalletWatchEligibleTokenAddress('0x93E66202A11B1772E55407B32B44e5Cd8eda7f22')).toBe(true);
  });

  it('excludes gas-native placeholder specs on Chain 138', () => {
    expect(
      isWalletWatchAssetEligible(
        { symbol: 'cAVAX', addresses: { 138: '0xcaaa00000000000000000000000000000000008a' } },
        138,
      ),
    ).toBe(false);
  });

  it('excludes staged V2 family deployments that would collide in MetaMask', () => {
    expect(
      isWalletWatchAssetEligible(
        {
          symbol: 'cUSDC_V2',
          familySymbol: 'cUSDC',
          deploymentVersion: 'v2',
          deploymentStatus: 'staged',
          addresses: { 138: '0x219522c60e83dEe01FC5b0329d6fA8fD84b9D13d' },
        },
        138,
      ),
    ).toBe(false);
    expect(
      isWalletWatchAssetEligible(
        { symbol: 'cUSDC', addresses: { 138: '0xf22258f57794CC8E06237084b353Ab30fFfa640b' } },
        138,
      ),
    ).toBe(true);
  });

  it('dedupes watchAsset rows by wallet symbol', () => {
    const deduped = dedupeWatchAssetEntriesBySymbol([
      {
        options: { symbol: 'cUSDC', address: '0xf22258f57794CC8E06237084b353Ab30fFfa640b' },
        metadata: { catalogSymbol: 'cUSDC' },
      },
      {
        options: { symbol: 'cUSDC', address: '0x219522c60e83dEe01FC5b0329d6fA8fD84b9D13d' },
        metadata: { catalogSymbol: 'cUSDC_V2', deploymentVersion: 'v2', deploymentStatus: 'staged' },
      },
    ]);
    expect(deduped).toHaveLength(1);
    expect(deduped[0]?.options.address).toBe('0xf22258f57794CC8E06237084b353Ab30fFfa640b');
  });
});
