Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: custom errors passing #783

Merged
merged 11 commits into from
Sep 27, 2024
4 changes: 3 additions & 1 deletion script/deploy/mainnet/M2_Mainnet_Upgrade.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import "../../utils/ExistingDeploymentParser.sol";
import "../../utils/TimelockEncoding.sol";
import "../../utils/Multisend.sol";

import "../../../src/contracts/interfaces/IPausable.sol";

/**
* @notice Script used for the first deployment of EigenLayer core contracts to Holesky
* anvil --fork-url $RPC_MAINNET
Expand Down Expand Up @@ -292,7 +294,7 @@ contract Queue_M2_Upgrade is M2_Mainnet_Upgrade, TimelockEncoding {
// this works because rETH has more than 1 ETH of its own token at its address :)
IERC20(rETH).transfer(address(this), amount);
IERC20(rETH).approve(address(strategyManager), amount);
cheats.expectRevert("Pausable: index is paused");
cheats.expectRevert(IPausable.CurrentlyPaused.selector);
strategyManager.depositIntoStrategy({
strategy: IStrategy(rETH_Strategy),
token: IERC20(rETH),
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/core/DelegationManagerStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import "../interfaces/IEigenPodManager.sol";
* @author Layr Labs, Inc.
* @notice Terms of Service: https://docs.eigenlayer.xyz/overview/terms-of-service
* @notice This storage contract is separate from the logic to simplify the upgrade process.
*/
*/
abstract contract DelegationManagerStorage is IDelegationManager {
/// @notice The EIP-712 typehash for the contract's domain
bytes32 public constant DOMAIN_TYPEHASH =
Expand Down
18 changes: 8 additions & 10 deletions src/test/Delegation.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ contract DelegationTests is EigenLayerTestHelper {
}

if (expiry < block.timestamp) {
cheats.expectRevert("DelegationManager.delegateToBySignature: staker signature expired");
cheats.expectRevert(IDelegationManager.SignatureExpired.selector);
}
ISignatureUtils.SignatureWithExpiry memory signatureWithExpiry = ISignatureUtils.SignatureWithExpiry({
signature: signature,
Expand Down Expand Up @@ -258,9 +258,7 @@ contract DelegationTests is EigenLayerTestHelper {
signature = abi.encodePacked(r, s, v);
}

cheats.expectRevert(
bytes("EIP1271SignatureUtils.checkSignature_EIP1271: ERC1271 signature verification failed")
);
cheats.expectRevert(EIP1271SignatureUtils.InvalidSignatureEIP1271.selector);
ISignatureUtils.SignatureWithExpiry memory signatureWithExpiry = ISignatureUtils.SignatureWithExpiry({
signature: signature,
expiry: type(uint256).max
Expand Down Expand Up @@ -345,7 +343,7 @@ contract DelegationTests is EigenLayerTestHelper {
stakerOptOutWindowBlocks: 0
});
_testRegisterAsOperator(operator, operatorDetails);
cheats.expectRevert(bytes("DelegationManager.registerAsOperator: caller is already actively delegated"));
cheats.expectRevert(IDelegationManager.AlreadyDelegated.selector);
_testRegisterAsOperator(operator, operatorDetails);
}

Expand All @@ -356,7 +354,7 @@ contract DelegationTests is EigenLayerTestHelper {
_testDepositStrategies(getOperatorAddress(1), 1e18, 1);
_testDepositEigen(getOperatorAddress(1), 1e18);

cheats.expectRevert(bytes("DelegationManager.delegateTo: operator is not registered in EigenLayer"));
cheats.expectRevert(IDelegationManager.OperatorDoesNotExist.selector);
cheats.startPrank(getOperatorAddress(1));
ISignatureUtils.SignatureWithExpiry memory signatureWithExpiry;
delegation.delegateTo(delegate, signatureWithExpiry, bytes32(0));
Expand Down Expand Up @@ -394,7 +392,7 @@ contract DelegationTests is EigenLayerTestHelper {
});
string memory emptyStringForMetadataURI;
delegation.registerAsOperator(operatorDetails, emptyStringForMetadataURI);
vm.expectRevert("DelegationManager.registerAsOperator: caller is already actively delegated");
cheats.expectRevert(IDelegationManager.AlreadyDelegated.selector);
delegation.registerAsOperator(operatorDetails, emptyStringForMetadataURI);
cheats.stopPrank();
}
Expand All @@ -405,10 +403,10 @@ contract DelegationTests is EigenLayerTestHelper {
address _unregisteredoperator
) public fuzzedAddress(_staker) {
vm.startPrank(_staker);
cheats.expectRevert(bytes("DelegationManager.delegateTo: operator is not registered in EigenLayer"));
cheats.expectRevert(IDelegationManager.OperatorDoesNotExist.selector);
ISignatureUtils.SignatureWithExpiry memory signatureWithExpiry;
delegation.delegateTo(_unregisteredoperator, signatureWithExpiry, bytes32(0));
cheats.expectRevert(bytes("DelegationManager.delegateTo: operator is not registered in EigenLayer"));
cheats.expectRevert(IDelegationManager.OperatorDoesNotExist.selector);
delegation.delegateTo(_staker, signatureWithExpiry, bytes32(0));
cheats.stopPrank();
}
Expand Down Expand Up @@ -436,7 +434,7 @@ contract DelegationTests is EigenLayerTestHelper {

// operators cannot undelegate from themselves
vm.prank(_operator);
cheats.expectRevert(bytes("DelegationManager.undelegate: operators cannot be undelegated"));
cheats.expectRevert(IDelegationManager.OperatorsCannotUndelegate.selector);
delegation.undelegate(_operator);

// assert still delegated
Expand Down
4 changes: 2 additions & 2 deletions src/test/DepositWithdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ contract DepositWithdrawTests is EigenLayerTestHelper {
strategyManager.addStrategiesToDepositWhitelist(_strategy, _thirdPartyTransfersForbiddenValues);
cheats.stopPrank();

cheats.expectRevert(bytes("StrategyBase.deposit: Can only deposit underlyingToken"));
cheats.expectRevert(IStrategy.OnlyUnderlyingToken.selector);
strategyManager.depositIntoStrategy(wethStrat, token, 10);
}

Expand Down Expand Up @@ -108,7 +108,7 @@ contract DepositWithdrawTests is EigenLayerTestHelper {
strategyManager.addStrategiesToDepositWhitelist(_strategy, _thirdPartyTransfersForbiddenValues);
cheats.stopPrank();

cheats.expectRevert(bytes("StrategyBase.deposit: newShares cannot be zero"));
cheats.expectRevert(IStrategy.NewSharesZero.selector);
strategyManager.depositIntoStrategy(wethStrat, weth, 0);
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/Pausable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ contract PausableTests is EigenLayerTestHelper {
{
cheats.assume(!eigenLayerPauserReg.isPauser(unauthorizedPauser));
cheats.startPrank(unauthorizedPauser);
cheats.expectRevert(bytes("msg.sender is not permissioned as pauser"));
cheats.expectRevert(IPausable.OnlyPauser.selector);
strategyManager.pause(type(uint256).max);
cheats.stopPrank();
}
Expand All @@ -64,7 +64,7 @@ contract PausableTests is EigenLayerTestHelper {
{
cheats.assume(fakePauser != eigenLayerPauserReg.unpauser());
cheats.startPrank(fakePauser);
cheats.expectRevert(bytes("msg.sender is not permissioned as unpauser"));
cheats.expectRevert(IPausable.OnlyUnpauser.selector);
eigenLayerPauserReg.setIsPauser(newPauser, true);
cheats.stopPrank();
}
Expand All @@ -84,7 +84,7 @@ contract PausableTests is EigenLayerTestHelper {
cheats.assume(notUnpauser != eigenLayerPauserReg.unpauser());

cheats.prank(notUnpauser);
cheats.expectRevert(bytes("msg.sender is not permissioned as unpauser"));
cheats.expectRevert(IPausable.OnlyUnpauser.selector);
strategyManager.setPauserRegistry(newPauserRegistry);
}
}
9 changes: 3 additions & 6 deletions src/test/Strategy.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ contract StrategyTests is EigenLayerTestHelper {
IERC20 underlyingToken = wethStrat.underlyingToken();

cheats.startPrank(invalidDepositor);
cheats.expectRevert(bytes("StrategyBase.onlyStrategyManager"));
cheats.expectRevert(IStrategy.UnauthorizedCaller.selector);
wethStrat.deposit(underlyingToken, 1e18);
cheats.stopPrank();
}
Expand All @@ -34,7 +34,7 @@ contract StrategyTests is EigenLayerTestHelper {
IERC20 underlyingToken = wethStrat.underlyingToken();

cheats.startPrank(invalidWithdrawer);
cheats.expectRevert(bytes("StrategyBase.onlyStrategyManager"));
cheats.expectRevert(IStrategy.UnauthorizedCaller.selector);
wethStrat.withdraw(depositor, underlyingToken, 1e18);
cheats.stopPrank();
}
Expand All @@ -47,10 +47,7 @@ contract StrategyTests is EigenLayerTestHelper {
IERC20 underlyingToken = wethStrat.underlyingToken();

cheats.startPrank(address(strategyManager));

cheats.expectRevert(
bytes("StrategyBase.withdraw: amountShares must be less than or equal to totalShares")
);
cheats.expectRevert(IStrategy.WithdrawalAmountExceedsTotalDeposits.selector);
wethStrat.withdraw(depositor, underlyingToken, shares);

cheats.stopPrank();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ contract Integration_VerifyWC_StartCP_CompleteCP is IntegrationCheckUtils {
staker.verifyWithdrawalCredentials(validators);
check_VerifyWC_State(staker, validators, beaconBalanceGwei);

cheats.expectRevert("EigenPod._verifyWithdrawalCredentials: validator must be inactive to prove withdrawal credentials");
cheats.expectRevert(IEigenPod.CredentialsAlreadyVerified.selector);
staker.verifyWithdrawalCredentials(validators);
}

Expand All @@ -132,7 +132,7 @@ contract Integration_VerifyWC_StartCP_CompleteCP is IntegrationCheckUtils {
staker.startCheckpoint();
check_StartCheckpoint_State(staker);

cheats.expectRevert("EigenPod._startCheckpoint: must finish previous checkpoint before starting another");
cheats.expectRevert(IEigenPod.CheckpointAlreadyActive.selector);
staker.startCheckpoint();
}

Expand All @@ -157,7 +157,7 @@ contract Integration_VerifyWC_StartCP_CompleteCP is IntegrationCheckUtils {
staker.completeCheckpoint();
check_CompleteCheckpoint_State(staker);

cheats.expectRevert("EigenPod._startCheckpoint: cannot checkpoint twice in one block");
cheats.expectRevert(IEigenPod.CannotCheckpointTwiceInSingleBlock.selector);
staker.startCheckpoint();
}

Expand Down Expand Up @@ -227,7 +227,7 @@ contract Integration_VerifyWC_StartCP_CompleteCP is IntegrationCheckUtils {
staker.exitValidators(validators);
beaconChain.advanceEpoch_NoRewards();

cheats.expectRevert("EigenPod._verifyWithdrawalCredentials: validator must not be exiting");
cheats.expectRevert(IEigenPod.ValidatorIsExitingBeaconChain.selector);
staker.verifyWithdrawalCredentials(validators);
}

Expand Down Expand Up @@ -312,7 +312,7 @@ contract Integration_VerifyWC_StartCP_CompleteCP is IntegrationCheckUtils {
// Advance epoch, withdrawing slashed validators to pod
beaconChain.advanceEpoch_NoRewards();

cheats.expectRevert("EigenPod._verifyWithdrawalCredentials: validator must not be exiting");
cheats.expectRevert(IEigenPod.ValidatorIsExitingBeaconChain.selector);
staker.verifyWithdrawalCredentials(validators);
}

Expand Down
78 changes: 40 additions & 38 deletions src/test/unit/AVSDirectoryUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ contract AVSDirectoryUnitTests_operatorAVSRegisterationStatus is AVSDirectoryUni
cheats.prank(pauser);
avsDirectory.pause(2 ** PAUSED_OPERATOR_REGISTER_DEREGISTER_TO_AVS);

cheats.expectRevert("Pausable: index is paused");
cheats.expectRevert(IPausable.CurrentlyPaused.selector);
avsDirectory.registerOperatorToAVS(address(0), ISignatureUtils.SignatureWithSaltAndExpiry(abi.encodePacked(""), 0, 0));

cheats.expectRevert("Pausable: index is paused");
cheats.expectRevert(IPausable.CurrentlyPaused.selector);
avsDirectory.deregisterOperatorFromAVS(address(0));
}

Expand Down Expand Up @@ -222,7 +222,7 @@ contract AVSDirectoryUnitTests_operatorAVSRegisterationStatus is AVSDirectoryUni
ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature =
_getOperatorSignature(delegationSignerPrivateKey, operator, defaultAVS, salt, expiry);

cheats.expectRevert("AVSDirectory.registerOperatorToAVS: operator not registered to EigenLayer yet");
cheats.expectRevert(IAVSDirectory.OperatorDoesNotExist.selector);
avsDirectory.registerOperatorToAVS(operator, operatorSignature);
}

Expand All @@ -236,7 +236,7 @@ contract AVSDirectoryUnitTests_operatorAVSRegisterationStatus is AVSDirectoryUni
ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature =
_getOperatorSignature(delegationSignerPrivateKey, operator, defaultAVS, salt, expiry);

cheats.expectRevert("EIP1271SignatureUtils.checkSignature_EIP1271: signature not from signer");
cheats.expectRevert(EIP1271SignatureUtils.InvalidSignatureEOA.selector);
cheats.prank(operator);
avsDirectory.registerOperatorToAVS(operator, operatorSignature);
}
Expand All @@ -248,7 +248,7 @@ contract AVSDirectoryUnitTests_operatorAVSRegisterationStatus is AVSDirectoryUni
address operator = cheats.addr(delegationSignerPrivateKey);
operatorSignature.expiry = bound(operatorSignature.expiry, 0, block.timestamp - 1);

cheats.expectRevert("AVSDirectory.registerOperatorToAVS: operator signature expired");
cheats.expectRevert(IAVSDirectory.SignatureExpired.selector);
avsDirectory.registerOperatorToAVS(operator, operatorSignature);
}

Expand All @@ -265,7 +265,7 @@ contract AVSDirectoryUnitTests_operatorAVSRegisterationStatus is AVSDirectoryUni
cheats.startPrank(defaultAVS);
avsDirectory.registerOperatorToAVS(operator, operatorSignature);

cheats.expectRevert("AVSDirectory.registerOperatorToAVS: operator already registered");
cheats.expectRevert(IAVSDirectory.OperatorAlreadyRegistered.selector);
avsDirectory.registerOperatorToAVS(operator, operatorSignature);
cheats.stopPrank();
}
Expand Down Expand Up @@ -310,40 +310,42 @@ contract AVSDirectoryUnitTests_operatorAVSRegisterationStatus is AVSDirectoryUni
cheats.prank(operator);
avsDirectory.cancelSalt(salt);

cheats.expectRevert("AVSDirectory.registerOperatorToAVS: salt already spent");
cheats.expectRevert(IAVSDirectory.SignatureSaltSpent.selector);
cheats.prank(defaultAVS);
avsDirectory.registerOperatorToAVS(operator, operatorSignature);
}

