From 8b8f22f59469091b9f50a36d9c33a8bf995add03 Mon Sep 17 00:00:00 2001 From: mp-web3 Date: Thu, 21 Dec 2023 18:34:50 +0100 Subject: [PATCH] testSwapBuyWethIntegral passed --- evm/test/IntegralSwapAdapter.t.sol | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/evm/test/IntegralSwapAdapter.t.sol b/evm/test/IntegralSwapAdapter.t.sol index a677ec7..c112aed 100644 --- a/evm/test/IntegralSwapAdapter.t.sol +++ b/evm/test/IntegralSwapAdapter.t.sol @@ -66,4 +66,35 @@ contract IntegralSwapAdapterTest is Test, ISwapAdapterTypes { } } + function testSwapBuyWethIntegral(uint256 specifiedAmount) public { + OrderSide side = OrderSide.Buy; + + bytes32 pair = bytes32(bytes20(USDC_WETH_PAIR)); + + uint256[] memory limits = adapter.getLimits(pair, USDC, WETH); + + vm.assume(specifiedAmount < limits[1]); + vm.assume(specifiedAmount > limits[3]); + + deal(address(USDC), address(this), type(uint256).max); + USDC.approve(address(adapter), type(uint256).max); + + uint256 usdc_balance = USDC.balanceOf(address(this)); + uint256 weth_balance = WETH.balanceOf(address(this)); + + Trade memory trade = adapter.swap(pair, USDC, WETH, side, specifiedAmount); + + if (trade.calculatedAmount > 0) { + assertEq(specifiedAmount, + WETH.balanceOf(address(this)) + weth_balance + ); + + assertEq( + trade.calculatedAmount, + usdc_balance - USDC.balanceOf(address(this)) + ); + } + + } + }