Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: slashing todos #880

Merged
merged 11 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ remappings = [
"ds-test/=lib/ds-test/src/",
"forge-std/=lib/forge-std/src/"
]
sparse_mode = true

# A list of ignored solc error codes

Expand Down
2 changes: 1 addition & 1 deletion lib/forge-std
2 changes: 1 addition & 1 deletion src/contracts/strategies/EigenStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ contract EigenStrategy is StrategyBase {
IPauserRegistry _pauserRegistry
) StrategyBase(_strategyManager, _pauserRegistry) {}

function initialize(IEigen _EIGEN, IERC20 _bEIGEN, IPauserRegistry _pauserRegistry) public virtual initializer {
function initialize(IEigen _EIGEN, IERC20 _bEIGEN) public virtual initializer {
EIGEN = _EIGEN;
_initializeStrategyBase(_bEIGEN);
}
Expand Down
1,706 changes: 993 additions & 713 deletions src/test/unit/AllocationManagerUnit.t.sol

Large diffs are not rendered by default.

704 changes: 344 additions & 360 deletions src/test/unit/DelegationUnit.t.sol

Large diffs are not rendered by default.

41 changes: 0 additions & 41 deletions src/test/utils/BeaconChainProofsWrapper.sol

This file was deleted.

2 changes: 1 addition & 1 deletion src/test/utils/EigenLayerUnitTestSetup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ abstract contract EigenLayerUnitTestSetup is Test {

pauserRegistry = new PauserRegistry(pausers, unpauser);
eigenLayerProxyAdmin = new ProxyAdmin();

avsDirectoryMock = AVSDirectoryMock(payable(address(new AVSDirectoryMock())));
allocationManagerMock = AllocationManagerMock(payable(address(new AllocationManagerMock())));
strategyManagerMock = StrategyManagerMock(payable(address(new StrategyManagerMock(IDelegationManager(address(delegationManagerMock))))));
Expand Down
48 changes: 0 additions & 48 deletions src/test/utils/Operators.sol

This file was deleted.

47 changes: 0 additions & 47 deletions src/test/utils/Owners.sol

This file was deleted.

152 changes: 147 additions & 5 deletions src/test/utils/Random.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.27;

import "src/contracts/interfaces/IAllocationManager.sol";
import "src/contracts/interfaces/IStrategy.sol";
import "src/contracts/libraries/OperatorSetLib.sol";

Expand All @@ -13,10 +14,10 @@ library Random {
/// Constants
/// -----------------------------------------------------------------------

// Equivalent to: `uint256(keccak256("RANDOMNESS.SEED"))`.
/// @dev Equivalent to: `uint256(keccak256("RANDOMNESS.SEED"))`.
uint256 constant SEED = 0x93bfe7cafd9427243dc4fe8c6e706851eb6696ba8e48960dd74ecc96544938ce;

/// Equivalent to: `uint256(keccak256("RANDOMNESS.SEED"))`.
/// @dev Equivalent to: `uint256(keccak256("RANDOMNESS.SLOT"))`.
uint256 constant SLOT = 0xd0660badbab446a974e6a19901c78a2ad88d7e4f1710b85e1cfc0878477344fd;

/// -----------------------------------------------------------------------
Expand Down Expand Up @@ -59,6 +60,16 @@ library Random {
return r.shuffle().unwrap();
}

function Uint128(Randomness r, uint128 min, uint128 max) internal returns (uint128) {
return uint128(Uint256(r, min, max));
}

function Uint128(
Randomness r
) internal returns (uint128) {
return uint128(Uint256(r));
}

function Uint64(Randomness r, uint64 min, uint64 max) internal returns (uint64) {
return uint64(Uint256(r, min, max));
}
Expand Down Expand Up @@ -91,18 +102,24 @@ library Random {
return address(uint160(r.Uint256(1, type(uint160).max)));
}

function Boolean(
Randomness r
) internal returns (bool) {
return r.Uint256() % 2 == 0;
}

/// -----------------------------------------------------------------------
/// EigenLayer Types
/// General Types
/// -----------------------------------------------------------------------

function strategyArray(Randomness r, uint256 len) internal returns (IStrategy[] memory strategies) {
function StrategyArray(Randomness r, uint256 len) internal returns (IStrategy[] memory strategies) {
strategies = new IStrategy[](len);
for (uint256 i; i < len; ++i) {
strategies[i] = IStrategy(r.Address());
}
}

function operatorSetArray(
function OperatorSetArray(
Randomness r,
address avs,
uint256 len
Expand All @@ -113,6 +130,131 @@ library Random {
}
}

/// -----------------------------------------------------------------------
/// `AllocationManager` Types
/// -----------------------------------------------------------------------

/// @dev Usage: `r.createSetParams(r, numOpSets, numStrats)`.
function CreateSetParams(
Randomness r,
uint256 numOpSets,
uint256 numStrats
) internal returns (IAllocationManagerTypes.CreateSetParams[] memory params) {
params = new IAllocationManagerTypes.CreateSetParams[](numOpSets);
for (uint256 i; i < numOpSets; ++i) {
params[i].operatorSetId = r.Uint32(1, type(uint32).max);
params[i].strategies = r.StrategyArray(numStrats);
}
}

/// @dev Usage:
/// ```
/// AllocateParams[] memory allocateParams = r.allocateParams(avs, numAllocations, numStrats);
/// cheats.prank(avs);
/// allocationManager.createOperatorSets(r.createSetParams(allocateParams));
/// ```
function CreateSetParams(
Randomness,
IAllocationManagerTypes.AllocateParams[] memory allocateParams
) internal pure returns (IAllocationManagerTypes.CreateSetParams[] memory params) {
params = new IAllocationManagerTypes.CreateSetParams[](allocateParams.length);
for (uint256 i; i < allocateParams.length; ++i) {
params[i] = IAllocationManagerTypes.CreateSetParams(
allocateParams[i].operatorSet.id, allocateParams[i].strategies
);
}
}

/// @dev Usage:
/// ```
/// AllocateParams[] memory allocateParams = r.allocateParams(avs, numAllocations, numStrats);
/// CreateSetParams[] memory createSetParams = r.createSetParams(allocateParams);
///
/// cheats.prank(avs);
/// allocationManager.createOperatorSets(createSetParams);
///
/// cheats.prank(operator);
/// allocationManager.modifyAllocations(allocateParams);
/// ```
function AllocateParams(
Randomness r,
address avs,
uint256 numAllocations,
uint256 numStrats
) internal returns (IAllocationManagerTypes.AllocateParams[] memory allocateParams) {
allocateParams = new IAllocationManagerTypes.AllocateParams[](numAllocations);

// TODO: Randomize magnitudes such that they sum to 1e18 (100%).
uint64 magnitudePerSet = uint64(WAD / numStrats);

for (uint256 i; i < numAllocations; ++i) {
allocateParams[i].operatorSet = OperatorSet(avs, r.Uint32());
allocateParams[i].strategies = r.StrategyArray(numStrats);
allocateParams[i].newMagnitudes = new uint64[](numStrats);

for (uint256 j; j < numStrats; ++j) {
allocateParams[i].newMagnitudes[j] = magnitudePerSet;
}
}
}

/// @dev Usage:
/// ```
/// AllocateParams[] memory allocateParams = r.allocateParams(avs, numAllocations, numStrats);
/// AllocateParams[] memory deallocateParams = r.deallocateParams(allocateParams);
/// CreateSetParams[] memory createSetParams = r.createSetParams(allocateParams);
///
/// cheats.prank(avs);
/// allocationManager.createOperatorSets(createSetParams);
///
/// cheats.prank(operator);
/// allocationManager.modifyAllocations(allocateParams);
///
/// cheats.prank(operator)
/// allocationManager.modifyAllocations(deallocateParams);
/// ```
function DeallocateParams(
Randomness r,
IAllocationManagerTypes.AllocateParams[] memory allocateParams
) internal returns (IAllocationManagerTypes.AllocateParams[] memory deallocateParams) {
uint256 numDeallocations = allocateParams.length;

deallocateParams = new IAllocationManagerTypes.AllocateParams[](numDeallocations);

for (uint256 i; i < numDeallocations; ++i) {
deallocateParams[i].operatorSet = allocateParams[i].operatorSet;
deallocateParams[i].strategies = allocateParams[i].strategies;

deallocateParams[i].newMagnitudes = new uint64[](allocateParams[i].strategies.length);
for (uint256 j; j < allocateParams[i].strategies.length; ++j) {
deallocateParams[i].newMagnitudes[j] = r.Uint64(0, allocateParams[i].newMagnitudes[j] - 1);
}
}
}

function RegisterParams(
Randomness r,
address avs,
uint256 numOpSets
) internal returns (IAllocationManagerTypes.RegisterParams memory params) {
params.avs = avs;
params.operatorSetIds = new uint32[](numOpSets);
for (uint256 i; i < numOpSets; ++i) {
params.operatorSetIds[i] = r.Uint32(1, type(uint32).max);
}
params.data = abi.encode(r.Bytes32());
}

function DeregisterParams(
Randomness,
address operator,
IAllocationManagerTypes.RegisterParams memory registerParams
) internal pure returns (IAllocationManagerTypes.DeregisterParams memory params) {
params.operator = operator;
params.avs = registerParams.avs;
params.operatorSetIds = registerParams.operatorSetIds;
}

/// -----------------------------------------------------------------------
/// Helpers
/// -----------------------------------------------------------------------
Expand Down
29 changes: 0 additions & 29 deletions src/test/utils/SignatureCompaction.sol

This file was deleted.

Loading
Loading