import {describe, it} from 'node:test'
import assert from 'node:assert'
import {sendTokenImpl} from '../../src/plugins/custom/privy.js'
import {Ticker} from '../../src/generated/ManagingApiTypes.js'
import {ARBITRUM} from '../../src/generated/gmxsdk/configs/chains.js'

describe('send token implementation', () => {

  it('should send USDC token successfully', async () => {
    try {
      // Test addresses - you can replace these with actual addresses
      const senderAddress = '0x0af60b5c1c349744ef8fa8c4ed78ee1a0d392fe9'
      const recipientAddress = '0xeba3adc12481db743884bbd11f2a75e0c4cffcf6'
      
      // Amount as string (will be converted to smallest units internally)
      const amount = "0.000547" // ETH amount
      const ticker = Ticker.ETH
      
      console.log('Testing token transfer:')
      console.log('Sender:', senderAddress)
      console.log('Recipient:', recipientAddress)
      console.log('Amount:', amount.toString())
      console.log('Ticker:', ticker)
      
      const result = await sendTokenImpl(
        senderAddress,
        recipientAddress,
        ticker,
        amount,
        ARBITRUM
      )
      
      // Verify the result is a transaction hash (string starting with 0x)
      assert.strictEqual(typeof result, 'string')
      assert.strictEqual(result.startsWith('0x'), true)
      assert.strictEqual(result.length, 66) // Standard transaction hash length
      
      console.log('Transaction hash:', result)
      
    } catch (error) {
      console.log('Error during token transfer:', error)
      
      // Test that the error is related to actual execution rather than parameter validation
      // This could be due to insufficient balance, allowance, or network issues
      assert.fail(`Token transfer failed: ${error.message}`)
    }
  })
})
