<?php

namespace Tests\Unit;

use App\Helpers\TronHelper;
use PHPUnit\Framework\TestCase;

class TronHelperUsdtTransferTest extends TestCase
{
    public function test_approval_event_is_not_a_usdt_recharge(): void
    {
        $result = TronHelper::parseUsdtTransferEventFromTransactionInfo([
            'blockNumber' => 83562014,
            'blockTimeStamp' => 1781355336000,
            'receipt' => ['result' => 'SUCCESS'],
            'log' => [[
                'address' => 'a614f803b6fd780986a42c78ec9c7f77e6ded13c',
                'topics' => [
                    '8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925',
                    '000000000000000000000000333acb6d5137263acb0f5a25f34dd45bd87cca39',
                    '000000000000000000000000b0c9500c261fa39a70de3b350a9f71fa0d46c474',
                ],
                'data' => '0000000000000000000000000000000000000000000000000000000005f5e100',
            ]],
        ], 'TS5y6GiRJdkHD8kodi1nZynqy5ojzjuypq', 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t');

        $this->assertFalse($result['success']);
        $this->assertTrue($result['invalid']);
    }

    public function test_transfer_event_to_expected_address_is_a_usdt_recharge(): void
    {
        $result = TronHelper::parseUsdtTransferEventFromTransactionInfo([
            'blockNumber' => 83562014,
            'blockTimeStamp' => 1781355336000,
            'receipt' => ['result' => 'SUCCESS'],
            'log' => [[
                'address' => 'a614f803b6fd780986a42c78ec9c7f77e6ded13c',
                'topics' => [
                    TronHelper::TRC20_TRANSFER_TOPIC,
                    '000000000000000000000000333acb6d5137263acb0f5a25f34dd45bd87cca39',
                    '000000000000000000000000b0c9500c261fa39a70de3b350a9f71fa0d46c474',
                ],
                'data' => '0000000000000000000000000000000000000000000000000000000005f5e100',
            ]],
        ], 'TS5y6GiRJdkHD8kodi1nZynqy5ojzjuypq', 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t');

        $this->assertTrue($result['success']);
        $this->assertSame('TEe5txwddmGjsgP5EfBNG8M3qLM4JR3x7Z', $result['from_address']);
        $this->assertSame('TS5y6GiRJdkHD8kodi1nZynqy5ojzjuypq', $result['to_address']);
        $this->assertSame('100.000000', $result['amount']);
    }
}
