Skip to content

Commit

Permalink
fix: tests wip
Browse files Browse the repository at this point in the history
  • Loading branch information
8sunyuan committed Jan 22, 2025
1 parent b5ed8be commit c547c37
Show file tree
Hide file tree
Showing 22 changed files with 2,704 additions and 221 deletions.
6 changes: 3 additions & 3 deletions src/BLSApkRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.27;

import {BLSApkRegistryStorage} from "./BLSApkRegistryStorage.sol";

import {IRegistryCoordinator} from "./interfaces/IRegistryCoordinator.sol";
import {ISlashingRegistryCoordinator} from "./interfaces/ISlashingRegistryCoordinator.sol";

import {BN254} from "./libraries/BN254.sol";

Expand All @@ -18,8 +18,8 @@ contract BLSApkRegistry is BLSApkRegistryStorage {

/// @notice Sets the (immutable) `registryCoordinator` address
constructor(
IRegistryCoordinator _registryCoordinator
) BLSApkRegistryStorage(_registryCoordinator) {}
ISlashingRegistryCoordinator _slashingRegistryCoordinator
) BLSApkRegistryStorage(_slashingRegistryCoordinator) {}

/*******************************************************************************
EXTERNAL FUNCTIONS - REGISTRY COORDINATOR
Expand Down
6 changes: 3 additions & 3 deletions src/BLSApkRegistryStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.27;

import {IBLSApkRegistry} from "./interfaces/IBLSApkRegistry.sol";
import {IRegistryCoordinator} from "./interfaces/IRegistryCoordinator.sol";
import {ISlashingRegistryCoordinator} from "./interfaces/ISlashingRegistryCoordinator.sol";

import {Initializable} from "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";

Expand All @@ -29,8 +29,8 @@ abstract contract BLSApkRegistryStorage is Initializable, IBLSApkRegistry {
/// @notice maps quorumNumber => current aggregate pubkey of quorum
mapping(uint8 => BN254.G1Point) public currentApk;

constructor(IRegistryCoordinator _registryCoordinator) {
registryCoordinator = address(_registryCoordinator);
constructor(ISlashingRegistryCoordinator _slashingRegistryCoordinator) {
registryCoordinator = address(_slashingRegistryCoordinator);
// disable initializers so that the implementation contract cannot be initialized
_disableInitializers();
}
Expand Down
6 changes: 3 additions & 3 deletions src/IndexRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pragma solidity ^0.8.27;

import {IndexRegistryStorage} from "./IndexRegistryStorage.sol";
import {IRegistryCoordinator} from "./interfaces/IRegistryCoordinator.sol";
import {ISlashingRegistryCoordinator} from "./interfaces/ISlashingRegistryCoordinator.sol";

/**
* @title A `Registry` that keeps track of an ordered list of operators for each quorum
Expand All @@ -18,8 +18,8 @@ contract IndexRegistry is IndexRegistryStorage {

/// @notice sets the (immutable) `registryCoordinator` address
constructor(
IRegistryCoordinator _registryCoordinator
) IndexRegistryStorage(_registryCoordinator) {}
ISlashingRegistryCoordinator _slashingRegistryCoordinator
) IndexRegistryStorage(_slashingRegistryCoordinator) {}

/*******************************************************************************
EXTERNAL FUNCTIONS - REGISTRY COORDINATOR
Expand Down
6 changes: 3 additions & 3 deletions src/IndexRegistryStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.27;

import {Initializable} from "@openzeppelin-upgrades/contracts/proxy/utils/Initializable.sol";

import {IRegistryCoordinator} from "./interfaces/IRegistryCoordinator.sol";
import {ISlashingRegistryCoordinator} from "./interfaces/ISlashingRegistryCoordinator.sol";
import {IIndexRegistry} from "./interfaces/IIndexRegistry.sol";

/**
Expand Down Expand Up @@ -31,9 +31,9 @@ abstract contract IndexRegistryStorage is Initializable, IIndexRegistry {
mapping(uint8 => QuorumUpdate[]) internal _operatorCountHistory;

constructor(
IRegistryCoordinator _registryCoordinator
ISlashingRegistryCoordinator _slashingRegistryCoordinator
){
registryCoordinator = address(_registryCoordinator);
registryCoordinator = address(_slashingRegistryCoordinator);
// disable initializers so that the implementation contract cannot be initialized
_disableInitializers();
}
Expand Down
7 changes: 2 additions & 5 deletions src/StakeRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {IDelegationManager} from "eigenlayer-contracts/src/contracts/interfaces/
import {IAVSDirectory } from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";
import {OperatorSet} from "eigenlayer-contracts/src/contracts/interfaces/IAllocationManager.sol";
import {IAllocationManager} from "eigenlayer-contracts/src/contracts/interfaces/IAllocationManager.sol";
import {IServiceManager} from "./interfaces/IServiceManager.sol";

import {StakeRegistryStorage, IStrategy} from "./StakeRegistryStorage.sol";

Expand Down Expand Up @@ -46,14 +45,12 @@ contract StakeRegistry is StakeRegistryStorage {
ISlashingRegistryCoordinator _slashingRegistryCoordinator,
IDelegationManager _delegationManager,
IAVSDirectory _avsDirectory,
IAllocationManager _allocationManager,
IServiceManager _serviceManager
IAllocationManager _allocationManager
) StakeRegistryStorage(
_slashingRegistryCoordinator,
_delegationManager,
_avsDirectory,
_allocationManager,
_serviceManager
_allocationManager
) {}

/*******************************************************************************
Expand Down
8 changes: 1 addition & 7 deletions src/StakeRegistryStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity ^0.8.27;
import {IDelegationManager} from "eigenlayer-contracts/src/contracts/interfaces/IDelegationManager.sol";
import {IAVSDirectory} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";
import {IAllocationManager} from "eigenlayer-contracts/src/contracts/interfaces/IAllocationManager.sol";
import {IServiceManager} from "./interfaces/IServiceManager.sol";
import {IStrategyManager, IStrategy} from "eigenlayer-contracts/src/contracts/interfaces/IStrategyManager.sol";

import {ISlashingRegistryCoordinator} from "./interfaces/ISlashingRegistryCoordinator.sol";
Expand Down Expand Up @@ -33,9 +32,6 @@ abstract contract StakeRegistryStorage is IStakeRegistry {
/// @notice the address of the AllocationManager for EigenLayer.
IAllocationManager public immutable allocationManager;

/// @notice the address of the ServiceManager associtated with the stake registries
IServiceManager public immutable serviceManager;

/// @notice the coordinator contract that this registry is associated with
address public immutable registryCoordinator;

Expand Down Expand Up @@ -68,13 +64,11 @@ abstract contract StakeRegistryStorage is IStakeRegistry {
ISlashingRegistryCoordinator _slashingRegistryCoordinator,
IDelegationManager _delegationManager,
IAVSDirectory _avsDirectory,
IAllocationManager _allocationManager,
IServiceManager _serviceManager
IAllocationManager _allocationManager
) {
registryCoordinator = address(_slashingRegistryCoordinator);
delegation = _delegationManager;
avsDirectory = _avsDirectory;
serviceManager = _serviceManager;
allocationManager = _allocationManager;
}

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/ISlashingRegistryCoordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface IRegistryCoordinatorErrors {
* @title Interface for a contract that coordinates between various registries for an AVS.
* @author Layr Labs, Inc.
*/
interface ISlashingRegistryCoordinator is IRegistryCoordinatorErrors{
interface ISlashingRegistryCoordinator is IRegistryCoordinatorErrors {
// EVENTS

event OperatorSetParamsUpdated(uint8 indexed quorumNumber, OperatorSetParam operatorSetParams);
Expand Down
3 changes: 2 additions & 1 deletion test/ffi/BLSPubKeyCompendiumFFI.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.27;
import "../../src/BLSApkRegistry.sol";
import "../ffi/util/G2Operations.sol";
import {IBLSApkRegistry} from "../../src/interfaces/IBLSApkRegistry.sol";
import {ISlashingRegistryCoordinator} from "../../src/interfaces/ISlashingRegistryCoordinator.sol";

contract BLSApkRegistryFFITests is G2Operations {
using BN254 for BN254.G1Point;
Expand All @@ -12,7 +13,7 @@ contract BLSApkRegistryFFITests is G2Operations {
Vm cheats = Vm(VM_ADDRESS);

BLSApkRegistry blsApkRegistry;
IRegistryCoordinator registryCoordinator;
ISlashingRegistryCoordinator registryCoordinator;

uint256 privKey;
IBLSApkRegistry.PubkeyRegistrationParams pubkeyRegistrationParams;
Expand Down
4 changes: 2 additions & 2 deletions test/harnesses/BLSApkRegistryHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import "../../src/BLSApkRegistry.sol";
contract BLSApkRegistryHarness is BLSApkRegistry {

constructor(
IRegistryCoordinator _registryCoordinator
) BLSApkRegistry(_registryCoordinator) {}
ISlashingRegistryCoordinator _slashingRegistryCoordinator
) BLSApkRegistry(_slashingRegistryCoordinator) {}

function setBLSPublicKey(address account, BN254.G1Point memory pk) external {

Expand Down
7 changes: 3 additions & 4 deletions test/harnesses/StakeRegistryHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ import "../../src/StakeRegistry.sol";
// wrapper around the StakeRegistry contract that exposes the internal functions for unit testing.
contract StakeRegistryHarness is StakeRegistry {
constructor(
IRegistryCoordinator _registryCoordinator,
ISlashingRegistryCoordinator _registryCoordinator,
IDelegationManager _delegationManager,
IAVSDirectory _avsDirectory,
IAllocationManager _allocationManager,
IServiceManager _serviceManager
) StakeRegistry(_registryCoordinator, _delegationManager, _avsDirectory, _allocationManager, _serviceManager) {
IAllocationManager _allocationManager
) StakeRegistry(_registryCoordinator, _delegationManager, _avsDirectory, _allocationManager) {
}

function recordOperatorStakeUpdate(bytes32 operatorId, uint8 quorumNumber, uint96 newStake) external returns(int256) {
Expand Down
20 changes: 10 additions & 10 deletions test/integration/IntegrationBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,22 @@ abstract contract IntegrationBase is IntegrationConfig {

/// @dev Also checks that the user has NEVER_REGISTERED status
function assert_HasNoOperatorInfo(User user, string memory err) internal {
IRegistryCoordinator.OperatorInfo memory info = _getOperatorInfo(user);
ISlashingRegistryCoordinator.OperatorInfo memory info = _getOperatorInfo(user);

assertEq(info.operatorId, bytes32(0), err);
assertTrue(info.status == IRegistryCoordinator.OperatorStatus.NEVER_REGISTERED, err);
assertTrue(info.status == ISlashingRegistryCoordinator.OperatorStatus.NEVER_REGISTERED, err);
}

function assert_HasRegisteredStatus(User user, string memory err) internal {
IRegistryCoordinator.OperatorStatus status = registryCoordinator.getOperatorStatus(address(user));
ISlashingRegistryCoordinator.OperatorStatus status = registryCoordinator.getOperatorStatus(address(user));

assertTrue(status == IRegistryCoordinator.OperatorStatus.REGISTERED, err);
assertTrue(status == ISlashingRegistryCoordinator.OperatorStatus.REGISTERED, err);
}

function assert_HasDeregisteredStatus(User user, string memory err) internal {
IRegistryCoordinator.OperatorStatus status = registryCoordinator.getOperatorStatus(address(user));
ISlashingRegistryCoordinator.OperatorStatus status = registryCoordinator.getOperatorStatus(address(user));

assertTrue(status == IRegistryCoordinator.OperatorStatus.DEREGISTERED, err);
assertTrue(status == ISlashingRegistryCoordinator.OperatorStatus.DEREGISTERED, err);
}

function assert_EmptyQuorumBitmap(User user, string memory err) internal {
Expand Down Expand Up @@ -213,8 +213,8 @@ abstract contract IntegrationBase is IntegrationConfig {
}

function assert_Snap_Unchanged_OperatorInfo(User user, string memory err) internal {
IRegistryCoordinator.OperatorInfo memory curInfo = _getOperatorInfo(user);
IRegistryCoordinator.OperatorInfo memory prevInfo = _getPrevOperatorInfo(user);
ISlashingRegistryCoordinator.OperatorInfo memory curInfo = _getOperatorInfo(user);
ISlashingRegistryCoordinator.OperatorInfo memory prevInfo = _getPrevOperatorInfo(user);

assertEq(prevInfo.operatorId, curInfo.operatorId, err);
assertTrue(prevInfo.status == curInfo.status, err);
Expand Down Expand Up @@ -789,11 +789,11 @@ abstract contract IntegrationBase is IntegrationConfig {

/// RegistryCoordinator:

function _getOperatorInfo(User user) internal view returns (IRegistryCoordinator.OperatorInfo memory) {
function _getOperatorInfo(User user) internal view returns (ISlashingRegistryCoordinator.OperatorInfo memory) {
return registryCoordinator.getOperator(address(user));
}

function _getPrevOperatorInfo(User user) internal timewarp() returns (IRegistryCoordinator.OperatorInfo memory) {
function _getPrevOperatorInfo(User user) internal timewarp() returns (ISlashingRegistryCoordinator.OperatorInfo memory) {
return _getOperatorInfo(user);
}

Expand Down
10 changes: 5 additions & 5 deletions test/integration/IntegrationConfig.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ contract IntegrationConfig is IntegrationDeployer, G2Operations, Constants {
emit log_named_uint("_configRand: number of quorums being initialized", quorumCount);

// Default OperatorSetParams for all quorums
IRegistryCoordinator.OperatorSetParam memory operatorSet = IRegistryCoordinator.OperatorSetParam({
ISlashingRegistryCoordinator.OperatorSetParam memory operatorSet = ISlashingRegistryCoordinator.OperatorSetParam({
maxOperatorCount: MAX_OPERATOR_COUNT,
kickBIPsOfOperatorStake: KICK_BIPS_OPERATOR_STAKE,
kickBIPsOfTotalStake: KICK_BIPS_TOTAL_STAKE
Expand Down Expand Up @@ -304,7 +304,7 @@ contract IntegrationConfig is IntegrationDeployer, G2Operations, Constants {
for (uint i = 0; i < churnQuorums.length; i++) {
uint8 quorum = uint8(churnQuorums[i]);

IRegistryCoordinator.OperatorSetParam memory params
ISlashingRegistryCoordinator.OperatorSetParam memory params
= registryCoordinator.getOperatorSetParams(quorum);

// Sanity check - make sure we're at the operator cap
Expand Down Expand Up @@ -338,15 +338,15 @@ contract IntegrationConfig is IntegrationDeployer, G2Operations, Constants {
/// From RegistryCoordinator._individualKickThreshold
function _individualKickThreshold(
uint96 operatorStake,
IRegistryCoordinator.OperatorSetParam memory setParams
ISlashingRegistryCoordinator.OperatorSetParam memory setParams
) internal pure returns (uint96) {
return operatorStake * setParams.kickBIPsOfOperatorStake / BIPS_DENOMINATOR;
}

/// From RegistryCoordinator._totalKickThreshold
function _totalKickThreshold(
uint96 totalStake,
IRegistryCoordinator.OperatorSetParam memory setParams
ISlashingRegistryCoordinator.OperatorSetParam memory setParams
) internal pure returns (uint96) {
return totalStake * setParams.kickBIPsOfTotalStake / BIPS_DENOMINATOR;
}
Expand Down Expand Up @@ -524,7 +524,7 @@ contract IntegrationConfig is IntegrationDeployer, G2Operations, Constants {
* @dev Uses _randFillType to determine how many operators to register for a quorum initially
* @return The number of operators to register
*/
function _randInitialOperators(IRegistryCoordinator.OperatorSetParam memory operatorSet) private returns (uint) {
function _randInitialOperators(ISlashingRegistryCoordinator.OperatorSetParam memory operatorSet) private returns (uint) {
uint fillTypeFlag = _randValue(fillTypeFlags);

if (fillTypeFlag == EMPTY) {
Expand Down
16 changes: 6 additions & 10 deletions test/integration/IntegrationDeployer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,16 @@ abstract contract IntegrationDeployer is Test, IUserDeployer {
cheats.stopPrank();

StakeRegistry stakeRegistryImplementation = new StakeRegistry(
IRegistryCoordinator(registryCoordinator), IDelegationManager(delegationManager), IAVSDirectory(avsDirectory), allocationManager, IServiceManager(serviceManager)
ISlashingRegistryCoordinator(registryCoordinator), IDelegationManager(delegationManager), IAVSDirectory(avsDirectory), allocationManager
);
BLSApkRegistry blsApkRegistryImplementation =
new BLSApkRegistry(IRegistryCoordinator(registryCoordinator));
new BLSApkRegistry(ISlashingRegistryCoordinator(registryCoordinator));
IndexRegistry indexRegistryImplementation =
new IndexRegistry(IRegistryCoordinator(registryCoordinator));
new IndexRegistry(ISlashingRegistryCoordinator(registryCoordinator));
ServiceManagerMock serviceManagerImplementation = new ServiceManagerMock(
IAVSDirectory(avsDirectory),
rewardsCoordinator,
IRegistryCoordinator(registryCoordinator),
ISlashingRegistryCoordinator(registryCoordinator),
stakeRegistry,
permissionController
);
Expand Down Expand Up @@ -380,16 +380,12 @@ abstract contract IntegrationDeployer is Test, IUserDeployer {
TransparentUpgradeableProxy(payable(address(registryCoordinator))),
address(registryCoordinatorImplementation),
abi.encodeWithSelector(
RegistryCoordinator.initialize.selector,
SlashingRegistryCoordinator.initialize.selector,
registryCoordinatorOwner,
churnApprover,
ejector,
0, /*initialPausedStatus*/
new IRegistryCoordinator.OperatorSetParam[](0),
new uint96[](0),
new IStakeRegistry.StrategyParams[][](0),
quorumStakeTypes,
slashableStakeQuorumLookAheadPeriods
address(serviceManager) // _accountIdentifier
)
);

Expand Down
10 changes: 5 additions & 5 deletions test/integration/User.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -152,28 +152,28 @@ contract User is Test {
.plus(standardBitmap)
.bitmapToBytesArray();

IRegistryCoordinator.OperatorKickParam[] memory kickParams
= new IRegistryCoordinator.OperatorKickParam[](allQuorums.length);
ISlashingRegistryCoordinator.OperatorKickParam[] memory kickParams
= new ISlashingRegistryCoordinator.OperatorKickParam[](allQuorums.length);

// this constructs OperatorKickParam[] in ascending quorum order
// (yikes)
uint churnIdx;
uint stdIdx;
while (churnIdx + stdIdx < allQuorums.length) {
if (churnIdx == churnQuorums.length) {
kickParams[churnIdx + stdIdx] = IRegistryCoordinator.OperatorKickParam({
kickParams[churnIdx + stdIdx] = ISlashingRegistryCoordinator.OperatorKickParam({
quorumNumber: 0,
operator: address(0)
});
stdIdx++;
} else if (stdIdx == standardQuorums.length || churnQuorums[churnIdx] < standardQuorums[stdIdx]) {
kickParams[churnIdx + stdIdx] = IRegistryCoordinator.OperatorKickParam({
kickParams[churnIdx + stdIdx] = ISlashingRegistryCoordinator.OperatorKickParam({
quorumNumber: uint8(churnQuorums[churnIdx]),
operator: address(churnTargets[churnIdx])
});
churnIdx++;
} else if (standardQuorums[stdIdx] < churnQuorums[churnIdx]) {
kickParams[churnIdx + stdIdx] = IRegistryCoordinator.OperatorKickParam({
kickParams[churnIdx + stdIdx] = ISlashingRegistryCoordinator.OperatorKickParam({
quorumNumber: 0,
operator: address(0)
});
Expand Down
Loading

0 comments on commit c547c37

Please sign in to comment.