Skip to content

Commit 7ae1697

Browse files
authored
test: table calc (#499)
**Motivation:** Add tests for the implemented table calculators **Modifications:** Add tests for the `_getOperatorWeights` function **Result:** Sufficient coverage. More will be added in integration
1 parent 36ec72b commit 7ae1697

File tree

7 files changed

+1200
-10
lines changed

7 files changed

+1200
-10
lines changed

test/mocks/AllocationManagerMock.sol

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {IPauserRegistry} from "eigenlayer-contracts/src/contracts/interfaces/IPa
1111
import {ISemVerMixin} from "eigenlayer-contracts/src/contracts/interfaces/ISemVerMixin.sol";
1212

1313
contract AllocationManagerIntermediate is IAllocationManager {
14+
mapping(address avs => address avsRegistrar) internal _avsRegistrar;
15+
1416
function initialize(address initialOwner, uint256 initialPausedStatus) external virtual {}
1517

1618
function slashOperator(
@@ -40,7 +42,15 @@ contract AllocationManagerIntermediate is IAllocationManager {
4042

4143
function setAllocationDelay(address operator, uint32 delay) external virtual {}
4244

43-
function setAVSRegistrar(address avs, IAVSRegistrar registrar) external virtual {}
45+
function setAVSRegistrar(address avs, IAVSRegistrar avsRegistrar) external {
46+
_avsRegistrar[avs] = address(avsRegistrar);
47+
}
48+
49+
function getAVSRegistrar(
50+
address avs
51+
) external view override returns (IAVSRegistrar) {
52+
return IAVSRegistrar(_avsRegistrar[avs]);
53+
}
4454

4555
function updateAVSMetadataURI(address avs, string calldata metadataURI) external virtual {}
4656

@@ -134,10 +144,6 @@ contract AllocationManagerIntermediate is IAllocationManager {
134144
OperatorSet memory operatorSet
135145
) external view virtual returns (uint256) {}
136146

137-
function getAVSRegistrar(
138-
address avs
139-
) external view virtual returns (IAVSRegistrar) {}
140-
141147
function getStrategiesInOperatorSet(
142148
OperatorSet memory operatorSet
143149
) external view virtual returns (IStrategy[] memory strategies) {}
@@ -219,6 +225,15 @@ contract AllocationManagerIntermediate is IAllocationManager {
219225
contract AllocationManagerMock is AllocationManagerIntermediate {
220226
uint32 internal constant _DEALLOCATION_DELAY = 86400;
221227

228+
mapping(bytes32 operatorSetKey => address[] members) internal _members;
229+
mapping(bytes32 operatorSetKey => IStrategy[] strategies) internal _strategies;
230+
mapping(
231+
bytes32 operatorSetKey
232+
=> mapping(
233+
address operator => mapping(IStrategy strategy => uint256 minimumSlashableStake)
234+
)
235+
) internal _minimumSlashableStake;
236+
222237
function DEALLOCATION_DELAY() external pure override returns (uint32) {
223238
return _DEALLOCATION_DELAY;
224239
}
@@ -263,4 +278,66 @@ contract AllocationManagerMock is AllocationManagerIntermediate {
263278
) external pure returns (uint256) {
264279
return 0;
265280
}
281+
282+
function getMembers(
283+
OperatorSet memory operatorSet
284+
) external view override returns (address[] memory) {
285+
return _members[operatorSet.key()];
286+
}
287+
288+
function setMembersInOperatorSet(
289+
OperatorSet memory operatorSet,
290+
address[] memory members
291+
) external {
292+
_members[operatorSet.key()] = members;
293+
}
294+
295+
function setStrategiesInOperatorSet(
296+
OperatorSet memory operatorSet,
297+
IStrategy[] memory strategies
298+
) external {
299+
_strategies[operatorSet.key()] = strategies;
300+
}
301+
302+
function getStrategiesInOperatorSet(
303+
OperatorSet memory operatorSet
304+
) external view override returns (IStrategy[] memory) {
305+
return _strategies[operatorSet.key()];
306+
}
307+
308+
function setMinimumSlashableStake(
309+
OperatorSet memory operatorSet,
310+
address[] memory operators,
311+
IStrategy[] memory strategies,
312+
uint256[][] memory minimumSlashableStake
313+
) external {
314+
for (uint256 i = 0; i < operators.length; ++i) {
315+
for (uint256 j = 0; j < strategies.length; ++j) {
316+
_minimumSlashableStake[operatorSet.key()][operators[i]][strategies[j]] =
317+
minimumSlashableStake[i][j];
318+
}
319+
}
320+
}
321+
322+
function getMinimumSlashableStake(
323+
OperatorSet memory operatorSet,
324+
address[] memory operators,
325+
IStrategy[] memory strategies,
326+
uint32 /* futureBlock */
327+
) external view override returns (uint256[][] memory) {
328+
uint256[][] memory minimumSlashableStake = new uint256[][](operators.length);
329+
330+
for (uint256 i = 0; i < operators.length; ++i) {
331+
minimumSlashableStake[i] = new uint256[](strategies.length);
332+
}
333+
334+
for (uint256 i = 0; i < operators.length; ++i) {
335+
for (uint256 j = 0; j < strategies.length; ++j) {
336+
minimumSlashableStake[i][j] =
337+
_minimumSlashableStake[operatorSet.key()][operators[i]][strategies[j]];
338+
}
339+
}
340+
341+
return minimumSlashableStake;
342+
}
266343
}

0 commit comments

Comments
 (0)