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

import {Test, console} from "forge-std/Test.sol";
import {wXRP} from "../../../contracts/bridge/interop/wXRP.sol";

contract wXRPTest is Test {
    wXRP public wxrp;
    address public admin = address(0x1);
    address public minter = address(0x2);
    address public burner = address(0x3);
    address public user = address(0x4);

    function setUp() public {
        vm.startPrank(admin);
        wxrp = new wXRP(admin);
        wxrp.grantRole(wxrp.MINTER_ROLE(), minter);
        wxrp.grantRole(wxrp.BURNER_ROLE(), burner);
        vm.stopPrank();
    }

    function test_Mint() public {
        bytes32 xrplTxHash = keccak256("xrpl-tx-1");
        
        vm.startPrank(minter);
        wxrp.mint(user, 1000 * 10**18, xrplTxHash);
        vm.stopPrank();

        assertEq(wxrp.balanceOf(user), 1000 * 10**18);
        assertEq(wxrp.totalSupply(), 1000 * 10**18);
    }

    function test_Burn() public {
        bytes32 xrplTxHash1 = keccak256("xrpl-tx-1");
        bytes32 xrplTxHash2 = keccak256("xrpl-tx-2");
        
        vm.startPrank(minter);
        wxrp.mint(user, 1000 * 10**18, xrplTxHash1);
        vm.stopPrank();

        vm.startPrank(burner);
        wxrp.burnFrom(user, 500 * 10**18, xrplTxHash2);
        vm.stopPrank();

        assertEq(wxrp.balanceOf(user), 500 * 10**18);
        assertEq(wxrp.totalSupply(), 500 * 10**18);
    }

    function test_Decimals() public view {
        assertEq(wxrp.decimals(), 18);
    }

    function test_Pause() public {
        vm.startPrank(admin);
        wxrp.pause();
        vm.stopPrank();

        bytes32 xrplTxHash = keccak256("xrpl-tx");
        vm.startPrank(minter);
        vm.expectRevert();
        wxrp.mint(user, 1000 * 10**18, xrplTxHash);
    }
}
