Skip to content

Commit

Permalink
test: add UAM to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ypatil12 committed Nov 11, 2024
1 parent 2e24315 commit 6ef26fa
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 48 deletions.
21 changes: 0 additions & 21 deletions src/test/mocks/PermissionControllerMock.sol

This file was deleted.

36 changes: 32 additions & 4 deletions src/test/unit/AllocationManagerUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ contract AllocationManagerUnitTests is EigenLayerUnitTestSetup, IAllocationManag
new AllocationManager(
IDelegationManager(address(delegationManagerMock)),
_pauserRegistry,
IPermissionController(address(permissionControllerMock)),
IPermissionController(address(permissionController)),
DEALLOCATION_DELAY,
ALLOCATION_CONFIGURATION_DELAY
)
Expand Down Expand Up @@ -1321,6 +1321,12 @@ contract AllocationManagerUnitTests_ModifyAllocations is AllocationManagerUnitTe
allocationManager.modifyAllocations(address(this), new AllocateParams[](0));
}

function test_revert_invalidCaller() public {
address invalidOperator = address(0x2);
cheats.expectRevert(InvalidCaller.selector);
allocationManager.modifyAllocations(invalidOperator, new AllocateParams[](0));
}

function test_revert_allocationDelayNotSet() public {
address invalidOperator = address(0x2);
cheats.prank(invalidOperator);
Expand Down Expand Up @@ -2557,6 +2563,11 @@ contract AllocationManagerUnitTests_SetAllocationDelay is AllocationManagerUnitT
allocationManager.setAllocationDelay(operatorToSet, 1);
}

function test_revert_callerNotAuthorized() public {
cheats.expectRevert(InvalidCaller.selector);
allocationManager.setAllocationDelay(operatorToSet, 1);
}

function testFuzz_setDelay(
Randomness r
) public rand(r) {
Expand Down Expand Up @@ -2679,12 +2690,13 @@ contract AllocationManagerUnitTests_registerForOperatorSets is AllocationManager
allocationManager.registerForOperatorSets(defaultOperator, defaultRegisterParams);
}

function testFuzz_registerForOperatorSets_InvalidOperator(
function testFuzz_registerForOperatorSets_InvalidOperator_x(
Randomness r
) public rand(r) {
cheats.prank(r.Address());
address operator = r.Address();
cheats.prank(operator);
cheats.expectRevert(InvalidOperator.selector);
allocationManager.registerForOperatorSets(r.Address(), defaultRegisterParams);
allocationManager.registerForOperatorSets(operator, defaultRegisterParams);
}

function testFuzz_registerForOperatorSets_InvalidOperatorSet(
Expand Down Expand Up @@ -2763,6 +2775,22 @@ contract AllocationManagerUnitTests_deregisterFromOperatorSets is AllocationMana
allocationManager.deregisterFromOperatorSets(defaultDeregisterParams);
}

function test_deregisterFromOperatorSets_revert_invalidCaller_notOperator() public {
address randomOperator = address(0x1);
defaultDeregisterParams.operator = randomOperator;

cheats.expectRevert(InvalidCaller.selector);
allocationManager.deregisterFromOperatorSets(defaultDeregisterParams);
}

function test_deregisterFromOperatorSets_revert_invalidCaller_notAVS() public {
address randomAVS = address(0x1);

cheats.prank(randomAVS);
cheats.expectRevert(InvalidCaller.selector);
allocationManager.deregisterFromOperatorSets(defaultDeregisterParams);
}

function testFuzz_deregisterFromOperatorSets_InvalidOperatorSet(
Randomness r
) public rand(r) {
Expand Down
67 changes: 64 additions & 3 deletions src/test/unit/DelegationUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ contract DelegationManagerUnitTests is EigenLayerUnitTestSetup, IDelegationManag
IEigenPodManager(address(eigenPodManagerMock)),
IAllocationManager(address(allocationManagerMock)),
pauserRegistry,
IPermissionController(address(permissionControllerMock)),
IPermissionController(address(permissionController)),
MIN_WITHDRAWAL_DELAY_BLOCKS
);

Expand Down Expand Up @@ -666,6 +666,44 @@ contract DelegationManagerUnitTests_RegisterModifyOperator is DelegationManagerU
emit OperatorMetadataURIUpdated(defaultOperator, metadataURI);
delegationManager.updateOperatorMetadataURI(defaultOperator, metadataURI);
}

