Skip to content

Commit

Permalink
feat: add tree and start on tests for op state ret (#140)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gpsanant authored Jan 12, 2024
1 parent bf7e07a commit 3d70abd
Show file tree
Hide file tree
Showing 4 changed files with 313 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/OperatorStateRetriever.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ contract OperatorStateRetriever {

// get the indices of the quorumBitmap updates for each of the operators in the nonSignerOperatorIds array
checkSignaturesIndices.nonSignerQuorumBitmapIndices = registryCoordinator.getQuorumBitmapIndicesAtBlockNumber(referenceBlockNumber, nonSignerOperatorIds);

// get the indices of the totalStake updates for each of the quorums in the quorumNumbers array
checkSignaturesIndices.totalStakeIndices = stakeRegistry.getTotalStakeIndicesAtBlockNumber(referenceBlockNumber, quorumNumbers);

Expand All @@ -130,6 +131,8 @@ contract OperatorStateRetriever {
checkSignaturesIndices.nonSignerQuorumBitmapIndices[i]
);

require(nonSignerQuorumBitmap != 0, "OperatorStateRetriever.getCheckSignaturesIndices: operator must be registered at blocknumber");

// if the operator was a part of the quorum and the quorum is a part of the provided quorumNumbers
if ((nonSignerQuorumBitmap >> uint8(quorumNumbers[quorumNumberIndex])) & 1 == 1) {
// get the index of the stake update for the operator at the given blocknumber and quorum number
Expand Down
1 change: 1 addition & 0 deletions src/StakeRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,7 @@ contract StakeRegistry is StakeRegistryStorage {
uint32[] memory indices = new uint32[](quorumNumbers.length);
for (uint256 i = 0; i < quorumNumbers.length; i++) {
uint8 quorumNumber = uint8(quorumNumbers[i]);
require(_quorumExists(quorumNumber), "StakeRegistry.getTotalStakeIndicesAtBlockNumber: quorum does not exist");
require(
_totalStakeHistory[quorumNumber][0].updateBlockNumber <= blockNumber,
"StakeRegistry.getTotalStakeIndicesAtBlockNumber: quorum has no stake history at blockNumber"
Expand Down
39 changes: 39 additions & 0 deletions test/tree/OperatorStateRetrieverUnit.tree
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.
└── OperatorStateRetriever tree (*** denotes that integration tests are needed to validate path)
├── when getOperatorState(IRegistryCoordinator,bytes32,uint32) is called
│ ├── when the given operator has never registered with the given registryCoordinator (their quorumBitmapHistory has length 0)
│ │ └── it should revert with "RegistryCoordinator.getQuorumBitmapIndicesAtBlockNumber: operator has no bitmap history at blockNumber"
│ └── when the given operator has registered for the first time with the given registryCoordinator
│ ├── after the given blockNumber
│ │ └── it should revert with "RegistryCoordinator.getQuorumBitmapIndicesAtBlockNumber: operator has no bitmap history at blockNumber"
│ └── before the given blockNumber
│ ├── and was not registered for any quorums at the given blockNumber
│ │ └── it should return (0, [])
│ └── and was registered for a set of quorums at the given blockNumber
│ └── it should return
└── the given operator's quorum bitmap at the given blockNumber as the first argument and
└── 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
├── when getOperatorState(IRegistryCoordinator,bytes memory,uint32) is called
│ ├── when at any of the given quorumNumbers were not created at the time of call
│ │ └── it should revert with "IndexRegistry._operatorCountAtBlockNumber: quorum does not exist"
│ ├── when at any of the given quorumNumbers were not created before or at the given blockNumber
│ │ └── it should revert with "IndexRegistry._operatorCountAtBlockNumber: quorum did not exist at given block number"
│ └── when the given quorumNumbers are created on the given registry registryCoordinator
│ └── 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
└── when getCheckSignaturesIndices is called
├── when any of the given nonSignerOperatorIds were never registered with the given registryCoordinator
│ └── it should revert with "RegistryCoordinator.getQuorumBitmapIndexAtBlockNumber: no bitmap update found for operatorId at block number"
├── when any of the given operator has registered for the first time with the given registryCoordinator after the given blockNumber
│ └── it should revert with "RegistryCoordinator.getQuorumBitmapIndexAtBlockNumber: no bitmap update found for operatorId at block number"
├── when any of the given operator is completely deregistered with the given registryCoordinator at the given blockNumber
│ └── it should revert with "RegistryCoordinator.getQuorumBitmapIndexAtBlockNumber: no bitmap update found for operatorId at block number"
├── when any of the given quorumNumbers were not created at the time of the call
│ └── it should revert with "StakeRegistry.getTotalStakeIndicesAtBlockNumber: quorum does not exist"
├── when any of the given quorumNumbers were not created before or at the given blockNumber
│ └── it should revert with "StakeRegistry.getTotalStakeIndicesAtBlockNumber: quorum has no stake history at blockNumber"
└── otherwise
└── it should return
├── 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
├── a list of the indices of the ApkUpdates at the given blockNumber for each quorum in the inputted quorumNumber order as the second argument
├── 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
└── 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
Loading

0 comments on commit 3d70abd

Please sign in to comment.