import type { Address } from 'ox'
import { ChannelDescriptor } from 'ox/tempo'
import { describe, expect, test } from 'vitest'

describe('from', () => {
  test('default', () => {
    expect(
      ChannelDescriptor.from({
        authorizedSigner: '0x3333333333333333333333333333333333333333',
        expiringNonceHash:
          '0x0000000000000000000000000000000000000000000000000000000000000002',
        operator: '0x4444444444444444444444444444444444444444',
        payee: '0x2222222222222222222222222222222222222222',
        payer: '0x1111111111111111111111111111111111111111',
        salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
        token: 1n,
      }),
    ).toMatchInlineSnapshot(`
      {
        "authorizedSigner": "0x3333333333333333333333333333333333333333",
        "expiringNonceHash": "0x0000000000000000000000000000000000000000000000000000000000000002",
        "operator": "0x4444444444444444444444444444444444444444",
        "payee": "0x2222222222222222222222222222222222222222",
        "payer": "0x1111111111111111111111111111111111111111",
        "salt": "0x0000000000000000000000000000000000000000000000000000000000000001",
        "token": "0x20c0000000000000000000000000000000000001",
      }
    `)
  })

  test('default values', () => {
    expect(
      ChannelDescriptor.from({
        expiringNonceHash:
          '0x0000000000000000000000000000000000000000000000000000000000000002',
        payee: '0x2222222222222222222222222222222222222222',
        payer: '0x1111111111111111111111111111111111111111',
        salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
        token: 1n,
      }),
    ).toMatchInlineSnapshot(`
      {
        "authorizedSigner": "0x0000000000000000000000000000000000000000",
        "expiringNonceHash": "0x0000000000000000000000000000000000000000000000000000000000000002",
        "operator": "0x0000000000000000000000000000000000000000",
        "payee": "0x2222222222222222222222222222222222222222",
        "payer": "0x1111111111111111111111111111111111111111",
        "salt": "0x0000000000000000000000000000000000000000000000000000000000000001",
        "token": "0x20c0000000000000000000000000000000000001",
      }
    `)
  })

  test('token address input', () => {
    expect(
      ChannelDescriptor.from({
        authorizedSigner: '0x3333333333333333333333333333333333333333',
        expiringNonceHash:
          '0x0000000000000000000000000000000000000000000000000000000000000002',
        operator: '0x4444444444444444444444444444444444444444',
        payee: '0x2222222222222222222222222222222222222222',
        payer: '0x1111111111111111111111111111111111111111',
        salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
        token: '0x20c0000000000000000000000000000000000001',
      }),
    ).toMatchInlineSnapshot(`
      {
        "authorizedSigner": "0x3333333333333333333333333333333333333333",
        "expiringNonceHash": "0x0000000000000000000000000000000000000000000000000000000000000002",
        "operator": "0x4444444444444444444444444444444444444444",
        "payee": "0x2222222222222222222222222222222222222222",
        "payer": "0x1111111111111111111111111111111111111111",
        "salt": "0x0000000000000000000000000000000000000000000000000000000000000001",
        "token": "0x20c0000000000000000000000000000000000001",
      }
    `)
  })

  test('return type', () => {
    const descriptor = ChannelDescriptor.from({
      expiringNonceHash:
        '0x0000000000000000000000000000000000000000000000000000000000000002',
      payee: '0x2222222222222222222222222222222222222222',
      payer: '0x1111111111111111111111111111111111111111',
      salt: '0x0000000000000000000000000000000000000000000000000000000000000001',
      token: 1n,
    })

    descriptor satisfies ChannelDescriptor.Resolved
    descriptor.payer satisfies Address.Address
    descriptor.token satisfies Address.Address
  })
})
