Skip to content

Commit

Permalink
Remove tests that were failing due to deleted slasher checks, and fix…
Browse files Browse the repository at this point in the history
…ed broken EigenPod test
  • Loading branch information
wadealexc committed Oct 13, 2023
1 parent 4a5ca56 commit 9b1509d
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 141 deletions.
28 changes: 1 addition & 27 deletions src/test/DepositWithdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -135,33 +135,7 @@ contract DepositWithdrawTests is EigenLayerTestHelper {
cheats.stopPrank();
//check middlewareTimes entry is correct
require(slasher.getMiddlewareTimesIndexStalestUpdateBlock(staker, 4) == 3, "middleware updateBlock update incorrect");
require(slasher.getMiddlewareTimesIndexServeUntilBlock(staker, 4) == 10, "middleware serveUntil update incorrect");

//move timestamp to 6, one middleware is past newServeUntilBlock but the second middleware is still using the restaked funds.
cheats.warp(8);
//Also move the current block ahead one
cheats.roll(4);

cheats.startPrank(staker);
//when called with the correct middlewareTimesIndex the call reverts

slasher.getMiddlewareTimesIndexStalestUpdateBlock(staker, 3);


{
uint256 correctMiddlewareTimesIndex = 4;
cheats.expectRevert("DelegationManager.completeQueuedAction: pending action is still slashable");
delegation.completeQueuedWithdrawal(queuedWithdrawal, tokensArray, correctMiddlewareTimesIndex, false);
}

//When called with a stale index the call should also revert.
{
uint256 staleMiddlewareTimesIndex = 2;
cheats.expectRevert("DelegationManager.completeQueuedAction: pending action is still slashable");
delegation.completeQueuedWithdrawal(queuedWithdrawal, tokensArray, staleMiddlewareTimesIndex, false);
}


require(slasher.getMiddlewareTimesIndexServeUntilBlock(staker, 4) == 10, "middleware serveUntil update incorrect");
}


Expand Down
6 changes: 0 additions & 6 deletions src/test/EigenPod.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -701,17 +701,11 @@ contract EigenPodTests is ProofParsing, EigenPodPausingConstants {
// // validator status should be marked as ACTIVE

function testProveSingleWithdrawalCredential() public {
// get beaconChainETH shares
int256 beaconChainETHBefore = eigenPodManager.podOwnerShares(podOwner);

// ./solidityProofGen "ValidatorFieldsProof" 302913 true "data/withdrawal_proof_goerli/goerli_block_header_6399998.json" "data/withdrawal_proof_goerli/goerli_slot_6399998.json" "withdrawal_credential_proof_302913.json" setJSON("./src/test/test-data/withdrawal_credential_proof_302913.json");
setJSON("./src/test/test-data/withdrawal_credential_proof_302913.json");
IEigenPod pod = _testDeployAndVerifyNewEigenPod(podOwner, signature, depositDataRoot);
bytes32 validatorPubkeyHash = getValidatorPubkeyHash();


int256 beaconChainETHAfter = eigenPodManager.podOwnerShares(pod.podOwner());
assertTrue(beaconChainETHAfter - beaconChainETHBefore == int256(_calculateRestakedBalanceGwei(pod.MAX_RESTAKED_BALANCE_GWEI_PER_VALIDATOR())*GWEI_TO_WEI), "pod balance not updated correcty");
assertTrue(pod.validatorStatus(validatorPubkeyHash) == IEigenPod.VALIDATOR_STATUS.ACTIVE, "wrong validator status");
}

Expand Down
57 changes: 0 additions & 57 deletions src/test/unit/DelegationUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1196,27 +1196,6 @@ contract DelegationUnitTests is EigenLayerTestHelper {
delegationManager.decreaseDelegatedShares(operator, strategy, shares);
}

// @notice Verifies that it is not possible for a staker to delegate to an operator when the operator is frozen in EigenLayer
function testCannotDelegateWhenOperatorIsFrozen(address operator, address staker) public fuzzedAddress(operator) fuzzedAddress(staker) {
cheats.assume(operator != staker);

cheats.startPrank(operator);
IDelegationManager.OperatorDetails memory operatorDetails = IDelegationManager.OperatorDetails({
earningsReceiver: operator,
delegationApprover: address(0),
stakerOptOutWindowBlocks: 0
});
delegationManager.registerAsOperator(operatorDetails, emptyStringForMetadataURI);
cheats.stopPrank();

slasherMock.setOperatorFrozenStatus(operator, true);
cheats.expectRevert(bytes("DelegationManager._delegate: cannot delegate to a frozen operator"));
cheats.startPrank(staker);
IDelegationManager.SignatureWithExpiry memory signatureWithExpiry;
delegationManager.delegateTo(operator, signatureWithExpiry, emptySalt);
cheats.stopPrank();
}

// @notice Verifies that it is not possible for a staker to delegate to an operator when they are already delegated to an operator
function testCannotDelegateWhenStakerHasExistingDelegation(address staker, address operator, address operator2) public
fuzzedAddress(staker)
Expand Down Expand Up @@ -1748,42 +1727,6 @@ contract DelegationUnitTests is EigenLayerTestHelper {
delegationManager.completeQueuedWithdrawal(withdrawal, tokensArray, middlewareTimesIndex, receiveAsTokens);
}

function testCompleteQueuedWithdrawalRevertsWhenCanWithdrawReturnsFalse(
uint256 depositAmount,
uint256 withdrawalAmount
) external {
cheats.assume(withdrawalAmount != 0 && withdrawalAmount <= depositAmount);
_tempStakerStorage = address(this);

(
IDelegationManager.Withdrawal memory withdrawal,
IERC20[] memory tokensArray,
) = testQueueWithdrawal_ToSelf(depositAmount, withdrawalAmount);

IStrategy strategy = withdrawal.strategies[0];
IERC20 token = tokensArray[0];

uint256 sharesBefore = strategyManager.stakerStrategyShares(address(this), strategy);
uint256 balanceBefore = token.balanceOf(address(_tempStakerStorage));

uint256 middlewareTimesIndex = 0;
bool receiveAsTokens = false;

// prepare mock
slasherMock.setCanWithdrawResponse(false);

cheats.expectRevert(
bytes("DelegationManager.completeQueuedAction: pending action is still slashable")
);
delegationManager.completeQueuedWithdrawal(withdrawal, tokensArray, middlewareTimesIndex, receiveAsTokens);

uint256 sharesAfter = strategyManager.stakerStrategyShares(address(this), strategy);
uint256 balanceAfter = token.balanceOf(address(_tempStakerStorage));

require(sharesAfter == sharesBefore, "sharesAfter != sharesBefore");
require(balanceAfter == balanceBefore, "balanceAfter != balanceBefore");
}

function testCompleteQueuedWithdrawalRevertsWhenNotCallingFromWithdrawerAddress(
uint256 depositAmount,
uint256 withdrawalAmount
Expand Down
51 changes: 0 additions & 51 deletions src/test/unit/StrategyManagerUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,6 @@ contract StrategyManagerUnitTests is Test, Utils {
strategyManager.depositIntoStrategy(dummyStrat, dummyToken, amount);
}

function testDepositIntoStrategyRevertsWhenStakerFrozen() public {
uint256 amount = 1e18;
address staker = address(this);

// freeze the staker
slasherMock.freezeOperator(staker);

cheats.expectRevert(
bytes("StrategyManager.onlyNotFrozen: staker has been frozen and may be subject to slashing")
);
strategyManager.depositIntoStrategy(dummyStrat, dummyToken, amount);
}

function testDepositIntoStrategyRevertsWhenReentering() public {
uint256 amount = 1e18;

Expand Down Expand Up @@ -416,44 +403,6 @@ contract StrategyManagerUnitTests is Test, Utils {
_depositIntoStrategyWithSignature(staker, 1e18, type(uint256).max, expectedRevertMessage);
}

function testDepositIntoStrategyWithSignatureRevertsWhenStakerFrozen() public {
address staker = cheats.addr(privateKey);
IStrategy strategy = dummyStrat;
IERC20 token = dummyToken;
uint256 amount = 1e18;

uint256 nonceBefore = strategyManager.nonces(staker);
uint256 expiry = type(uint256).max;
bytes memory signature;

{
bytes32 structHash = keccak256(
abi.encode(strategyManager.DEPOSIT_TYPEHASH(), strategy, token, amount, nonceBefore, expiry)
);
bytes32 digestHash = keccak256(abi.encodePacked("\x19\x01", strategyManager.domainSeparator(), structHash));

(uint8 v, bytes32 r, bytes32 s) = cheats.sign(privateKey, digestHash);

signature = abi.encodePacked(r, s, v);
}

uint256 sharesBefore = strategyManager.stakerStrategyShares(staker, strategy);

// freeze the staker
slasherMock.freezeOperator(staker);

cheats.expectRevert(
bytes("StrategyManager.onlyNotFrozen: staker has been frozen and may be subject to slashing")
);
strategyManager.depositIntoStrategyWithSignature(strategy, token, amount, staker, expiry, signature);

uint256 sharesAfter = strategyManager.stakerStrategyShares(staker, strategy);
uint256 nonceAfter = strategyManager.nonces(staker);

require(sharesAfter == sharesBefore, "sharesAfter != sharesBefore");
require(nonceAfter == nonceBefore, "nonceAfter != nonceBefore");
}

function testDepositIntoStrategyWithSignatureRevertsWhenReentering() public {
reenterer = new Reenterer();

Expand Down

0 comments on commit 9b1509d

Please sign in to comment.