// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {Test} from "forge-std/Test.sol";
import {MirrorDetailExtension} from "../../contracts/mainnet-checkpoint/extensions/MirrorDetailExtension.sol";
import {CheckpointStorage} from "../../contracts/mainnet-checkpoint/storage/CheckpointStorage.sol";
import {CheckpointLeaf} from "../../contracts/mainnet-checkpoint/libraries/CheckpointLeaf.sol";

contract MirrorDetailV2DecodeTest is Test {
    MirrorDetailExtension mirror;

    function setUp() public {
        mirror = new MirrorDetailExtension();
    }

    function testAfterSubmitStoresV2TokenValue() public {
        CheckpointLeaf.PaymentLeafV2[] memory leaves = new CheckpointLeaf.PaymentLeafV2[](1);
        leaves[0] = CheckpointLeaf.PaymentLeafV2({
            txHash: keccak256("t"),
            from: address(1),
            to: address(2),
            token: address(0xAA),
            value: 5_000_000,
            blockNumber: 1,
            blockTimestamp: 2,
            gasUsed: 3,
            success: true,
            logIndex: 0
        });
        bytes memory data = abi.encode(bytes1(0x02), leaves);
        CheckpointStorage.CheckpointHeader memory header = CheckpointStorage.CheckpointHeader({
            batchId: 1,
            previousBatchId: 0,
            chainId: 138,
            checkpointBlock: 1,
            startBlock: 1,
            endBlock: 1,
            blockHash: bytes32(0),
            stateRoot: bytes32(0),
            paymentsRoot: bytes32(0),
            receiptsRoot: bytes32(0),
            txCount: 1,
            flags: 0,
            submittedAt: 0,
            submitter: address(0),
            contentURI: bytes32(0)
        });
        mirror.afterSubmit(header, data);
        (, , , uint256 value, , , , ) = mirror.transactions(leaves[0].txHash);
        assertEq(value, 5_000_000);
        assertEq(mirror.txToken(leaves[0].txHash), address(0xAA));
    }
}
