Skip to content

Commit b29c5ea

Browse files
committed
test(wip): createOperatorDirectedOperatorSetRewardsSubmission
1 parent 37f4549 commit b29c5ea

File tree

2 files changed

+138
-25
lines changed

2 files changed

+138
-25
lines changed

test/mocks/AllocationManagerMock.sol

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
// SPDX-License-Identifier: BUSL-1.1
22
pragma solidity ^0.8.27;
33

4-
import {IAllocationManager, OperatorSet} from "eigenlayer-contracts/src/contracts/interfaces/IAllocationManager.sol";
4+
import {IAllocationManager, OperatorSet } from "eigenlayer-contracts/src/contracts/interfaces/IAllocationManager.sol";
5+
import {OperatorSetLib} from "eigenlayer-contracts/src/contracts/libraries/OperatorSetLib.sol";
6+
57
import {IAVSRegistrar } from "eigenlayer-contracts/src/contracts/interfaces/IAVSRegistrar.sol";
68
import {IStrategy} from "eigenlayer-contracts/src/contracts/interfaces/IStrategy.sol";
79
import {IPauserRegistry} from "eigenlayer-contracts/src/contracts/interfaces/IPauserRegistry.sol";
810
contract AllocationManagerIntermediate is IAllocationManager {
11+
using OperatorSetLib for OperatorSet;
12+
13+
14+
mapping(bytes32 => bool) internal _isOperatorSet;
15+
916
function initialize(
1017
address initialOwner,
1118
uint256 initialPausedStatus
@@ -139,7 +146,16 @@ contract AllocationManagerIntermediate is IAllocationManager {
139146

140147
function isOperatorSet(
141148
OperatorSet memory operatorSet
142-
) external view virtual returns (bool) {}
149+
) external view virtual returns (bool) {
150+
return _isOperatorSet[operatorSet.key()];
151+
}
152+
153+
function setIsOperatorSet(
154+
OperatorSet memory operatorSet,
155+
bool isSet
156+
) external virtual {
157+
_isOperatorSet[operatorSet.key()] = isSet;
158+
}
143159

144160
function getMembers(
145161
OperatorSet memory operatorSet

test/unit/ServiceManagerBase.t.sol

Lines changed: 120 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol";
55
import {
66
RewardsCoordinator,
77
IRewardsCoordinator,
8+
IRewardsCoordinatorErrors,
89
IRewardsCoordinatorTypes,
10+
OperatorSet,
911
IERC20
1012
} from "eigenlayer-contracts/src/contracts/core/RewardsCoordinator.sol";
13+
import {IAllocationManagerTypes} from "eigenlayer-contracts/src/contracts/interfaces/IAllocationManager.sol";
1114
import {PermissionController} from "eigenlayer-contracts/src/contracts/permissions/PermissionController.sol";
1215
import {StrategyBase} from "eigenlayer-contracts/src/contracts/strategies/StrategyBase.sol";
1316
import {IStrategyManager} from "eigenlayer-contracts/src/contracts/interfaces/IStrategyManager.sol";
@@ -40,8 +43,9 @@ contract ServiceManagerBase_UnitTests is MockAVSDeployer, IServiceManagerBaseEve
4043
IStrategy strategyMock1;
4144
IStrategy strategyMock2;
4245
IStrategy strategyMock3;
46+
IStrategy[] strategies;
4347
StrategyBase strategyImplementation;
44-
IRewardsCoordinator.StrategyAndMultiplier[] defaultStrategyAndMultipliers;
48+
IRewardsCoordinatorTypes.StrategyAndMultiplier[] defaultStrategyAndMultipliers;
4549

4650
// mapping to setting fuzzed inputs
4751
mapping(address => bool) public addressIsExcludedFromFuzzedInputs;
@@ -177,11 +181,14 @@ contract ServiceManagerBase_UnitTests is MockAVSDeployer, IServiceManagerBaseEve
177181
)
178182
)
179183
);
180-
IStrategy[] memory strategies = new IStrategy[](3);
181-
strategies[0] = strategyMock1;
182-
strategies[1] = strategyMock2;
183-
strategies[2] = strategyMock3;
184-
strategies = _sortArrayAsc(strategies);
184+
185+
IStrategy[] memory strats = new IStrategy[](3);
186+
strats[0] = strategyMock1;
187+
strats[1] = strategyMock2;
188+
strats[2] = strategyMock3;
189+
strats = _sortArrayAsc(strats);
190+
191+
strategies = strats;
185192

