Skip to content

Commit

Permalink
fix: flaky integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ypatil12 committed Jan 2, 2024
1 parent d86d626 commit ea3fa5c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/test/integration/IntegrationChecks.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ contract IntegrationCheckUtils is IntegrationBase {
// ... check that each withdrawal was successfully enqueued, that the returned roots
// match the hashes of each withdrawal, and that the staker and operator have
// reduced shares.
assertEq(withdrawalRoots.length, 1, "check_QueuedWithdrawal_State: should only have 1 withdrawal root after queueing");
assert_AllWithdrawalsPending(withdrawalRoots,
"check_QueuedWithdrawal_State: staker withdrawals should now be pending");
assert_ValidWithdrawalHashes(withdrawals, withdrawalRoots,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ contract Integration_Deposit_Delegate_Redelegate_Complete is IntegrationCheckUti
// 4. Complete withdrawal as shares
// Fast forward to when we can complete the withdrawal
cheats.roll(block.number + delegationManager.withdrawalDelayBlocks());
staker.completeWithdrawalAsShares(withdrawals[0]);

check_Withdrawal_AsShares_Undelegated_State(staker, operator1, withdrawals[0], strategies, shares);
for (uint256 i = 0; i < withdrawals.length; ++i) {
staker.completeWithdrawalAsShares(withdrawals[i]);
check_Withdrawal_AsShares_Undelegated_State(staker, operator1, withdrawals[i], withdrawals[i].strategies, withdrawals[i].shares);
}

// 5. Delegate to a new operator
staker.delegateTo(operator2);
Expand Down Expand Up @@ -207,8 +208,10 @@ contract Integration_Deposit_Delegate_Redelegate_Complete is IntegrationCheckUti
// 4. Complete withdrawal as shares
// Fast forward to when we can complete the withdrawal
cheats.roll(block.number + delegationManager.withdrawalDelayBlocks());
staker.completeWithdrawalAsShares(withdrawals[0]);
check_Withdrawal_AsShares_Undelegated_State(staker, operator1, withdrawals[0], strategies, halfShares);
for (uint256 i = 0; i < withdrawals.length; ++i) {
staker.completeWithdrawalAsShares(withdrawals[i]);
check_Withdrawal_AsShares_Undelegated_State(staker, operator1, withdrawals[i], withdrawals[i].strategies, withdrawals[i].shares);
}

// 5. Delegate to a new operator
staker.delegateTo(operator2);
Expand Down Expand Up @@ -292,8 +295,10 @@ contract Integration_Deposit_Delegate_Redelegate_Complete is IntegrationCheckUti
// 4. Complete withdrawal as shares
// Fast forward to when we can complete the withdrawal
cheats.roll(block.number + delegationManager.withdrawalDelayBlocks());
staker.completeWithdrawalAsShares(withdrawals[0]);
check_Withdrawal_AsShares_Undelegated_State(staker, operator1, withdrawals[0], strategies, halfShares);
for (uint256 i = 0; i < withdrawals.length; ++i) {
staker.completeWithdrawalAsShares(withdrawals[i]);
check_Withdrawal_AsShares_Undelegated_State(staker, operator1, withdrawals[i], withdrawals[i].strategies, withdrawals[i].shares);
}

// 5. Deposit into Strategies
uint[] memory sharesAdded = _calculateExpectedShares(strategies, numTokensRemaining);
Expand Down Expand Up @@ -359,12 +364,14 @@ contract Integration_Deposit_Delegate_Redelegate_Complete is IntegrationCheckUti
bytes32[] memory withdrawalRoots = _getWithdrawalHashes(withdrawals);
check_Undelegate_State(staker, operator1, withdrawals, withdrawalRoots, strategies, shares);

// 4. Complete withdrawal as shares
// 4. Complete withdrawal as tokens
// Fast forward to when we can complete the withdrawal
cheats.roll(block.number + delegationManager.withdrawalDelayBlocks());
uint[] memory expectedTokens = _calculateExpectedTokens(withdrawals[0].strategies, withdrawals[0].shares);
IERC20[] memory tokens = staker.completeWithdrawalAsTokens(withdrawals[0]);
check_Withdrawal_AsTokens_State(staker, operator1, withdrawals[0], strategies, shares, tokens, expectedTokens);
for (uint256 i = 0; i < withdrawals.length; ++i) {
uint[] memory expectedTokens = _calculateExpectedTokens(withdrawals[i].strategies, withdrawals[i].shares);
IERC20[] memory tokens = staker.completeWithdrawalAsTokens(withdrawals[i]);
check_Withdrawal_AsTokens_State(staker, operator1, withdrawals[i], withdrawals[i].strategies, withdrawals[i].shares, tokens, expectedTokens);
}

//5. Deposit into Strategies
staker.depositIntoEigenlayer(strategies, tokenBalances);
Expand All @@ -386,8 +393,8 @@ contract Integration_Deposit_Delegate_Redelegate_Complete is IntegrationCheckUti

// Complete withdrawals as tokens
for (uint i = 0; i < withdrawals.length; i++) {
expectedTokens = _calculateExpectedTokens(withdrawals[i].strategies, withdrawals[i].shares);
tokens = staker.completeWithdrawalAsTokens(withdrawals[i]);
uint[] memory expectedTokens = _calculateExpectedTokens(withdrawals[i].strategies, withdrawals[i].shares);
IERC20[] memory tokens = staker.completeWithdrawalAsTokens(withdrawals[i]);
check_Withdrawal_AsTokens_State(staker, operator2, withdrawals[i], strategies, shares, tokens, expectedTokens);
}
}
Expand Down Expand Up @@ -426,12 +433,14 @@ contract Integration_Deposit_Delegate_Redelegate_Complete is IntegrationCheckUti
bytes32[] memory withdrawalRoots = _getWithdrawalHashes(withdrawals);
check_Undelegate_State(staker, operator1, withdrawals, withdrawalRoots, strategies, shares);

// 4. Complete withdrawal as shares
// 4. Complete withdrawal as Tokens
// Fast forward to when we can complete the withdrawal
cheats.roll(block.number + delegationManager.withdrawalDelayBlocks());
uint[] memory expectedTokens = _calculateExpectedTokens(withdrawals[0].strategies, withdrawals[0].shares);
IERC20[] memory tokens = staker.completeWithdrawalAsTokens(withdrawals[0]);
check_Withdrawal_AsTokens_State(staker, operator1, withdrawals[0], strategies, shares, tokens, expectedTokens);
for (uint256 i = 0; i < withdrawals.length; ++i) {
uint[] memory expectedTokens = _calculateExpectedTokens(withdrawals[i].strategies, withdrawals[i].shares);
IERC20[] memory tokens = staker.completeWithdrawalAsTokens(withdrawals[i]);
check_Withdrawal_AsTokens_State(staker, operator1, withdrawals[i], withdrawals[i].strategies, withdrawals[i].shares, tokens, expectedTokens);
}

//5. Deposit into Strategies
staker.depositIntoEigenlayer(strategies, tokenBalances);
Expand All @@ -453,7 +462,6 @@ contract Integration_Deposit_Delegate_Redelegate_Complete is IntegrationCheckUti

// Complete withdrawals as shares
for (uint i = 0; i < withdrawals.length; i++) {
expectedTokens = _calculateExpectedTokens(withdrawals[i].strategies, withdrawals[i].shares);
staker.completeWithdrawalAsShares(withdrawals[i]);
check_Withdrawal_AsShares_State(staker, operator2, withdrawals[i], strategies, shares);
}
Expand Down

0 comments on commit ea3fa5c

Please sign in to comment.