Skip to content

Commit c14e824

Browse files
committed
refactor: review changes
1 parent e195b74 commit c14e824

File tree

1 file changed

+64
-45
lines changed

1 file changed

+64
-45
lines changed

src/test/unit/RewardsCoordinatorUnit.t.sol

Lines changed: 64 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,14 @@ contract RewardsCoordinatorUnitsTests_setOperatorSetSplit is RewardsCoordinatorU
820820
rewardsCoordinator.setOperatorSetSplit(operator, operatorSet, split);
821821
}
822822

823+
function testFuzz_Revert_InvalidOperatorSet(address operator, uint16 split) public filterFuzzedAddressInputs(operator) {
824+
cheats.assume(operator != address(0));
825+
operatorSet.id = 2; // Invalid operator set id
826+
cheats.prank(operator);
827+
cheats.expectRevert(InvalidOperatorSet.selector);
828+
rewardsCoordinator.setOperatorSetSplit(operator, operatorSet, split);
829+
}
830+
823831
function testFuzz_setOperatorSetSplit(address operator, uint16 split) public filterFuzzedAddressInputs(operator) {
824832
cheats.assume(operator != address(0));
825833

@@ -2920,51 +2928,62 @@ contract RewardsCoordinatorUnitTests_createOperatorDirectedOperatorSetRewardsSub
29202928
rewardsCoordinator.createOperatorDirectedOperatorSetRewardsSubmission(operatorSet, operatorDirectedRewardsSubmissions);
29212929
}
29222930

2923-
// // Revert from reentrancy
2924-
// function testFuzz_Revert_WhenReentrancy(uint256 startTimestamp, uint256 duration) public {
2925-
// // 1. Bound fuzz inputs to valid ranges and amounts
2926-
// duration = bound(duration, 0, MAX_REWARDS_DURATION);
2927-
// duration = duration - (duration % CALCULATION_INTERVAL_SECONDS);
2928-
// startTimestamp = bound(
2929-
// startTimestamp,
2930-
// uint256(_maxTimestamp(GENESIS_REWARDS_TIMESTAMP, uint32(block.timestamp) - MAX_RETROACTIVE_LENGTH)) +
2931-
// CALCULATION_INTERVAL_SECONDS -
2932-
// 1,
2933-
// block.timestamp - duration - 1
2934-
// );
2935-
// startTimestamp = startTimestamp - (startTimestamp % CALCULATION_INTERVAL_SECONDS);
2936-
2937-
// // 2. Deploy Reenterer
2938-
// Reenterer reenterer = new Reenterer();
2939-
2940-
// // 2. Create operator directed rewards submission input param
2941-
// OperatorDirectedRewardsSubmission[]
2942-
// memory operatorDirectedRewardsSubmissions = new OperatorDirectedRewardsSubmission[](1);
2943-
// operatorDirectedRewardsSubmissions[0] = OperatorDirectedRewardsSubmission({
2944-
// strategiesAndMultipliers: defaultStrategyAndMultipliers,
2945-
// token: IERC20(address(reenterer)),
2946-
// operatorRewards: defaultOperatorRewards,
2947-
// startTimestamp: uint32(startTimestamp),
2948-
// duration: uint32(duration),
2949-
// description: ""
2950-
// });
2951-
2952-
// address targetToUse = address(rewardsCoordinator);
2953-
// uint256 msgValueToUse = 0;
2954-
// bytes memory calldataToUse = abi.encodeWithSelector(
2955-
// RewardsCoordinator.createOperatorDirectedOperatorSetRewardsSubmission.selector,
2956-
// address(reenterer),
2957-
// operatorDirectedRewardsSubmissions
2958-
// );
2959-
// reenterer.prepare(targetToUse, msgValueToUse, calldataToUse);
2960-
2961-
// cheats.prank(address(reenterer));
2962-
// cheats.expectRevert("ReentrancyGuard: reentrant call");
2963-
// rewardsCoordinator.createOperatorDirectedOperatorSetRewardsSubmission(
2964-
// address(reenterer),
2965-
// operatorDirectedRewardsSubmissions
2966-
// );
2967-
// }
2931+
function testFuzz_Revert_InvalidOperatorSet(uint32 id) public {
2932+
cheats.assume(id != 1);
2933+
operatorSet.id = id;
2934+
OperatorDirectedRewardsSubmission[] memory operatorDirectedRewardsSubmissions;
2935+
cheats.prank(operatorSet.avs);
2936+
cheats.expectRevert(InvalidOperatorSet.selector);
2937+
rewardsCoordinator.createOperatorDirectedOperatorSetRewardsSubmission(operatorSet, operatorDirectedRewardsSubmissions);
2938+
}
2939+
2940+
// Revert from reentrancy
2941+
function testFuzz_Revert_WhenReentrancy(uint256 startTimestamp, uint256 duration) public {
2942+
// 1. Bound fuzz inputs to valid ranges and amounts
2943+
duration = bound(duration, 0, MAX_REWARDS_DURATION);
2944+
duration = duration - (duration % CALCULATION_INTERVAL_SECONDS);
2945+
startTimestamp = bound(
2946+
startTimestamp,
2947+
uint256(_maxTimestamp(GENESIS_REWARDS_TIMESTAMP, uint32(block.timestamp) - MAX_RETROACTIVE_LENGTH)) +
2948+
CALCULATION_INTERVAL_SECONDS -
2949+
1,
2950+
block.timestamp - duration - 1
2951+
);
2952+
startTimestamp = startTimestamp - (startTimestamp % CALCULATION_INTERVAL_SECONDS);
2953+
2954+
// 2. Deploy Reenterer
2955+
Reenterer reenterer = new Reenterer();
2956+
2957+
// 2. Create operator directed rewards submission input param
2958+
OperatorDirectedRewardsSubmission[]
2959+
memory operatorDirectedRewardsSubmissions = new OperatorDirectedRewardsSubmission[](1);
2960+
operatorDirectedRewardsSubmissions[0] = OperatorDirectedRewardsSubmission({
2961+
strategiesAndMultipliers: defaultStrategyAndMultipliers,
2962+
token: IERC20(address(reenterer)),
2963+
operatorRewards: defaultOperatorRewards,
2964+
startTimestamp: uint32(startTimestamp),
2965+
duration: uint32(duration),
2966+
description: ""
2967+
});
2968+
2969+
operatorSet = OperatorSet(address(reenterer), 1);
2970+
allocationManagerMock.setIsOperatorSet(operatorSet, true);
2971+
address targetToUse = address(rewardsCoordinator);
2972+
uint256 msgValueToUse = 0;
2973+
bytes memory calldataToUse = abi.encodeWithSelector(
2974+
RewardsCoordinator.createOperatorDirectedOperatorSetRewardsSubmission.selector,
2975+
operatorSet,
2976+
operatorDirectedRewardsSubmissions
2977+
);
2978+
reenterer.prepare(targetToUse, msgValueToUse, calldataToUse);
2979+
2980+
cheats.prank(address(reenterer));
2981+
cheats.expectRevert("ReentrancyGuard: reentrant call");
2982+
rewardsCoordinator.createOperatorDirectedOperatorSetRewardsSubmission(
2983+
operatorSet,
2984+
operatorDirectedRewardsSubmissions
2985+
);
2986+
}
29682987

29692988
// Revert with 0 length strats and multipliers
29702989
function testFuzz_Revert_WhenEmptyStratsAndMultipliers(

0 commit comments

Comments
 (0)