mock sets up three pools including a stablecoin pair pool and a pool with native wrapper token
This commit is contained in:
@@ -140,7 +140,7 @@ contract NativeTest is Test {
|
||||
|
||||
// Execute swap: WETH (index 2) -> token0 (index 0)
|
||||
// Send native currency with {value: maxIn}
|
||||
(uint256 amountIn, uint256 amountOut, uint256 fee) = pool.swap{value: maxIn}(
|
||||
(uint256 amountIn, uint256 amountOut, ) = pool.swap{value: maxIn}(
|
||||
alice, // payer
|
||||
alice, // receiver
|
||||
2, // inputTokenIndex (WETH)
|
||||
@@ -177,7 +177,7 @@ contract NativeTest is Test {
|
||||
uint256 aliceEthBefore = alice.balance;
|
||||
|
||||
// Execute swap: token0 (index 0) -> WETH (index 2) with unwrap=true
|
||||
(uint256 amountIn, uint256 amountOut, uint256 fee) = pool.swap(
|
||||
(uint256 amountIn, uint256 amountOut, ) = pool.swap(
|
||||
alice, // payer
|
||||
alice, // receiver
|
||||
0, // inputTokenIndex (token0)
|
||||
@@ -212,7 +212,7 @@ contract NativeTest is Test {
|
||||
uint256 aliceEthBefore = alice.balance;
|
||||
|
||||
// Execute swap with excess native currency
|
||||
(uint256 amountIn, uint256 amountOut, uint256 fee) = pool.swap{value: totalSent}(
|
||||
(uint256 amountIn, , ) = pool.swap{value: totalSent}(
|
||||
alice, // payer
|
||||
alice, // receiver
|
||||
2, // inputTokenIndex (WETH)
|
||||
@@ -225,7 +225,6 @@ contract NativeTest is Test {
|
||||
|
||||
// Verify that only amountIn was used, and excess was refunded
|
||||
assertTrue(amountIn <= maxIn, "used input must not exceed max");
|
||||
uint256 expectedRefund = totalSent - amountIn;
|
||||
assertEq(alice.balance, aliceEthBefore - amountIn, "Alice should be refunded excess ETH");
|
||||
|
||||
vm.stopPrank();
|
||||
@@ -537,21 +536,19 @@ contract NativeTest is Test {
|
||||
token0.approve(address(pool), type(uint256).max);
|
||||
token1.approve(address(pool), type(uint256).max);
|
||||
|
||||
uint256 aliceEthStart = alice.balance;
|
||||
|
||||
uint256 lpMinted = pool.mint{value: deposits[2]}(alice, alice, lpRequest, 0);
|
||||
assertTrue(lpMinted > 0, "Should mint LP");
|
||||
|
||||
// 2. Swap native currency for token0
|
||||
uint256 swapAmount = 5_000;
|
||||
(uint256 amountIn, uint256 amountOut, ) = pool.swap{value: swapAmount}(
|
||||
(, uint256 amountOut, ) = pool.swap{value: swapAmount}(
|
||||
alice, alice, 2, 0, swapAmount, 0, 0, false
|
||||
);
|
||||
assertTrue(amountOut > 0, "Should receive token0");
|
||||
|
||||
// 3. Swap token0 back to native currency
|
||||
uint256 token0Balance = token0.balanceOf(alice);
|
||||
(uint256 swapIn2, uint256 swapOut2, ) = pool.swap(
|
||||
(, uint256 swapOut2, ) = pool.swap(
|
||||
alice, alice, 0, 2, token0Balance / 2, 0, 0, true
|
||||
);
|
||||
assertTrue(swapOut2 > 0, "Should receive native currency");
|
||||
@@ -578,7 +575,7 @@ contract NativeTest is Test {
|
||||
uint256 aliceEthBefore = alice.balance;
|
||||
|
||||
// Swap token0 -> WETH without unwrap
|
||||
(uint256 amountIn, uint256 amountOut, ) = pool.swap(
|
||||
(, uint256 amountOut, ) = pool.swap(
|
||||
alice, alice, 0, 2, maxIn, 0, 0, false // unwrap=false
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user