@@ -20,6 +20,22 @@ contract V4RouterTest is RoutingTestHelpers {
20
20
ERC20 -> ERC20 EXACT INPUT
21
21
//////////////////////////////////////////////////////////////*/
22
22
23
+ function test_swapExactInputSingle_revertsForAmountOut () public {
24
+ uint256 amountIn = 1 ether ;
25
+ uint256 expectedAmountOut = 992054607780215625 ;
26
+
27
+ // min amount out of 1 higher than the actual amount out
28
+ IV4Router.ExactInputSingleParams memory params = IV4Router.ExactInputSingleParams (
29
+ key0, true , uint128 (amountIn), uint128 (expectedAmountOut + 1 ), 0 , bytes ("" )
30
+ );
31
+
32
+ plan = plan.add (Actions.SWAP_EXACT_IN_SINGLE, abi.encode (params));
33
+ bytes memory data = plan.finalizeSwap (key0.currency0, key0.currency1, address (this ));
34
+
35
+ vm.expectRevert (IV4Router.TooLittleReceived.selector );
36
+ router.executeActions (data);
37
+ }
38
+
23
39
function test_swapExactInputSingle_zeroForOne () public {
24
40
uint256 amountIn = 1 ether ;
25
41
uint256 expectedAmountOut = 992054607780215625 ;
@@ -56,6 +72,22 @@ contract V4RouterTest is RoutingTestHelpers {
56
72
assertEq (outputBalanceAfter - outputBalanceBefore, expectedAmountOut);
57
73
}
58
74
75
+ function test_swapExactInput_revertsForAmountOut () public {
76
+ uint256 amountIn = 1 ether ;
77
+ uint256 expectedAmountOut = 992054607780215625 ;
78
+
79
+ tokenPath.push (currency0);
80
+ tokenPath.push (currency1);
81
+ IV4Router.ExactInputParams memory params = _getExactInputParams (tokenPath, amountIn);
82
+ params.amountOutMinimum = uint128 (expectedAmountOut + 1 );
83
+
84
+ plan = plan.add (Actions.SWAP_EXACT_IN, abi.encode (params));
85
+ bytes memory data = plan.finalizeSwap (key0.currency0, key0.currency1, address (this ));
86
+
87
+ vm.expectRevert (IV4Router.TooLittleReceived.selector );
88
+ router.executeActions (data);
89
+ }
90
+
59
91
function test_swapExactIn_1Hop_zeroForOne () public {
60
92
uint256 amountIn = 1 ether ;
61
93
uint256 expectedAmountOut = 992054607780215625 ;
@@ -287,6 +319,21 @@ contract V4RouterTest is RoutingTestHelpers {
287
319
ERC20 -> ERC20 EXACT OUTPUT
288
320
//////////////////////////////////////////////////////////////*/
289
321
322
+ function test_swapExactOutputSingle_revertsForAmountIn () public {
323
+ uint256 amountOut = 1 ether ;
324
+ uint256 expectedAmountIn = 1008049273448486163 ;
325
+
326
+ IV4Router.ExactOutputSingleParams memory params = IV4Router.ExactOutputSingleParams (
327
+ key0, true , uint128 (amountOut), uint128 (expectedAmountIn - 1 ), 0 , bytes ("" )
328
+ );
329
+
330
+ plan = plan.add (Actions.SWAP_EXACT_OUT_SINGLE, abi.encode (params));
331
+ bytes memory data = plan.finalizeSwap (key0.currency0, key0.currency1, address (this ));
332
+
333
+ vm.expectRevert (IV4Router.TooMuchRequested.selector );
334
+ router.executeActions (data);
335
+ }
336
+
290
337
function test_swapExactOutputSingle_zeroForOne () public {
291
338
uint256 amountOut = 1 ether ;
292
339
uint256 expectedAmountIn = 1008049273448486163 ;
@@ -327,6 +374,22 @@ contract V4RouterTest is RoutingTestHelpers {
327
374
assertEq (outputBalanceAfter - outputBalanceBefore, amountOut);
328
375
}
329
376
377
+ function test_swapExactOut_revertsForAmountIn () public {
378
+ uint256 amountOut = 1 ether ;
379
+ uint256 expectedAmountIn = 1008049273448486163 ;
380
+
381
+ tokenPath.push (currency0);
382
+ tokenPath.push (currency1);
383
+ IV4Router.ExactOutputParams memory params = _getExactOutputParams (tokenPath, amountOut);
384
+ params.amountInMaximum = uint128 (expectedAmountIn - 1 );
385
+
386
+ plan = plan.add (Actions.SWAP_EXACT_OUT, abi.encode (params));
387
+ bytes memory data = plan.finalizeSwap (key0.currency0, key0.currency1, address (this ));
388
+
389
+ vm.expectRevert (IV4Router.TooMuchRequested.selector );
390
+ router.executeActions (data);
391
+ }
392
+
330
393
function test_swapExactOut_1Hop_zeroForOne () public {
331
394
uint256 amountOut = 1 ether ;
332
395
uint256 expectedAmountIn = 1008049273448486163 ;
0 commit comments