function testFuzz_UAM_modifyOperatorDetails(
OperatorDetails memory operatorDetails
) public {
// Set admin
cheats.prank(defaultOperator);
permissionController.setDelegate(
defaultOperator,
address(this),
address(delegationManager),
IDelegationManager.modifyOperatorDetails.selector
);

_registerOperatorWithBaseDetails(defaultOperator);

// Modify operator details
cheats.expectEmit(true, true, true, true, address(delegationManager));
emit OperatorDetailsModified(defaultOperator, operatorDetails);
delegationManager.modifyOperatorDetails(defaultOperator, operatorDetails);
}

function testFuzz_UAM_updateOperatorMetadataURI(string memory metadataURI) public {
// Set admin
cheats.prank(defaultOperator);
permissionController.setDelegate(
defaultOperator,
address(this),
address(delegationManager),
IDelegationManager.updateOperatorMetadataURI.selector
);

_registerOperatorWithBaseDetails(defaultOperator);

// call `updateOperatorMetadataURI` and check for event
cheats.expectEmit(true, true, true, true, address(delegationManager));
emit OperatorMetadataURIUpdated(defaultOperator, metadataURI);
delegationManager.updateOperatorMetadataURI(defaultOperator, metadataURI);
}
}

contract DelegationManagerUnitTests_delegateTo is DelegationManagerUnitTests {
Expand Down Expand Up @@ -2516,8 +2554,6 @@ contract DelegationManagerUnitTests_Undelegate is DelegationManagerUnitTests {
function testFuzz_undelegate_revert_invalidCaller(
address invalidCaller
) public filterFuzzedAddressInputs(invalidCaller) {
// Invalidate canCall on permissionController
permissionControllerMock.setCanCallResult(false);
address staker = address(0x123);
// filter out addresses that are actually allowed to call the function
cheats.assume(invalidCaller != staker);
Expand Down Expand Up @@ -2596,6 +2632,31 @@ contract DelegationManagerUnitTests_Undelegate is DelegationManagerUnitTests {
assertFalse(delegationManager.isDelegated(staker), "staker not undelegated");
}

function testFuzz_undelegate_UAM(address staker, bytes32 salt) public {
_registerOperatorWithBaseDetails(defaultOperator);
_delegateToOperatorWhoRequiresSig(staker, defaultOperator, salt);

// Set delegate
cheats.prank(defaultOperator);
permissionController.setDelegate(
defaultOperator,
address(this),
address(delegationManager),
IDelegationManager.undelegate.selector
);

// Undelegate
delegationManager.undelegate(staker);

// Checks
assertEq(
delegationManager.delegatedTo(staker),
address(0),
"undelegated staker should be delegated to zero address"
);
assertFalse(delegationManager.isDelegated(staker), "staker not undelegated");
}

/**
* @notice Verifies that the `undelegate` function properly queues a withdrawal for all shares of the staker
*/
Expand Down
16 changes: 1 addition & 15 deletions src/test/unit/PermissionControllerUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import "src/contracts/interfaces/IPermissionController.sol";
import "src/test/utils/EigenLayerUnitTestSetup.sol";

contract PermissionControllerUnitTests is EigenLayerUnitTestSetup, IPermissionControllerEvents, IPermissionControllerErrors {

PermissionController permissionController;
PermissionController permissionControllerImplementation;

address account = address(0x1);
address admin = address(0x2);
address admin2 = address(0x3);
Expand All @@ -25,19 +21,9 @@ contract PermissionControllerUnitTests is EigenLayerUnitTestSetup, IPermissionCo
bytes4 selector2 = IAllocationManager.modifyAllocations.selector;

function setUp() virtual public override {
// Setup
// Setup - already deploys permissionController
EigenLayerUnitTestSetup.setUp();

// Deploy PermissionController
permissionControllerImplementation = new PermissionController();
permissionController = PermissionController(address(new TransparentUpgradeableProxy(
address(permissionControllerImplementation),
address(eigenLayerProxyAdmin),
abi.encodeWithSelector(
PermissionController.initialize.selector
)
)));

// Set targets
target1 = address(delegationManagerMock);
target2 = address(allocationManagerMock);
Expand Down
2 changes: 1 addition & 1 deletion src/test/unit/RewardsCoordinatorUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ contract RewardsCoordinatorUnitTests is EigenLayerUnitTestSetup, IRewardsCoordin
IDelegationManager(address(delegationManagerMock)),
IStrategyManager(address(strategyManagerMock)),
pauserRegistry,
IPermissionController(address(permissionControllerMock)),
IPermissionController(address(permissionController)),
CALCULATION_INTERVAL_SECONDS,
MAX_REWARDS_DURATION,
MAX_RETROACTIVE_LENGTH,
Expand Down
17 changes: 13 additions & 4 deletions src/test/utils/EigenLayerUnitTestSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import "src/test/mocks/EmptyContract.sol";

import "src/test/utils/SingleItemArrayLib.sol";
import "src/test/utils/Random.sol";
import "src/test/mocks/PermissionControllerMock.sol";

import "src/test/utils/SingleItemArrayLib.sol";

Expand All @@ -36,8 +35,9 @@ abstract contract EigenLayerUnitTestSetup is Test {

PauserRegistry pauserRegistry;
ProxyAdmin eigenLayerProxyAdmin;
PermissionController permissionControllerImplementation;
PermissionController permissionController;

PermissionControllerMock permissionControllerMock;
AVSDirectoryMock avsDirectoryMock;
AllocationManagerMock allocationManagerMock;
StrategyManagerMock strategyManagerMock;
Expand Down Expand Up @@ -70,23 +70,32 @@ abstract contract EigenLayerUnitTestSetup is Test {
pauserRegistry = new PauserRegistry(pausers, unpauser);
eigenLayerProxyAdmin = new ProxyAdmin();

// Deploy permission controller
permissionControllerImplementation = new PermissionController();
permissionController = PermissionController(address(new TransparentUpgradeableProxy(
address(permissionControllerImplementation),
address(eigenLayerProxyAdmin),
abi.encodeWithSelector(
PermissionController.initialize.selector
)
)));

avsDirectoryMock = AVSDirectoryMock(payable(address(new AVSDirectoryMock())));
allocationManagerMock = AllocationManagerMock(payable(address(new AllocationManagerMock())));
strategyManagerMock = StrategyManagerMock(payable(address(new StrategyManagerMock(IDelegationManager(address(delegationManagerMock))))));
delegationManagerMock = DelegationManagerMock(payable(address(new DelegationManagerMock())));
eigenPodManagerMock = EigenPodManagerMock(payable(address(new EigenPodManagerMock(pauserRegistry))));
emptyContract = new EmptyContract();
permissionControllerMock = PermissionControllerMock(payable(address(new PermissionControllerMock())));


isExcludedFuzzAddress[address(0)] = true;
isExcludedFuzzAddress[address(pauserRegistry)] = true;
isExcludedFuzzAddress[address(permissionController)] = true;
isExcludedFuzzAddress[address(eigenLayerProxyAdmin)] = true;
isExcludedFuzzAddress[address(avsDirectoryMock)] = true;
isExcludedFuzzAddress[address(allocationManagerMock)] = true;
isExcludedFuzzAddress[address(strategyManagerMock)] = true;
isExcludedFuzzAddress[address(delegationManagerMock)] = true;
isExcludedFuzzAddress[address(eigenPodManagerMock)] = true;
isExcludedFuzzAddress[address(permissionControllerMock)] = true;
}
}

0 comments on commit 6ef26fa

Please sign in to comment.