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

import {Test, console} from "forge-std/Test.sol";
import {WETH} from "../contracts/tokens/WETH.sol";

contract WETHTest is Test {
    WETH public weth;
    address public user = address(0x10); // Use address that can receive ETH (not precompile)
    
    function setUp() public {
        weth = new WETH();
        vm.deal(user, 10 ether);
    }
    
    function testDeposit() public {
        vm.prank(user);
        weth.deposit{value: 1 ether}();
        
        assertEq(weth.balanceOf(user), 1 ether);
        assertEq(weth.totalSupply(), 1 ether);
    }
    
    function testWithdraw() public {
        vm.deal(user, 10 ether);
        vm.prank(user);
        weth.deposit{value: 1 ether}();
        
        // WETH contract now has 1 ether from the deposit
        uint256 balanceBefore = user.balance;
        vm.prank(user);
        weth.withdraw(1 ether);
        
        assertEq(weth.balanceOf(user), 0);
        assertEq(user.balance, balanceBefore + 1 ether);
    }
    
    function testTransfer() public {
        address recipient = address(2);
        
        vm.prank(user);
        weth.deposit{value: 1 ether}();
        
        vm.prank(user);
        weth.transfer(recipient, 0.5 ether);
        
        assertEq(weth.balanceOf(user), 0.5 ether);
        assertEq(weth.balanceOf(recipient), 0.5 ether);
    }
    
    function testApprove() public {
        address spender = address(2);
        
        vm.prank(user);
        weth.deposit{value: 1 ether}();
        
        vm.prank(user);
        weth.approve(spender, 0.5 ether);
        
        assertEq(weth.allowance(user, spender), 0.5 ether);
    }
    
    function testReceive() public {
        vm.prank(user);
        (bool success, ) = address(weth).call{value: 1 ether}("");
        require(success, "Transfer failed");
        
        assertEq(weth.balanceOf(user), 1 ether);
    }
}

