/ test / GasProviderHelper.t.sol
GasProviderHelper.t.sol
 1  // SPDX-License-Identifier: MIT
 2  pragma solidity ^0.8.20;
 3  import "forge-std/Test.sol";
 4  import '../src/GasProviderHelper.sol';
 5  import './FundUSDC.sol';
 6  import "solmate/tokens/ERC20.sol";
 7  
 8  contract TestGasProviderHelper is Test {
 9  
10    FundUSDC fundUSDC;
11    GasProviderHelper gasProviderHelper;
12    ERC20 constant usdc = ERC20(0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359);
13    uint256 constant MAX_INT = 2**256 - 1;
14  
15    function setUp() public {
16      fundUSDC = new FundUSDC();
17      gasProviderHelper = new GasProviderHelper(0x92f1C3d951018C90C364c234ff5fEE00f334072F, address(usdc));
18    }
19    
20    function test_shouldSwapUSDCforETH() public {
21      fundUSDC.swapExactOutputSingle{value: 100 ether}(10_000_000, 100 ether);
22      assertEq(usdc.balanceOf(address(this)), 10_000_000);
23      usdc.approve(address(gasProviderHelper), MAX_INT);
24      uint256 balanceBefore = address(this).balance;
25      gasProviderHelper.swapTokensForGas(address(usdc));
26      
27      assertEq(usdc.balanceOf(address(this)), 0);
28      console2.log("10 USDC been exchanged for %s MATIC", address(this).balance - balanceBefore);
29    }
30  
31    receive() external payable {}
32  }