Skip to content

Commit 2a14f1a

Browse files
committed
test: deposit, delegate, redelegate, complete
1 parent 6d608fd commit 2a14f1a

File tree

1 file changed

+141
-1
lines changed

1 file changed

+141
-1
lines changed

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

Lines changed: 141 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,147 @@ contract Integration_Deposit_Delegate_Redelegate_Complete is IntegrationTestUtil
1414
/// 5. delegate to a new operator
1515
/// 5. queueWithdrawal
1616
/// 7. complete their queued withdrawal as tokens
17-
function testFuzz_deposit_delegate_reDelegate_completeAsTokens(uint24 _random) public {
17+
function testFuzz_deposit_delegate_reDelegate_completeLastWithdrawalAsShares(uint24 _random) public {
18+
// When new Users are created, they will choose a random configuration from these params:
19+
_configRand({
20+
_randomSeed: _random,
21+
_assetTypes: HOLDS_LST | HOLDS_ETH | HOLDS_ALL,
22+
_userTypes: DEFAULT | ALT_METHODS
23+
});
24+
25+
/// 0. Create an operator and a staker with:
26+
// - some nonzero underlying token balances
27+
// - corresponding to a random number of strategies
28+
//
29+
// ... check that the staker has no deleagatable shares and isn't delegated
30+
31+
(
32+
User staker,
33+
IStrategy[] memory strategies,
34+
uint[] memory tokenBalances
35+
) = _newRandomStaker();
36+
(User operator1, ,) = _newRandomOperator();
37+
(User operator2, ,) = _newRandomOperator();
38+
uint[] memory shares = _calculateExpectedShares(strategies, tokenBalances);
39+
40+
assert_HasNoDelegatableShares(staker, "staker should not have delegatable shares before depositing");
41+
assertFalse(delegationManager.isDelegated(address(staker)), "staker should not be delegated");
42+
43+
/// 1. Deposit Into Strategies
44+
staker.depositIntoEigenlayer(strategies, tokenBalances);
45+
assertDepositState(staker, strategies, shares);
46+
47+
// 2. Delegate to an operator
48+
staker.delegateTo(operator1);
49+
assertDelegationState(staker, operator1, strategies, shares);
50+
51+
// 3. Undelegate from an operator
52+
IDelegationManager.Withdrawal memory expectedWithdrawal = _getExpectedWithdrawalStruct(staker);
53+
bytes32 withdrawalRoot = staker.undelegate();
54+
assertUndelegateState(staker, operator1, expectedWithdrawal, withdrawalRoot, strategies, shares);
55+
56+
// 4. Complete withdrawal as shares
57+
// Fast forward to when we can complete the withdrawal
58+
cheats.roll(block.number + delegationManager.withdrawalDelayBlocks());
59+
staker.completeQueuedWithdrawal(expectedWithdrawal, false);
60+
61+
assertWithdrawalAsSharesState(staker, expectedWithdrawal, strategies, shares);
62+
63+
// 5. Delegate to a new operator
64+
staker.delegateTo(operator2);
65+
assertDelegationState(staker, operator2, strategies, shares);
66+
assertNotEq(address(operator1), delegationManager.delegatedTo(address(staker)), "staker should not be delegated to operator1");
67+
68+
// 6. Queue Withdrawal
69+
IDelegationManager.Withdrawal[] memory withdrawals;
70+
bytes32[] memory withdrawalRoots;
71+
(withdrawals, withdrawalRoots) = staker.queueWithdrawals(strategies, shares);
72+
assertQueuedWithdrawalState(staker, operator2, strategies, shares, withdrawals, withdrawalRoots);
73+
74+
// 7. Complete withdrawal
75+
// Fast forward to when we can complete the withdrawal
76+
cheats.roll(block.number + delegationManager.withdrawalDelayBlocks());
77+
78+
// Complete all but last withdrawal as tokens
79+
for (uint i = 0; i < withdrawals.length - 1; i++) {
80+
staker.completeQueuedWithdrawal(withdrawals[i], true);
81+
}
82+
83+
// Complete last withdrawal as shares
84+
staker.completeQueuedWithdrawal(withdrawals[withdrawals.length - 1], false);
85+
assertWithdrawalAsSharesState(staker, withdrawals[withdrawals.length - 1], strategies, shares);
86+
}
87+
88+
function testFuzz_deposit_delegate_reDelegate_withAdditionalDepositBefore(uint24 _random) public {
89+
// When new Users are created, they will choose a random configuration from these params:
90+
_configRand({
91+
_randomSeed: _random,
92+
_assetTypes: HOLDS_LST | HOLDS_ETH | HOLDS_ALL,
93+
_userTypes: DEFAULT | ALT_METHODS
94+
});
95+
96+
/// 0. Create an operator and a staker with:
97+
// - some nonzero underlying token balances
98+
// - corresponding to a random number of strategies
99+
//
100+
// ... check that the staker has no deleagatable shares and isn't delegated
101+
102+
(
103+
User staker,
104+
IStrategy[] memory strategies,
105+
uint[] memory tokenBalances
106+
) = _newRandomStaker();
107+
(User operator1, ,) = _newRandomOperator();
108+
(User operator2, ,) = _newRandomOperator();
109+
uint[] memory shares = _calculateExpectedShares(strategies, tokenBalances);
110+
111+
assert_HasNoDelegatableShares(staker, "staker should not have delegatable shares before depositing");
112+
assertFalse(delegationManager.isDelegated(address(staker)), "staker should not be delegated");
113+
114+
/// 1. Deposit Into Strategies
115+
staker.depositIntoEigenlayer(strategies, tokenBalances);
116+
assertDepositState(staker, strategies, shares);
117+
118+
// 2. Delegate to an operator
119+
staker.delegateTo(operator1);
120+
assertDelegationState(staker, operator1, strategies, shares);
121+
122+
// 3. Undelegate from an operator
123+
IDelegationManager.Withdrawal memory expectedWithdrawal = _getExpectedWithdrawalStruct(staker);
124+
bytes32 withdrawalRoot = staker.undelegate();
125+
assertUndelegateState(staker, operator1, expectedWithdrawal, withdrawalRoot, strategies, shares);
126+
127+
// 4. Complete withdrawal as shares
128+
// Fast forward to when we can complete the withdrawal
129+
cheats.roll(block.number + delegationManager.withdrawalDelayBlocks());
130+
staker.completeQueuedWithdrawal(expectedWithdrawal, false);
131+
132+
assertWithdrawalAsSharesState(staker, expectedWithdrawal, strategies, shares);
133+
134+
// 5. Delegate to a new operator
135+
staker.delegateTo(operator2);
136+
assertDelegationState(staker, operator2, strategies, shares);
137+
assertNotEq(address(operator1), delegationManager.delegatedTo(address(staker)), "staker should not be delegated to operator1");
138+
139+
// 6. Queue Withdrawal
140+
IDelegationManager.Withdrawal[] memory withdrawals;
141+
bytes32[] memory withdrawalRoots;
142+
(withdrawals, withdrawalRoots) = staker.queueWithdrawals(strategies, shares);
143+
assertQueuedWithdrawalState(staker, operator2, strategies, shares, withdrawals, withdrawalRoots);
144+
145+
// 7. Complete withdrawal
146+
// Fast forward to when we can complete the withdrawal
147+
cheats.roll(block.number + delegationManager.withdrawalDelayBlocks());
148+
149+
// Complete withdrawals
150+
for (uint i = 0; i < withdrawals.length; i++) {
151+
IERC20[] memory tokens = staker.completeQueuedWithdrawal(withdrawals[i], true);
152+
uint[] memory expectedTokens = _calculateExpectedTokens(withdrawals[i].strategies, withdrawals[i].shares);
153+
assertWithdrawalAsTokensState(staker, withdrawals[i], strategies, shares, tokens, expectedTokens);
154+
}
155+
}
156+
157+
function testFuzz_deposit_delegate_reDelegate_withAdditionalDepositAfter(uint24 _random) public {
18158
// When new Users are created, they will choose a random configuration from these params:
19159
_configRand({
20160
_randomSeed: _random,

0 commit comments

Comments
 (0)