|
2 | 2 | pragma solidity ^0.8.27;
|
3 | 3 |
|
4 | 4 | import "../utils/MockAVSDeployer.sol";
|
5 |
| -import {IStakeRegistryErrors} from "../../src/interfaces/IStakeRegistry.sol"; |
| 5 | +import {IStakeRegistryErrors, IStakeRegistryTypes} from "../../src/interfaces/IStakeRegistry.sol"; |
6 | 6 | import {ISlashingRegistryCoordinatorTypes} from "../../src/interfaces/IRegistryCoordinator.sol";
|
7 | 7 |
|
8 | 8 | contract OperatorStateRetrieverUnitTests is MockAVSDeployer {
|
@@ -144,6 +144,141 @@ contract OperatorStateRetrieverUnitTests is MockAVSDeployer {
|
144 | 144 | assertEq(operators[1][0].stake, defaultStake - 1);
|
145 | 145 | }
|
146 | 146 |
|
| 147 | + function test_getOperatorStateWithSocket_revert_neverRegistered() public { |
| 148 | + cheats.expectRevert( |
| 149 | + "RegistryCoordinator.getQuorumBitmapIndexAtBlockNumber: no bitmap update found for operatorId" |
| 150 | + ); |
| 151 | + operatorStateRetriever.getOperatorStateWithSocket( |
| 152 | + registryCoordinator, defaultOperatorId, uint32(block.number) |
| 153 | + ); |
| 154 | + } |
| 155 | + |
| 156 | + function test_getOperatorStateWithSocket_revert_registeredFirstAfterReferenceBlockNumber() |
| 157 | + public |
| 158 | + { |
| 159 | + cheats.roll(registrationBlockNumber); |
| 160 | + _registerOperatorWithCoordinator(defaultOperator, 1, defaultPubKey); |
| 161 | + |
| 162 | + // should revert because the operator was registered for the first time after the reference block number |
| 163 | + cheats.expectRevert( |
| 164 | + "RegistryCoordinator.getQuorumBitmapIndexAtBlockNumber: no bitmap update found for operatorId" |
| 165 | + ); |
| 166 | + operatorStateRetriever.getOperatorStateWithSocket( |
| 167 | + registryCoordinator, defaultOperatorId, registrationBlockNumber - 1 |
| 168 | + ); |
| 169 | + } |
| 170 | + |
| 171 | + function test_getOperatorStateWithSocket_deregisteredBeforeReferenceBlockNumber() public { |
| 172 | + uint256 quorumBitmap = 1; |
| 173 | + cheats.roll(registrationBlockNumber); |
| 174 | + _registerOperatorWithCoordinator(defaultOperator, quorumBitmap, defaultPubKey); |
| 175 | + |
| 176 | + cheats.roll(registrationBlockNumber + 10); |
| 177 | + cheats.prank(defaultOperator); |
| 178 | + registryCoordinator.deregisterOperator(BitmapUtils.bitmapToBytesArray(quorumBitmap)); |
| 179 | + |
| 180 | + (uint256 fetchedQuorumBitmap, OperatorStateRetriever.Operator[][] memory operators,) = |
| 181 | + operatorStateRetriever.getOperatorStateWithSocket( |
| 182 | + registryCoordinator, defaultOperatorId, uint32(block.number) |
| 183 | + ); |
| 184 | + assertEq(fetchedQuorumBitmap, 0); |
| 185 | + assertEq(operators.length, 0); |
| 186 | + } |
| 187 | + |
| 188 | + function test_getOperatorStateWithSocket_registeredAtReferenceBlockNumber() public { |
| 189 | + uint256 quorumBitmap = 1; |
| 190 | + cheats.roll(registrationBlockNumber); |
| 191 | + _registerOperatorWithCoordinator(defaultOperator, quorumBitmap, defaultPubKey); |
| 192 | + |
| 193 | + (uint256 fetchedQuorumBitmap, OperatorStateRetriever.Operator[][] memory operators,) = |
| 194 | + operatorStateRetriever.getOperatorStateWithSocket( |
| 195 | + registryCoordinator, defaultOperatorId, uint32(block.number) |
| 196 | + ); |
| 197 | + assertEq(fetchedQuorumBitmap, 1); |
| 198 | + assertEq(operators.length, 1); |
| 199 | + assertEq(operators[0].length, 1); |
| 200 | + assertEq(operators[0][0].operator, defaultOperator); |
| 201 | + assertEq(operators[0][0].operatorId, defaultOperatorId); |
| 202 | + assertEq(operators[0][0].stake, defaultStake); |
| 203 | + } |
| 204 | + |
| 205 | + function test_getOperatorStateWithSocket_revert_quorumNotCreatedAtCallTime() public { |
| 206 | + cheats.expectRevert( |
| 207 | + "IndexRegistry._operatorCountAtBlockNumber: quorum did not exist at given block number" |
| 208 | + ); |
| 209 | + operatorStateRetriever.getOperatorStateWithSocket( |
| 210 | + registryCoordinator, |
| 211 | + BitmapUtils.bitmapToBytesArray(1 << numQuorums), |
| 212 | + uint32(block.number) |
| 213 | + ); |
| 214 | + } |
| 215 | + |
| 216 | + function test_getOperatorStateWithSocket_revert_quorumNotCreatedAtReferenceBlockNumber() |
| 217 | + public |
| 218 | + { |
| 219 | + cheats.roll(registrationBlockNumber); |
| 220 | + ISlashingRegistryCoordinator.OperatorSetParam memory operatorSetParams = |
| 221 | + ISlashingRegistryCoordinatorTypes.OperatorSetParam({ |
| 222 | + maxOperatorCount: defaultMaxOperatorCount, |
| 223 | + kickBIPsOfOperatorStake: defaultKickBIPsOfOperatorStake, |
| 224 | + kickBIPsOfTotalStake: defaultKickBIPsOfTotalStake |
| 225 | + }); |
| 226 | + uint96 minimumStake = 1; |
| 227 | + IStakeRegistry.StrategyParams[] memory strategyParams = |
| 228 | + new IStakeRegistry.StrategyParams[](1); |
| 229 | + strategyParams[0] = IStakeRegistryTypes.StrategyParams({ |
| 230 | + strategy: IStrategy(address(1000)), |
| 231 | + multiplier: 1e16 |
| 232 | + }); |
| 233 | + |
| 234 | + cheats.prank(registryCoordinator.owner()); |
| 235 | + registryCoordinator.createTotalDelegatedStakeQuorum( |
| 236 | + operatorSetParams, minimumStake, strategyParams |
| 237 | + ); |
| 238 | + |
| 239 | + cheats.expectRevert( |
| 240 | + "IndexRegistry._operatorCountAtBlockNumber: quorum did not exist at given block number" |
| 241 | + ); |
| 242 | + operatorStateRetriever.getOperatorStateWithSocket( |
| 243 | + registryCoordinator, |
| 244 | + BitmapUtils.bitmapToBytesArray(1 << numQuorums), |
| 245 | + uint32(registrationBlockNumber - 1) |
| 246 | + ); |
| 247 | + } |
| 248 | + |
| 249 | + function test_getOperatorStateWithSocket_returnsCorrect() public { |
| 250 | + uint256 quorumBitmapOne = 1; |
| 251 | + uint256 quorumBitmapThree = 3; |
| 252 | + cheats.roll(registrationBlockNumber); |
| 253 | + _registerOperatorWithCoordinator(defaultOperator, quorumBitmapOne, defaultPubKey); |
| 254 | + |
| 255 | + address otherOperator = _incrementAddress(defaultOperator, 1); |
| 256 | + BN254.G1Point memory otherPubKey = BN254.G1Point(1, 2); |
| 257 | + bytes32 otherOperatorId = BN254.hashG1Point(otherPubKey); |
| 258 | + _registerOperatorWithCoordinator( |
| 259 | + otherOperator, quorumBitmapThree, otherPubKey, defaultStake - 1 |
| 260 | + ); |
| 261 | + |
| 262 | + (OperatorStateRetriever.Operator[][] memory operators,) = operatorStateRetriever |
| 263 | + .getOperatorStateWithSocket( |
| 264 | + registryCoordinator, |
| 265 | + BitmapUtils.bitmapToBytesArray(quorumBitmapThree), |
| 266 | + uint32(block.number) |
| 267 | + ); |
| 268 | + assertEq(operators.length, 2); |
| 269 | + assertEq(operators[0].length, 2); |
| 270 | + assertEq(operators[1].length, 1); |
| 271 | + assertEq(operators[0][0].operator, defaultOperator); |
| 272 | + assertEq(operators[0][0].operatorId, defaultOperatorId); |
| 273 | + assertEq(operators[0][0].stake, defaultStake); |
| 274 | + assertEq(operators[0][1].operator, otherOperator); |
| 275 | + assertEq(operators[0][1].operatorId, otherOperatorId); |
| 276 | + assertEq(operators[0][1].stake, defaultStake - 1); |
| 277 | + assertEq(operators[1][0].operator, otherOperator); |
| 278 | + assertEq(operators[1][0].operatorId, otherOperatorId); |
| 279 | + assertEq(operators[1][0].stake, defaultStake - 1); |
| 280 | + } |
| 281 | + |
147 | 282 | function test_getCheckSignaturesIndices_revert_neverRegistered() public {
|
148 | 283 | bytes32[] memory nonSignerOperatorIds = new bytes32[](1);
|
149 | 284 | nonSignerOperatorIds[0] = defaultOperatorId;
|
@@ -630,7 +765,7 @@ contract OperatorStateRetrieverUnitTests is MockAVSDeployer {
|
630 | 765 | OperatorStateRetriever.Operator[][] memory operators,
|
631 | 766 | uint256[][] memory expectedOperatorOverallIndices,
|
632 | 767 | OperatorMetadata[] memory operatorMetadatas
|
633 |
| - ) internal { |
| 768 | + ) internal pure { |
634 | 769 | // for each quorum
|
635 | 770 | for (uint256 j = 0; j < quorumNumbers.length; j++) {
|
636 | 771 | // make sure the each operator id and stake is correct
|
|
0 commit comments