/// @notice Verifies that an operator cannot cancel the same salt twice
function testFuzz_revert_whenSaltCancelledTwice(bytes32 salt) public {
address operator = cheats.addr(delegationSignerPrivateKey);
assertFalse(delegationManager.isOperator(operator), "bad test setup");
_registerOperatorWithBaseDetails(operator);

cheats.startPrank(operator);
avsDirectory.cancelSalt(salt);

cheats.expectRevert("AVSDirectory.cancelSalt: cannot cancel spent salt");
avsDirectory.cancelSalt(salt);
cheats.stopPrank();
}

/// @notice Verifies that an operator cannot cancel the same salt twice
function testFuzz_revert_whenCancellingSaltUsedToRegister(bytes32 salt) public {
address operator = cheats.addr(delegationSignerPrivateKey);
assertFalse(delegationManager.isOperator(operator), "bad test setup");
_registerOperatorWithBaseDetails(operator);

uint256 expiry = type(uint256).max;
ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature =
_getOperatorSignature(delegationSignerPrivateKey, operator, defaultAVS, salt, expiry);

cheats.prank(defaultAVS);
avsDirectory.registerOperatorToAVS(operator, operatorSignature);

cheats.prank(operator);
cheats.expectRevert("AVSDirectory.cancelSalt: cannot cancel spent salt");
avsDirectory.cancelSalt(salt);
}
// NOTE: This check was removed.
// /// @notice Verifies that an operator cannot cancel the same salt twice
// function testFuzz_revert_whenSaltCancelledTwice(bytes32 salt) public {
// address operator = cheats.addr(delegationSignerPrivateKey);
// assertFalse(delegationManager.isOperator(operator), "bad test setup");
// _registerOperatorWithBaseDetails(operator);

// cheats.startPrank(operator);
// avsDirectory.cancelSalt(salt);

// cheats.expectRevert(IAVSDirectory.SignatureSaltSpent.selector);
// avsDirectory.cancelSalt(salt);
// cheats.stopPrank();
// }

// NOTE: This check was removed.
// /// @notice Verifies that an operator cannot cancel the same salt twice
// function testFuzz_revert_whenCancellingSaltUsedToRegister(bytes32 salt) public {
// address operator = cheats.addr(delegationSignerPrivateKey);
// assertFalse(delegationManager.isOperator(operator), "bad test setup");
// _registerOperatorWithBaseDetails(operator);

// uint256 expiry = type(uint256).max;
// ISignatureUtils.SignatureWithSaltAndExpiry memory operatorSignature =
// _getOperatorSignature(delegationSignerPrivateKey, operator, defaultAVS, salt, expiry);

// cheats.prank(defaultAVS);
// avsDirectory.registerOperatorToAVS(operator, operatorSignature);

// cheats.prank(operator);
// cheats.expectRevert(IAVSDirectory.SignatureSaltSpent.selector);
// avsDirectory.cancelSalt(salt);
// }
}
Loading
Loading