Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: improve tests cases in avsregistry/reader #307

Open
damiramirez opened this issue Feb 5, 2025 · 2 comments
Open

refactor: improve tests cases in avsregistry/reader #307

damiramirez opened this issue Feb 5, 2025 · 2 comments
Milestone

Comments

@damiramirez
Copy link

damiramirez commented Feb 5, 2025

We were previously testing the avsregistry/reader against Holesky. In a recent PR, the method that create avs_reader was modified to use Anvil. This change caused issues in tests related to methods with block_number.

I have added an assert error as a temporary fix for

  • test_get_operators_stake_in_quorums_at_block
  • test_get_operators_stake_in_quorums_at_block_operator_id
  • test_get_operators_stake_in_quorums_at_current_block
  • test_get_operators_stake_in_quorums_of_operator_at_current_block
  • test_get_operators_stake_in_quorums_of_operator_at_block

Example:

#[tokio::test]
    async fn test_get_operators_stake_in_quorums_at_block_operator_id() {
        let (_container, http_endpoint, _ws_endpoint) = start_anvil_container().await;
        let avs_reader = build_avs_registry_chain_reader(http_endpoint.clone()).await;

        let operator_id = U256::from_str(
            "35344093966194310405039483339636912150346494903629410125452342281826147822033",
        )
        .unwrap();

        // revert: RegistryCoordinator.getQuorumBitmapIndexAtBlockNumber: no bitmap update found for operatorId
        let operators_stake = avs_reader
            .get_operators_stake_in_quorums_at_block_operator_id(1245842, operator_id.into())
            .await;

        assert!(operators_stake.is_err());
    }

The goal is to create a more comprehensive test that ensures the function does not return an error and verifies that the returned value is correct.

@damiramirez
Copy link
Author

I was reviewing these cases, and it seems that the problem is with the _getQuorumBitmapIndexAtBlockNumber method from RegistryCoordinator. This method calls QuorumBitmapHistoryLib.getQuorumBitmapIndexAtBlockNumber.

 function getQuorumBitmapIndexAtBlockNumber(
        mapping(bytes32 => IRegistryCoordinator.QuorumBitmapUpdate[]) storage self,
        uint32 blockNumber,
        bytes32 operatorId
    ) internal view returns (uint32 index) {
        uint256 length = self[operatorId].length;

        // Traverse the operator's bitmap history in reverse, returning the first index
        // corresponding to an update made before or at `blockNumber`
        for (uint256 i = 0; i < length; i++) {
            index = uint32(length - i - 1);

            if (self[operatorId][index].updateBlockNumber <= blockNumber) {
                return index;
            }
        }

        revert(
            "RegistryCoordinator.getQuorumBitmapIndexAtBlockNumber: no bitmap update found for operatorId"
        );
    }

Since we didn’t create or update bitmaps for the operatorId in the test, the method throws a revert.

@damiramirez
Copy link
Author

This was fixed by making a better test setup. First the operator is created with register_operator_in_quorum_with_avs_registry_coordinator and then the methods are called

@MegaRedHand MegaRedHand added this to the SDK parity milestone Feb 6, 2025
MegaRedHand pushed a commit that referenced this issue Feb 7, 2025
### What Changed?
In `avsregistry/reader,` we are testing against Holesky. The idea is to
run tests locally against Anvil. The method that constructs `avs_reader`
has been modified.

When making the change, it generated a problem in the tests and so a
temporary fix was added. Related issue #307

### Reviewer Checklist

- [ ] New features are tested and documented
- [ ] PR updates the changelog with a description of changes
- [x] PR has one of the `changelog-X` labels (if applies)
- [ ] Code deprecates any old functionality before removing it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants