Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
8sunyuan committed Jan 24, 2025
1 parent 7f89acc commit 8b269dc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
8 changes: 8 additions & 0 deletions test/harnesses/RegistryCoordinatorHarness.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,12 @@ contract RegistryCoordinatorHarness is RegistryCoordinator, Test {
function _updateOperatorBitmapExternal(bytes32 operatorId, uint192 quorumBitmap) external {
_updateOperatorBitmap(operatorId, quorumBitmap);
}

function setOperatorSetsEnabled(bool enabled) external {
operatorSetsEnabled = enabled;
}

function setM2QuorumsDisabled(bool disabled) external {
m2QuorumsDisabled = disabled;
}
}
30 changes: 20 additions & 10 deletions test/integration/IntegrationDeployer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -439,27 +439,37 @@ abstract contract IntegrationDeployer is Test, IUserDeployer {
});
cheats.stopPrank();

_setoperatorSetsEnabled(false);
_setOperatorSetsEnabled(false);
_setM2QuorumsDisabled(false);
}

/// @notice Overwrite RegistryCoordinator.operatorSetsEnabled to false since by default
/// RegistryCoordinator is deployed and intitialized with operatorSetsEnabled set to true
/// This is to enable testing of RegistryCoordinator in non operator set mode.
function _setoperatorSetsEnabled(bool operatorSetsEnabled) internal {
/// @notice Overwrite RegistryCoordinator.operatorSetsEnabled to the specified value.
/// This is to enable testing of RegistryCoordinator in non-operator set mode.
function _setOperatorSetsEnabled(bool operatorSetsEnabled) internal {
// 1. First read the current value of the entire slot
// which holds operatorSetsEnabled and accountIdentifier
// which holds operatorSetsEnabled, m2QuorumsDisabled, and accountIdentifier
bytes32 currentSlot = cheats.load(address(registryCoordinator), bytes32(uint256(161)));

// 2. Clear only the first byte (operatorSetsEnabled) while keeping the rest (accountIdentifier)
// We can do this by:
// i. Masking out the first byte of the current slot (keep accountIdentifier)
// ii. OR it with 0 in the first byte position (set operatorSetsEnabled to false)
// 2. Clear only the first byte (operatorSetsEnabled) while keeping the rest
bytes32 newSlot = (currentSlot & ~bytes32(uint256(0xff))) | bytes32(uint256(operatorSetsEnabled ? 0x01 : 0x00));

// 3. Store the modified slot
cheats.store(address(registryCoordinator), bytes32(uint256(161)), newSlot);
}

/// @notice Overwrite RegistryCoordinator.m2QuorumsDisabled to the specified value.
function _setM2QuorumsDisabled(bool m2QuorumsDisabled) internal {
// 1. First read the current value of the entire slot
// which holds operatorSetsEnabled, m2QuorumsDisabled, and accountIdentifier
bytes32 currentSlot = cheats.load(address(registryCoordinator), bytes32(uint256(161)));

// 2. Clear only the second byte (m2QuorumsDisabled) while keeping the rest
bytes32 newSlot = (currentSlot & ~bytes32(uint256(0xff) << 8)) | bytes32(uint256(m2QuorumsDisabled ? 0x01 : 0x00) << 8);

// 3. Store the modified slot
cheats.store(address(registryCoordinator), bytes32(uint256(161)), newSlot);
}

/// @dev Deploy a strategy and its underlying token, push to global lists of tokens/strategies, and whitelist
/// strategy in strategyManager
function _newStrategyAndToken(
Expand Down
21 changes: 2 additions & 19 deletions test/utils/MockAVSDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@ contract MockAVSDeployer is Test {

operatorStateRetriever = new OperatorStateRetriever();

_setoperatorSetsEnabled(false);
registryCoordinator.setOperatorSetsEnabled(false);
registryCoordinator.setM2QuorumsDisabled(false);
}

function _labelContracts() internal {
Expand Down Expand Up @@ -359,24 +360,6 @@ contract MockAVSDeployer is Test {
vm.label(address(allocationManagerImplementation), "AllocationManagerImplementation");
}

/// @notice Overwrite RegistryCoordinator.operatorSetsEnabled to false since by default
/// RegistryCoordinator is deployed and intitialized with operatorSetsEnabled set to true
/// This is to enable testing of RegistryCoordinator in non operator set mode.
function _setoperatorSetsEnabled(bool operatorSetsEnabled) internal {
// 1. First read the current value of the entire slot
// which holds operatorSetsEnabled and accountIdentifier
bytes32 currentSlot = cheats.load(address(registryCoordinator), bytes32(uint256(161)));

// 2. Clear only the first byte (operatorSetsEnabled) while keeping the rest (accountIdentifier)
// We can do this by:
// i. Masking out the first byte of the current slot (keep accountIdentifier)
// ii. OR it with 0 in the first byte position (set operatorSetsEnabled to false)
bytes32 newSlot = (currentSlot & ~bytes32(uint256(0xff))) | bytes32(uint256(operatorSetsEnabled ? 0x01 : 0x00));

// 3. Store the modified slot
cheats.store(address(registryCoordinator), bytes32(uint256(161)), newSlot);
}

/**
* @notice registers operator with coordinator
*/
Expand Down

0 comments on commit 8b269dc

Please sign in to comment.