186193
strategyManagerMock.setStrategyWhitelist(strategies[0], true);
187194
strategyManagerMock.setStrategyWhitelist(strategies[1], true);
@@ -217,12 +224,29 @@ contract ServiceManagerBase_UnitTests is MockAVSDeployer, IServiceManagerBaseEve
217224
return timestamp1 > timestamp2 ? timestamp1 : timestamp2;
218225
}
219226

227+
// function test_setRewardsInitiator() public {
228+
// address newRewardsInitiator = address(uint160(uint256(keccak256("newRewardsInitiator"))));
229+
// cheats.prank(serviceManagerOwner);
230+
// serviceManager.setRewardsInitiator(newRewardsInitiator);
231+
// assertEq(newRewardsInitiator, serviceManager.rewardsInitiator());
232+
// }
233+
234+
// function test_setRewardsInitiator_revert_notOwner() public {
235+
// address caller = address(uint160(uint256(keccak256("caller"))));
236+
// address newRewardsInitiator = address(uint160(uint256(keccak256("newRewardsInitiator"))));
237+
// cheats.expectRevert("Ownable: caller is not the owner");
238+
// cheats.prank(caller);
239+
// serviceManager.setRewardsInitiator(newRewardsInitiator);
240+
// }
241+
}
242+
243+
contract ServiceManagerBase_createAVSRewardsSubmission_UnitTests is ServiceManagerBase_UnitTests {
220244
function testFuzz_createAVSRewardsSubmission_Revert_WhenNotOwner(address caller)
221245
public
222246
filterFuzzedAddressInputs(caller)
223247
{
224248
cheats.assume(caller != rewardsInitiator);
225-
IRewardsCoordinator.RewardsSubmission[] memory rewardsSubmissions;
249+
IRewardsCoordinatorTypes.RewardsSubmission[] memory rewardsSubmissions;
226250

227251
cheats.prank(caller);
228252
cheats.expectRevert(
@@ -337,8 +361,8 @@ contract ServiceManagerBase_UnitTests is MockAVSDeployer, IServiceManagerBaseEve
337361
cheats.assume(2 <= numSubmissions && numSubmissions <= 10);
338362
cheats.prank(rewardsCoordinator.owner());
339363

340-
IRewardsCoordinator.RewardsSubmission[] memory rewardsSubmissions =
341-
new IRewardsCoordinator.RewardsSubmission[](numSubmissions);
364+
IRewardsCoordinatorTypes.RewardsSubmission[] memory rewardsSubmissions =
365+
new IRewardsCoordinatorTypes.RewardsSubmission[](numSubmissions);
342366
bytes32[] memory avsSubmissionHashes = new bytes32[](numSubmissions);
343367
uint256 startSubmissionNonce = rewardsCoordinator.submissionNonce(address(serviceManager));
344368
_deployMockRewardTokens(rewardsInitiator, numSubmissions);
@@ -430,8 +454,8 @@ contract ServiceManagerBase_UnitTests is MockAVSDeployer, IServiceManagerBaseEve
430454
cheats.assume(2 <= numSubmissions && numSubmissions <= 10);
431455
cheats.prank(rewardsCoordinator.owner());
432456

433-
IRewardsCoordinator.RewardsSubmission[] memory rewardsSubmissions =
434-
new IRewardsCoordinator.RewardsSubmission[](numSubmissions);
457+
IRewardsCoordinatorTypes.RewardsSubmission[] memory rewardsSubmissions =
458+
new IRewardsCoordinatorTypes.RewardsSubmission[](numSubmissions);
435459
bytes32[] memory avsSubmissionHashes = new bytes32[](numSubmissions);
436460
uint256 startSubmissionNonce = rewardsCoordinator.submissionNonce(address(serviceManager));
437461
IERC20 rewardToken = new ERC20PresetFixedSupply(
@@ -518,19 +542,92 @@ contract ServiceManagerBase_UnitTests is MockAVSDeployer, IServiceManagerBaseEve
518542
);
519543
}
520544
}
545+
}
521546

522-
function test_setRewardsInitiator() public {
523-
address newRewardsInitiator = address(uint160(uint256(keccak256("newRewardsInitiator"))));
524-
cheats.prank(serviceManagerOwner);
525-
serviceManager.setRewardsInitiator(newRewardsInitiator);
526-
assertEq(newRewardsInitiator, serviceManager.rewardsInitiator());
527-
}
547+
contract ServiceManagerBase_createOperatorDirectedOperatorSetRewardsSubmission_UnitTests is
548+
ServiceManagerBase_UnitTests
549+
{
550+
OperatorSet operatorSet = OperatorSet(address(this), 1);
551+
552+
function testFuzz_createOperatorDirectedOperatorSetRewardsSubmission_Revert_WhenNotOwner(
553+
address caller
554+
) public filterFuzzedAddressInputs(caller) {
555+
cheats.assume(caller != rewardsInitiator);
528556

529-
function test_setRewardsInitiator_revert_notOwner() public {
530-
address caller = address(uint160(uint256(keccak256("caller"))));
531-
address newRewardsInitiator = address(uint160(uint256(keccak256("newRewardsInitiator"))));
532-
cheats.expectRevert("Ownable: caller is not the owner");
533557
cheats.prank(caller);
534-
serviceManager.setRewardsInitiator(newRewardsInitiator);
558+
cheats.expectRevert(
559+
"ServiceManagerBase.onlyRewardsInitiator: caller is not the rewards initiator"
560+
);
561+
serviceManager.createOperatorDirectedOperatorSetRewardsSubmission(
562+
operatorSet,
563+
new IRewardsCoordinatorTypes.OperatorDirectedRewardsSubmission[](0),
564+
new uint256[](0)
565+
);
566+
}
567+
568+
function testFuzz_createOperatorDirectedOperatorSetRewardsSubmission_Revert_InvalidOperatorSet() public {
569+
permissionControllerMock.setCanCall({
570+
account: address(this),
571+
caller: address(serviceManager),
572+
target: address(rewardsCoordinator),
573+
selector: IRewardsCoordinator.createOperatorDirectedOperatorSetRewardsSubmission.selector
574+
});
575+
576+
cheats.prank(rewardsInitiator);
577+
cheats.expectRevert(IRewardsCoordinatorErrors.InvalidOperatorSet.selector);
578+
serviceManager.createOperatorDirectedOperatorSetRewardsSubmission(
579+
operatorSet, new IRewardsCoordinatorTypes.OperatorDirectedRewardsSubmission[](0), new uint256[](0)
580+
);
581+
}
582+
583+
function testFuzz_createOperatorDirectedOperatorSetRewardsSubmission_Correctness() public {
584+
allocationManagerMock.setIsOperatorSet(operatorSet, true);
585+
586+
uint256 numSubmissions = cheats.randomUint(1, 10);
587+
uint256 maxOperatorsPerSubmission = cheats.randomUint(1, 32);
588+
589+
_deployMockRewardTokens(rewardsInitiator, numSubmissions);
590+
591+
IRewardsCoordinatorTypes.OperatorDirectedRewardsSubmission[] memory rewardsSubmissions =
592+
new IRewardsCoordinatorTypes.OperatorDirectedRewardsSubmission[](numSubmissions);
593+
uint256[] memory totalAmounts = new uint256[](numSubmissions);
594+
595+
for (uint256 i = 0; i < numSubmissions; ++i) {
596+
uint256 numOperators = cheats.randomUint(1, maxOperatorsPerSubmission);
597+
IRewardsCoordinatorTypes.OperatorReward[] memory operatorRewards =
598+
new IRewardsCoordinatorTypes.OperatorReward[](numOperators);
599+
uint256 totalAmount = 0;
600+
601+
for (uint256 j = 0; j < numOperators; ++j) {
602+
address operator = cheats.randomAddress();
603+
uint256 amount = cheats.randomUint(1 ether, 100 ether);
604+
operatorRewards[j] =
605+
IRewardsCoordinatorTypes.OperatorReward({operator: operator, amount: amount});
606+
totalAmount += amount;
607+
}
608+
609+
rewardsSubmissions[i] = IRewardsCoordinatorTypes.OperatorDirectedRewardsSubmission({
610+
strategiesAndMultipliers: defaultStrategyAndMultipliers,
611+
token: rewardTokens[i % rewardTokens.length],
612+
operatorRewards: operatorRewards,
613+
startTimestamp: uint32(block.timestamp),
614+
duration: uint32(1 weeks),
615+
description: string.concat("Test submission #", cheats.toString(i))
616+
});
617+
618+
totalAmounts[i] = totalAmount;
619+
}
620+
621+
permissionControllerMock.setCanCall({
622+
account: address(this),
623+
caller: address(serviceManager),
624+
target: address(rewardsCoordinator),
625+
selector: IRewardsCoordinator.createOperatorDirectedOperatorSetRewardsSubmission.selector
626+
});
627+
628+
cheats.prank(rewardsInitiator);
629+
serviceManager.createOperatorDirectedOperatorSetRewardsSubmission(
630+
operatorSet, rewardsSubmissions, totalAmounts
631+
);
535632
}
536-
}
633+
}

0 commit comments

Comments
 (0)