@@ -26,13 +26,15 @@ contract SpokeWithdrawValidationTest is SpokeBase {
2626 spoke1.withdraw (reserveId, amount, bob);
2727 }
2828
29- function test_withdraw_revertsWith_InsufficientSupply_zero_supplied () public {
29+ /// @dev Test passes 1 as amount with no supplied assets.
30+ /// @dev The spoke contract changes the calling amount to the total user supplied, but since it's zero, it reverts.
31+ function test_withdraw_revertsWith_InvalidAmount_zero_supplied () public {
3032 uint256 reserveId = _daiReserveId (spoke1);
3133 uint256 amount = 1 ;
3234
3335 assertEq (spoke1.getUserSuppliedAssets (reserveId, alice), 0 );
3436
35- vm.expectRevert (abi.encodeWithSelector (ISpoke.InsufficientSupply. selector , 0 ) );
37+ vm.expectRevert (IHub.InvalidAmount. selector );
3638 vm.prank (alice);
3739 spoke1.withdraw (reserveId, amount, alice);
3840 }
@@ -43,42 +45,11 @@ contract SpokeWithdrawValidationTest is SpokeBase {
4345
4446 assertEq (spoke1.getUserSuppliedAssets (reserveId, alice), 0 );
4547
46- vm.expectRevert (abi.encodeWithSelector (ISpoke.InsufficientSupply. selector , 0 ) );
48+ vm.expectRevert (IHub.InvalidAmount. selector );
4749 vm.prank (alice);
4850 spoke1.withdraw (reserveId, amount, alice);
4951 }
5052
51- // Withdraw reverts when there is not enough avaulable liquidity
52- function test_withdraw_revertsWith_InsufficientSupply_with_supply () public {
53- uint256 amount = 100e18 ;
54- uint256 reserveId = _daiReserveId (spoke1);
55-
56- // User spoke supply
57- Utils.supply ({
58- spoke: spoke1,
59- reserveId: reserveId,
60- caller: alice,
61- amount: amount,
62- onBehalfOf: alice
63- });
64-
65- uint256 withdrawalLimit = getWithdrawalLimit (spoke1, reserveId, alice);
66- assertGt (withdrawalLimit, 0 );
67-
68- vm.expectRevert (abi.encodeWithSelector (ISpoke.InsufficientSupply.selector , withdrawalLimit));
69- vm.prank (alice);
70- spoke1.withdraw (reserveId, withdrawalLimit + 1 , alice);
71-
72- // skip time but no index increase with no borrow
73- skip (365 days);
74- // withdrawal limit remains constant
75- assertEq (withdrawalLimit, getWithdrawalLimit (spoke1, reserveId, alice));
76-
77- vm.expectRevert (abi.encodeWithSelector (ISpoke.InsufficientSupply.selector , withdrawalLimit));
78- vm.prank (alice);
79- spoke1.withdraw (reserveId, withdrawalLimit + 1 , alice);
80- }
81-
8253 // Withdrawal limit increases due to debt interest, but still cannot withdraw more than available liquidity
8354 function test_withdraw_revertsWith_InsufficientSupply_with_debt () public {
8455 uint256 supplyAmount = 100e18 ;
@@ -103,18 +74,23 @@ contract SpokeWithdrawValidationTest is SpokeBase {
10374 onBehalfOf: alice
10475 });
10576
106- vm.expectRevert (abi.encodeWithSelector (ISpoke.InsufficientSupply.selector , supplyAmount));
77+ vm.expectRevert (
78+ abi.encodeWithSelector (IHub.InsufficientLiquidity.selector , supplyAmount - borrowAmount)
79+ );
10780 vm.prank (alice);
10881 spoke1.withdraw ({reserveId: reserveId, amount: supplyAmount + 1 , onBehalfOf: alice});
10982
11083 // accrue interest
11184 skip (365 days);
11285
113- uint256 newWithdrawalLimit = getWithdrawalLimit (spoke1, reserveId, alice);
86+ uint256 newWithdrawalLimit = getTotalWithdrawable (spoke1, reserveId, alice);
11487 // newWithdrawalLimit with accrued interest should be greater than supplyAmount
11588 assertGt (newWithdrawalLimit, supplyAmount);
11689
117- vm.expectRevert (abi.encodeWithSelector (ISpoke.InsufficientSupply.selector , newWithdrawalLimit));
90+ // Interest added on both sides, so can ignore
91+ vm.expectRevert (
92+ abi.encodeWithSelector (IHub.InsufficientLiquidity.selector , supplyAmount - borrowAmount)
93+ );
11894 vm.prank (alice);
11995 spoke1.withdraw ({reserveId: reserveId, amount: newWithdrawalLimit + 1 , onBehalfOf: alice});
12096 }
@@ -152,18 +128,23 @@ contract SpokeWithdrawValidationTest is SpokeBase {
152128 onBehalfOf: alice
153129 });
154130
155- vm.expectRevert (abi.encodeWithSelector (ISpoke.InsufficientSupply.selector , supplyAmount));
131+ vm.expectRevert (
132+ abi.encodeWithSelector (IHub.InsufficientLiquidity.selector , supplyAmount - borrowAmount)
133+ );
156134 vm.prank (alice);
157135 spoke1.withdraw ({reserveId: reserveId, amount: supplyAmount + 1 , onBehalfOf: alice});
158136
159137 // debt accrues
160138 skip (skipTime);
161139
162- uint256 newWithdrawalLimit = getWithdrawalLimit (spoke1, reserveId, alice);
140+ uint256 newWithdrawalLimit = getTotalWithdrawable (spoke1, reserveId, alice);
163141 // newWithdrawalLimit with accrued interest should be greater than supplyAmount
164142 vm.assume (newWithdrawalLimit > supplyAmount);
165143
166- vm.expectRevert (abi.encodeWithSelector (ISpoke.InsufficientSupply.selector , newWithdrawalLimit));
144+ // Interest added on both sides, so can ignore
145+ vm.expectRevert (
146+ abi.encodeWithSelector (IHub.InsufficientLiquidity.selector , supplyAmount - borrowAmount)
147+ );
167148 vm.prank (alice);
168149 spoke1.withdraw ({reserveId: reserveId, amount: newWithdrawalLimit + 1 , onBehalfOf: alice});
169150 }
0 commit comments