diff --git a/src/test/integration/tests/Slashed_Eigenpod.t.sol b/src/test/integration/tests/Slashed_Eigenpod.t.sol index af338d948..5bd01ae74 100644 --- a/src/test/integration/tests/Slashed_Eigenpod.t.sol +++ b/src/test/integration/tests/Slashed_Eigenpod.t.sol @@ -134,72 +134,71 @@ contract Integration_SlashedEigenpod is IntegrationCheckUtils { assertApproxEqAbs(withdrawableSharesAfter[0], depositSharesAfter[0], 100, "Withdrawable shares should equal deposit shares after withdrawal"); } - // TODO: Fix this test - // function testFuzz_delegateSlashedStaker_slashedOperator(uint24 _random) public rand(_random) { - - - // (User staker2,,) = _newRandomStaker(); - // (uint40[] memory validators2,) = staker2.startValidators(); - // beaconChain.advanceEpoch_NoWithdrawNoRewards(); - // staker2.verifyWithdrawalCredentials(validators2); - // staker2.startCheckpoint(); - // staker2.completeCheckpoint(); - // staker2.delegateTo(operator); - - // //randomize additional deposit to eigenpod - // if(_randBool()){ - // uint amount = 32 ether * _randUint({min: 1, max: 5}); - // cheats.deal(address(staker), amount); - // (uint40[] memory validators,) = staker.startValidators(); - // beaconChain.advanceEpoch_NoWithdrawNoRewards(); - // staker.verifyWithdrawalCredentials(validators); + function testFuzz_delegateSlashedStaker_slashedOperator(uint24 _random) public rand(_random) { + + + (User staker2,,) = _newRandomStaker(); + (uint40[] memory validators2,) = staker2.startValidators(); + beaconChain.advanceEpoch_NoWithdrawNoRewards(); + staker2.verifyWithdrawalCredentials(validators2); + staker2.startCheckpoint(); + staker2.completeCheckpoint(); + staker2.delegateTo(operator); + + //randomize additional deposit to eigenpod + if(_randBool()){ + uint amount = 32 ether * _randUint({min: 1, max: 5}); + cheats.deal(address(staker), amount); + (uint40[] memory validators,) = staker.startValidators(); + beaconChain.advanceEpoch_NoWithdrawNoRewards(); + staker.verifyWithdrawalCredentials(validators); - // staker.startCheckpoint(); - // staker.completeCheckpoint(); - // } - - // // Create an operator set and register an operator. - // operatorSet = avs.createOperatorSet(strategies); - // operator.registerForOperatorSet(operatorSet); - // check_Registration_State_NoAllocation(operator, operatorSet, strategies); - - // // Allocate to operator set - // allocateParams = _genAllocation_AllAvailable(operator, operatorSet, strategies); - // operator.modifyAllocations(allocateParams); - // check_IncrAlloc_State_Slashable(operator, allocateParams); - // _rollBlocksForCompleteAllocation(operator, operatorSet, strategies); - - // //Slash operator before delegation - // IAllocationManagerTypes.SlashingParams memory slashingParams; - // uint wadToSlash = _randWadToSlash(); - // slashingParams = avs.slashOperator(operator, operatorSet.id, strategies, wadToSlash.toArrayU256()); - // assert_Snap_Allocations_Slashed(slashingParams, operatorSet, true, "operator allocations should be slashed"); - - // uint256[] memory initDelegatableShares = _getWithdrawableShares(staker, strategies); - // uint256[] memory initDepositShares = _getStakerDepositShares(staker, strategies); - - // // Delegate to an operator - // staker.delegateTo(operator); - // (uint256[] memory delegatedShares, ) = delegationManager.getWithdrawableShares(address(staker), strategies); - // check_Delegation_State(staker, operator, strategies, initDepositShares); + staker.startCheckpoint(); + staker.completeCheckpoint(); + } + + // Create an operator set and register an operator. + operatorSet = avs.createOperatorSet(strategies); + operator.registerForOperatorSet(operatorSet); + check_Registration_State_NoAllocation(operator, operatorSet, strategies); + + // Allocate to operator set + allocateParams = _genAllocation_AllAvailable(operator, operatorSet, strategies); + operator.modifyAllocations(allocateParams); + check_IncrAlloc_State_Slashable(operator, allocateParams); + _rollBlocksForCompleteAllocation(operator, operatorSet, strategies); + + //Slash operator before delegation + IAllocationManagerTypes.SlashingParams memory slashingParams; + uint wadToSlash = _randWadToSlash(); + slashingParams = avs.slashOperator(operator, operatorSet.id, strategies, wadToSlash.toArrayU256()); + assert_Snap_Allocations_Slashed(slashingParams, operatorSet, true, "operator allocations should be slashed"); + + uint256[] memory initDelegatableShares = _getWithdrawableShares(staker, strategies); + uint256[] memory initDepositShares = _getStakerDepositShares(staker, strategies); + + // Delegate to an operator + staker.delegateTo(operator); + (uint256[] memory delegatedShares, ) = delegationManager.getWithdrawableShares(address(staker), strategies); + check_Delegation_State(staker, operator, strategies, initDepositShares); - // // Undelegate from an operator - // IDelegationManagerTypes.Withdrawal[] memory withdrawals = staker.undelegate(); - // bytes32[] memory withdrawalRoots = _getWithdrawalHashes(withdrawals); - // check_Undelegate_State(staker, operator, withdrawals, withdrawalRoots, strategies, initDepositShares, delegatedShares); - - // // Complete withdrawal as shares - // // Fast forward to when we can complete the withdrawal - // _rollBlocksForCompleteWithdrawals(withdrawals); - // for (uint256 i = 0; i < withdrawals.length; ++i) { - // staker.completeWithdrawalAsShares(withdrawals[i]); - // check_Withdrawal_AsShares_Undelegated_State(staker, operator, withdrawals[i], withdrawals[i].strategies, delegatedShares); - // } - - // (uint256[] memory withdrawableSharesAfter, uint256[] memory depositSharesAfter) = delegationManager.getWithdrawableShares(address(staker), strategies); - // assertEq(depositSharesAfter[0], delegatedShares[0], "Deposit shares should reset to reflect slash(es)"); - // assertApproxEqAbs(withdrawableSharesAfter[0], depositSharesAfter[0], 100, "Withdrawable shares should equal deposit shares after withdrawal"); - // } + // Undelegate from an operator + IDelegationManagerTypes.Withdrawal[] memory withdrawals = staker.undelegate(); + bytes32[] memory withdrawalRoots = _getWithdrawalHashes(withdrawals); + check_Undelegate_State(staker, operator, withdrawals, withdrawalRoots, strategies, initDepositShares, delegatedShares); + + // Complete withdrawal as shares + // Fast forward to when we can complete the withdrawal + _rollBlocksForCompleteWithdrawals(withdrawals); + for (uint256 i = 0; i < withdrawals.length; ++i) { + staker.completeWithdrawalAsShares(withdrawals[i]); + check_Withdrawal_AsShares_Undelegated_State(staker, operator, withdrawals[i], withdrawals[i].strategies, delegatedShares); + } + + (uint256[] memory withdrawableSharesAfter, uint256[] memory depositSharesAfter) = delegationManager.getWithdrawableShares(address(staker), strategies); + assertEq(depositSharesAfter[0], delegatedShares[0], "Deposit shares should reset to reflect slash(es)"); + assertApproxEqAbs(withdrawableSharesAfter[0], depositSharesAfter[0], 100, "Withdrawable shares should equal deposit shares after withdrawal"); + } function testFuzz_delegateSlashedStaker_redelegate_complete(uint24 _random) public rand(_random){