Skip to content

Commit

Permalink
test: testDeregisterValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
shaspitz committed Jun 27, 2024
1 parent 2bf967c commit 092c1ad
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 20 deletions.
3 changes: 0 additions & 3 deletions contracts/contracts/interfaces/IMevCommitAVS.sol
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,6 @@ interface IMevCommitAVS {
/// @dev Unpauses the contract, restricted to contract owner.
function unpause() external;

/// @dev Checks if the provided validators are opted-in.
function areValidatorsOptedIn(bytes[] calldata valPubKeys) external view returns (bool[] memory);

/// @dev Checks if a validator is opted-in.
function isValidatorOptedIn(bytes calldata valPubKey) external view returns (bool);

Expand Down
20 changes: 3 additions & 17 deletions contracts/contracts/validator-registry/avs/MevCommitAVS.sol
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,6 @@ contract MevCommitAVS is IMevCommitAVS, MevCommitAVSStorage,
}

/// @dev Internal function to deregister a validator.
//
// TODO: confirm frozen validators cannot deregister
function _deregisterValidator(bytes calldata valPubKey) internal {
require(!validatorRegistrations[valPubKey].freezeHeight.exists, "frozen validator cannot deregister");
require(validatorRegistrations[valPubKey].deregRequestHeight.exists,
Expand All @@ -396,6 +394,9 @@ contract MevCommitAVS is IMevCommitAVS, MevCommitAVSStorage,
}

/// @dev Internal function to register an LST restaker.
/// @notice For UX purposes each chosen validator must be "opted-in" when an LST restaker first registers.
/// However a chosen validator may later become not "opted-in" as defined in _isValidatorOptedIn(),
/// which will affect rewards/points earned by the LST restaker.
function _registerLSTRestaker(bytes[] calldata chosenValidators) internal {
require(chosenValidators.length > 0, "LST restaker must choose at least one validator");
for (uint256 i = 0; i < chosenValidators.length; i++) {
Expand Down Expand Up @@ -428,8 +429,6 @@ contract MevCommitAVS is IMevCommitAVS, MevCommitAVSStorage,
}

/// @dev Internal function to deregister an LST restaker.
//
// TODO: Confirm a chosen validator being frozen does not affect an LST restaker being able to deregister.
function _deregisterLSTRestaker() internal {
LSTRestakerRegistrationInfo storage reg = lstRestakerRegistrations[msg.sender];
require(reg.deregRequestHeight.exists, "LST restaker must have requested deregistration");
Expand All @@ -449,10 +448,6 @@ contract MevCommitAVS is IMevCommitAVS, MevCommitAVSStorage,
}

/// @dev Internal function to unfreeze a validator.
//
// TODO: test scenario where validator was req deregistered before being frozen, and goes back to registerd after unfreeze.
// TODO: Also confirm the unfreeze fee is fully given to reciever and not contract.
// TODO: test multiple vals unfrozen in one tx.
function _unfreeze(bytes calldata valPubKey, uint256 feeToPay) internal {
require(validatorRegistrations[valPubKey].freezeHeight.exists, "validator must be frozen");
require(block.number >= validatorRegistrations[valPubKey].freezeHeight.blockHeight + unfreezePeriodBlocks,
Expand Down Expand Up @@ -554,15 +549,6 @@ contract MevCommitAVS is IMevCommitAVS, MevCommitAVSStorage,
return _getRestakeableStrategies();
}

/// @dev Checks if the provided validators are opted-in.
function areValidatorsOptedIn(bytes[] calldata valPubKeys) external view returns (bool[] memory) {
bool[] memory result = new bool[](valPubKeys.length);
for (uint256 i = 0; i < valPubKeys.length; i++) {
result[i] = _isValidatorOptedIn(valPubKeys[i]);
}
return result;
}

/// @dev Checks if a validator is opted-in.
function isValidatorOptedIn(bytes calldata valPubKey) external view returns (bool) {
return _isValidatorOptedIn(valPubKey);
Expand Down
91 changes: 91 additions & 0 deletions contracts/test/validator-registry/avs/MevCommitAVSTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,95 @@ contract MevCommitAVSTest is Test {
vm.prank(podOwner);
mevCommitAVS.requestValidatorsDeregistration(valPubkeys);
}

function testDeregisterValidator() public {

address operator = address(0x888);
address podOwner = address(0x420);
bytes[] memory valPubkeys = new bytes[](1);
valPubkeys[0] = bytes("valPubkey1");
vm.expectRevert("validator must be registered");
vm.prank(podOwner);
mevCommitAVS.deregisterValidators(valPubkeys);

testRegisterValidatorsByPodOwners();

address otherAcct = address(0x777);
vm.expectRevert("sender must be podOwner or delegated operator of validator");
vm.prank(otherAcct);
mevCommitAVS.deregisterValidators(valPubkeys);

vm.expectRevert("validator must have requested deregistration");
vm.prank(podOwner);
mevCommitAVS.deregisterValidators(valPubkeys);

bytes[] memory valPubkeys2 = new bytes[](2);
valPubkeys2[0] = bytes("valPubkey1");
valPubkeys2[1] = bytes("valPubkey2");
vm.prank(podOwner);
mevCommitAVS.requestValidatorsDeregistration(valPubkeys2);

IMevCommitAVS.ValidatorRegistrationInfo memory regInfo0 = mevCommitAVS.getValidatorRegInfo(valPubkeys2[0]);
IMevCommitAVS.ValidatorRegistrationInfo memory regInfo1 = mevCommitAVS.getValidatorRegInfo(valPubkeys2[1]);
assertTrue(regInfo0.deregRequestHeight.exists);
assertTrue(regInfo1.deregRequestHeight.exists);

vm.expectRevert("deregistration must happen at least validatorDeregPeriodBlocks after deregistration request height");
vm.prank(operator);
mevCommitAVS.deregisterValidators(valPubkeys2);

vm.roll(103 + validatorDeregPeriodBlocks);
vm.expectEmit(true, true, true, true);
emit ValidatorDeregistered(valPubkeys2[0], podOwner);
vm.expectEmit(true, true, true, true);
emit ValidatorDeregistered(valPubkeys2[1], podOwner);
vm.prank(operator);
mevCommitAVS.deregisterValidators(valPubkeys2);

regInfo0 = mevCommitAVS.getValidatorRegInfo(valPubkeys2[0]);
regInfo1 = mevCommitAVS.getValidatorRegInfo(valPubkeys2[1]);
assertFalse(regInfo0.exists);
assertFalse(regInfo1.exists);
}

// TODO: test that LST restakers cannot choose validators who're not registered / valid with eigen core
function testRegisterLSTRestaker() public {
}

function testRequestLSTRestakerDeregistration() public {
}

function testDeregisterLSTRestaker() public {
}


function testFreeze() public {
// TODO: test multiple vals frozen in one tx.
}

function testFrozenValidatorsCantDeregister() public {
// TODO:
}

function testFrozenValidatorDoesntAffectLSTRestakerDeregistration() public {
// TODO: Confirm a chosen validator being frozen does not affect an LST restaker being able to deregister.
}

function testUnfreeze() public {
// TODO: test scenario where validator was req deregistered before being frozen, and goes back to registerd after unfreeze.
// TODO: Also confirm the unfreeze fee is fully given to reciever and not contract.
// TODO: test multiple vals unfrozen in one tx.
}

function testPause() public {
// TODO: list out all funcs that are affected
}

function testUnpause() public {
// TODO: list out all funcs that are affected
}

function testSetters() public {
// only owner for all
}
}

0 comments on commit 092c1ad

Please sign in to comment.