Skip to content

Commit 1b24d9d

Browse files
committed
test: add separate withdrawal as tokens and shares methods
1 parent 619e67e commit 1b24d9d

File tree

5 files changed

+27
-20
lines changed

5 files changed

+27
-20
lines changed

src/test/integration/tests/utils.t.sol renamed to src/test/integration/IntegrationChecks.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "src/test/integration/IntegrationBase.t.sol";
55
import "src/test/integration/User.t.sol";
66

77
/// @notice Contract that provides utility functions to reuse common test blocks & checks
8-
contract IntegrationTestUtils is IntegrationBase {
8+
contract IntegrationCheckUtils is IntegrationBase {
99

1010
function check_Deposit_State(User staker, IStrategy[] memory strategies, uint[] memory shares) internal {
1111
/// Deposit into strategies:

src/test/integration/User.t.sol

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,19 @@ contract User is Test {
176176

177177
return (withdrawals);
178178
}
179+
180+
function completeWithdrawalAsTokens(IDelegationManager.Withdrawal memory withdrawal) public createSnapshot virtual returns (IERC20[] memory) {
181+
return _completeQueuedWithdrawal(withdrawal, true);
182+
}
183+
184+
function completeWithdrawalAsShares(IDelegationManager.Withdrawal memory withdrawal) public createSnapshot virtual returns (IERC20[] memory) {
185+
return _completeQueuedWithdrawal(withdrawal, false);
186+
}
179187

180-
function completeQueuedWithdrawal(
188+
function _completeQueuedWithdrawal(
181189
IDelegationManager.Withdrawal memory withdrawal,
182190
bool receiveAsTokens
183-
) public createSnapshot virtual returns (IERC20[] memory) {
191+
) internal virtual returns (IERC20[] memory) {
184192
IERC20[] memory tokens = new IERC20[](withdrawal.strategies.length);
185193

186194
for (uint i = 0; i < tokens.length; i++) {

src/test/integration/tests/Deposit_Delegate_Queue_Complete.t.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// SPDX-License-Identifier: BUSL-1.1
22
pragma solidity =0.8.12;
33

4-
import "src/test/integration/tests/utils.t.sol";
4+
import "src/test/integration/IntegrationChecks.t.sol";
55
import "src/test/integration/User.t.sol";
66

7-
contract Integration_Deposit_Delegate_Queue_Complete is IntegrationTestUtils {
7+
contract Integration_Deposit_Delegate_Queue_Complete is IntegrationCheckUtils {
88

99
/*******************************************************************************
1010
FULL WITHDRAWALS
@@ -58,7 +58,7 @@ contract Integration_Deposit_Delegate_Queue_Complete is IntegrationTestUtils {
5858

5959
for (uint i = 0; i < withdrawals.length; i++) {
6060
uint[] memory expectedTokens = _calculateExpectedTokens(withdrawals[i].strategies, withdrawals[i].shares);
61-
IERC20[] memory tokens = staker.completeQueuedWithdrawal(withdrawals[i], true);
61+
IERC20[] memory tokens = staker.completeWithdrawalAsTokens(withdrawals[i]);
6262
check_Withdrawal_AsTokens_State(staker, operator, withdrawals[i], strategies, shares, tokens, expectedTokens);
6363
}
6464

@@ -116,7 +116,7 @@ contract Integration_Deposit_Delegate_Queue_Complete is IntegrationTestUtils {
116116
cheats.roll(block.number + delegationManager.withdrawalDelayBlocks());
117117

118118
for (uint i = 0; i < withdrawals.length; i++) {
119-
staker.completeQueuedWithdrawal(withdrawals[i], false);
119+
staker.completeWithdrawalAsShares(withdrawals[i]);
120120
check_Withdrawal_AsShares_State(staker, operator, withdrawals[i], strategies, shares);
121121
}
122122

@@ -184,7 +184,7 @@ contract Integration_Deposit_Delegate_Queue_Complete is IntegrationTestUtils {
184184
cheats.roll(block.number + delegationManager.withdrawalDelayBlocks());
185185
for (uint i = 0; i < withdrawals.length; i++) {
186186
uint[] memory expectedTokens = _calculateExpectedTokens(withdrawals[i].strategies, withdrawals[i].shares);
187-
IERC20[] memory tokens = staker.completeQueuedWithdrawal(withdrawals[i], true);
187+
IERC20[] memory tokens = staker.completeWithdrawalAsTokens(withdrawals[i]);
188188
check_Withdrawal_AsTokens_State(staker, operator, withdrawals[i], withdrawStrats, withdrawShares, tokens, expectedTokens);
189189
}
190190

@@ -246,7 +246,7 @@ contract Integration_Deposit_Delegate_Queue_Complete is IntegrationTestUtils {
246246
cheats.roll(block.number + delegationManager.withdrawalDelayBlocks());
247247

248248
for (uint i = 0; i < withdrawals.length; i++) {
249-
staker.completeQueuedWithdrawal(withdrawals[i], false);
249+
staker.completeWithdrawalAsShares(withdrawals[i]);
250250
check_Withdrawal_AsShares_State(staker, operator, withdrawals[i], withdrawStrats, withdrawShares);
251251
}
252252

src/test/integration/tests/Deposit_Delegate_Redelegate_Complete.t.sol

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// SPDX-License-Identifier: BUSL-1.1
22
pragma solidity =0.8.12;
33

4-
import "src/test/integration/IntegrationBase.t.sol";
54
import "src/test/integration/User.t.sol";
6-
import "src/test/integration/tests/utils.t.sol";
5+
import "src/test/integration/IntegrationChecks.t.sol";
76

8-
contract Integration_Deposit_Delegate_Redelegate_Complete is IntegrationTestUtils {
7+
contract Integration_Deposit_Delegate_Redelegate_Complete is IntegrationCheckUtils {
98
/// Randomly generates a user with different held assets. Then:
109
/// 1. deposit into strategy
1110
/// 2. delegate to an operator
@@ -56,7 +55,7 @@ contract Integration_Deposit_Delegate_Redelegate_Complete is IntegrationTestUtil
5655
// 4. Complete withdrawal as shares
5756
// Fast forward to when we can complete the withdrawal
5857
cheats.roll(block.number + delegationManager.withdrawalDelayBlocks());
59-
staker.completeQueuedWithdrawal(withdrawals[0], false);
58+
staker.completeWithdrawalAsShares(withdrawals[0]);
6059
check_Withdrawal_AsShares_Undelegated_State(staker, operator1, withdrawals[0], strategies, shares);
6160

6261
// 5. Delegate to a new operator
@@ -76,7 +75,7 @@ contract Integration_Deposit_Delegate_Redelegate_Complete is IntegrationTestUtil
7675
// Complete withdrawals
7776
for (uint i = 0; i < withdrawals.length; i++) {
7877
uint[] memory expectedTokens = _calculateExpectedTokens(withdrawals[i].strategies, withdrawals[i].shares);
79-
IERC20[] memory tokens = staker.completeQueuedWithdrawal(withdrawals[i], true);
78+
IERC20[] memory tokens = staker.completeWithdrawalAsTokens(withdrawals[i]);
8079
check_Withdrawal_AsTokens_State(staker, operator2, withdrawals[i], strategies, shares, tokens, expectedTokens);
8180
}
8281
}

src/test/integration/tests/Deposit_Delegate_Undelegate_Complete.t.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
pragma solidity =0.8.12;
33

44
import "src/test/integration/User.t.sol";
5-
import "src/test/integration/tests/utils.t.sol";
5+
import "src/test/integration/IntegrationChecks.t.sol";
66

7-
contract Integration_Deposit_Delegate_Undelegate_Complete is IntegrationTestUtils {
7+
contract Integration_Deposit_Delegate_Undelegate_Complete is IntegrationCheckUtils {
88

99
/// Randomly generates a user with different held assets. Then:
1010
/// 1. deposit into strategy
@@ -55,7 +55,7 @@ contract Integration_Deposit_Delegate_Undelegate_Complete is IntegrationTestUtil
5555

5656
// Complete withdrawal
5757
uint[] memory expectedTokens = _calculateExpectedTokens(withdrawals[0].strategies, withdrawals[0].shares);
58-
IERC20[] memory tokens = staker.completeQueuedWithdrawal(withdrawals[0], true);
58+
IERC20[] memory tokens = staker.completeWithdrawalAsTokens(withdrawals[0]);
5959
check_Withdrawal_AsTokens_State(staker, operator, withdrawals[0], strategies, shares, tokens, expectedTokens);
6060

6161
// Check Final State
@@ -110,7 +110,7 @@ contract Integration_Deposit_Delegate_Undelegate_Complete is IntegrationTestUtil
110110
// 4. Complete withdrawal
111111
// Fast forward to when we can complete the withdrawal
112112
cheats.roll(block.number + delegationManager.withdrawalDelayBlocks());
113-
staker.completeQueuedWithdrawal(withdrawals[0], false);
113+
staker.completeWithdrawalAsShares(withdrawals[0]);
114114
check_Withdrawal_AsShares_Undelegated_State(staker, operator, withdrawals[0], strategies, shares);
115115

116116
// Check final state:
@@ -162,7 +162,7 @@ contract Integration_Deposit_Delegate_Undelegate_Complete is IntegrationTestUtil
162162
cheats.roll(block.number + delegationManager.withdrawalDelayBlocks());
163163

164164
uint[] memory expectedTokens = _calculateExpectedTokens(withdrawals[0].strategies, withdrawals[0].shares);
165-
IERC20[] memory tokens = staker.completeQueuedWithdrawal(withdrawals[0], true);
165+
IERC20[] memory tokens = staker.completeWithdrawalAsTokens(withdrawals[0]);
166166
check_Withdrawal_AsTokens_State(staker, operator, withdrawals[0], strategies, shares, tokens, expectedTokens);
167167

168168
// Check Final State
@@ -212,7 +212,7 @@ contract Integration_Deposit_Delegate_Undelegate_Complete is IntegrationTestUtil
212212
// 4. Complete withdrawal
213213
// Fast forward to when we can complete the withdrawal
214214
cheats.roll(block.number + delegationManager.withdrawalDelayBlocks());
215-
staker.completeQueuedWithdrawal(withdrawals[0], false);
215+
staker.completeWithdrawalAsShares(withdrawals[0]);
216216
check_Withdrawal_AsShares_Undelegated_State(staker, operator, withdrawals[0], strategies, shares);
217217

218218
// Check final state:

0 commit comments

Comments
 (0)