Skip to content

Commit 3d70abd

Browse files
authored
feat: add tree and start on tests for op state ret (#140)
* feat: add tree and start on tests for op state ret * feat: getOperatorState tests work * feat: complete checksignatures checks and handle extra reversions * feat: sync tree * fix: clarify and correct treefile * feat: add comments on tests and update test case * feat: check operator addresses as well
1 parent bf7e07a commit 3d70abd

File tree

4 files changed

+313
-1
lines changed

4 files changed

+313
-1
lines changed

src/OperatorStateRetriever.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ contract OperatorStateRetriever {
112112

113113
// get the indices of the quorumBitmap updates for each of the operators in the nonSignerOperatorIds array
114114
checkSignaturesIndices.nonSignerQuorumBitmapIndices = registryCoordinator.getQuorumBitmapIndicesAtBlockNumber(referenceBlockNumber, nonSignerOperatorIds);
115+
115116
// get the indices of the totalStake updates for each of the quorums in the quorumNumbers array
116117
checkSignaturesIndices.totalStakeIndices = stakeRegistry.getTotalStakeIndicesAtBlockNumber(referenceBlockNumber, quorumNumbers);
117118

@@ -130,6 +131,8 @@ contract OperatorStateRetriever {
130131
checkSignaturesIndices.nonSignerQuorumBitmapIndices[i]
131132
);
132133

134+
require(nonSignerQuorumBitmap != 0, "OperatorStateRetriever.getCheckSignaturesIndices: operator must be registered at blocknumber");
135+
133136
// if the operator was a part of the quorum and the quorum is a part of the provided quorumNumbers
134137
if ((nonSignerQuorumBitmap >> uint8(quorumNumbers[quorumNumberIndex])) & 1 == 1) {
135138
// get the index of the stake update for the operator at the given blocknumber and quorum number

src/StakeRegistry.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ contract StakeRegistry is StakeRegistryStorage {
697697
uint32[] memory indices = new uint32[](quorumNumbers.length);
698698
for (uint256 i = 0; i < quorumNumbers.length; i++) {
699699
uint8 quorumNumber = uint8(quorumNumbers[i]);
700+
require(_quorumExists(quorumNumber), "StakeRegistry.getTotalStakeIndicesAtBlockNumber: quorum does not exist");
700701
require(
701702
_totalStakeHistory[quorumNumber][0].updateBlockNumber <= blockNumber,
702703
"StakeRegistry.getTotalStakeIndicesAtBlockNumber: quorum has no stake history at blockNumber"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
.
2+
└── OperatorStateRetriever tree (*** denotes that integration tests are needed to validate path)
3+
├── when getOperatorState(IRegistryCoordinator,bytes32,uint32) is called
4+
│ ├── when the given operator has never registered with the given registryCoordinator (their quorumBitmapHistory has length 0)
5+
│ │ └── it should revert with "RegistryCoordinator.getQuorumBitmapIndicesAtBlockNumber: operator has no bitmap history at blockNumber"
6+
│ └── when the given operator has registered for the first time with the given registryCoordinator
7+
│ ├── after the given blockNumber
8+
│ │ └── it should revert with "RegistryCoordinator.getQuorumBitmapIndicesAtBlockNumber: operator has no bitmap history at blockNumber"
9+
│ └── before the given blockNumber
10+
│ ├── and was not registered for any quorums at the given blockNumber
11+
│ │ └── it should return (0, [])
12+
│ └── and was registered for a set of quorums at the given blockNumber
13+
│ └── it should return
14+
└── the given operator's quorum bitmap at the given blockNumber as the first argument and
15+
└── a list of the list of operators (by id and stake) ordered by index for each quorum in the quorumBitmap from the first argument ascending by quorumNumber
16+
├── when getOperatorState(IRegistryCoordinator,bytes memory,uint32) is called
17+
│ ├── when at any of the given quorumNumbers were not created at the time of call
18+
│ │ └── it should revert with "IndexRegistry._operatorCountAtBlockNumber: quorum does not exist"
19+
│ ├── when at any of the given quorumNumbers were not created before or at the given blockNumber
20+
│ │ └── it should revert with "IndexRegistry._operatorCountAtBlockNumber: quorum did not exist at given block number"
21+
│ └── when the given quorumNumbers are created on the given registry registryCoordinator
22+
│ └── it should return their quorum bitmap as the first argument and a list of the list of operators (by id and stake) ordered by index for each quorum in the set ascending by quorumNumber
23+
└── when getCheckSignaturesIndices is called
24+
├── when any of the given nonSignerOperatorIds were never registered with the given registryCoordinator
25+
│ └── it should revert with "RegistryCoordinator.getQuorumBitmapIndexAtBlockNumber: no bitmap update found for operatorId at block number"
26+
├── when any of the given operator has registered for the first time with the given registryCoordinator after the given blockNumber
27+
│ └── it should revert with "RegistryCoordinator.getQuorumBitmapIndexAtBlockNumber: no bitmap update found for operatorId at block number"
28+
├── when any of the given operator is completely deregistered with the given registryCoordinator at the given blockNumber
29+
│ └── it should revert with "RegistryCoordinator.getQuorumBitmapIndexAtBlockNumber: no bitmap update found for operatorId at block number"
30+
├── when any of the given quorumNumbers were not created at the time of the call
31+
│ └── it should revert with "StakeRegistry.getTotalStakeIndicesAtBlockNumber: quorum does not exist"
32+
├── when any of the given quorumNumbers were not created before or at the given blockNumber
33+
│ └── it should revert with "StakeRegistry.getTotalStakeIndicesAtBlockNumber: quorum has no stake history at blockNumber"
34+
└── otherwise
35+
└── it should return
36+
├── a list of the indices of the QuorumBitmapUpdates at the given blockNumber for the given nonSignerOperatorIds in the inputted quorumNumber order as the first argument
37+
├── a list of the indices of the ApkUpdates at the given blockNumber for each quorum in the inputted quorumNumber order as the second argument
38+
├── a list of the indices of the StakeUpdates at the given blockNumber for the total stake for each quorum in the inputted quorumNumber order as the third argument
39+
└── a list of (a list of the indices of the stakes of each operator in each of the quorums the operator was in at the blockNumber from lowest to greatest quorumNumber they were apart of) in the order of the inputted nonSigners

0 commit comments

Comments
 (0)