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

fix low-level connectiontolightclientmapping calculation in unit tests #213

Merged
merged 1 commit into from
Oct 22, 2024

Conversation

RnkSngh
Copy link
Collaborator

@RnkSngh RnkSngh commented Sep 26, 2024

thanks to @nicopernas for finding out that the low-level caluclation was incorrect in our test suite.

This pr fixes this, and also now actually tests that this calculation is working

Summary by CodeRabbit

  • Bug Fixes

    • Improved connection removal logic to ensure proper verification before and after deletion.
  • New Features

    • Updated connection-to-client ID mapping function to return an address instead of a numeric ID, enhancing clarity and functionality.
  • Chores

    • Adjusted constant value for better alignment with internal logic.

Copy link

coderabbitai bot commented Sep 26, 2024

Caution

Review failed

The head commit changed during the review from e00dda2 to 2768074.

Walkthrough

The changes involve modifications to two contracts: DispatcherRealProofMultiClient and Base. In the DispatcherRealProofMultiClient, assertions were added to ensure a connection exists before deletion and to confirm its removal. In the Base contract, a constant was updated, and a function's return type was changed from uint256 to address, along with adjustments to its internal logic for mapping connections to client IDs.

Changes

Files Change Summary
test/Dispatcher/Dispatcher.multiclient.sol Updated test_Dispatcher_removeConnection to add assertions for connection existence and successful removal.
test/utils/Dispatcher.base.t.sol Changed CONNECTION_TO_CLIENT_ID_STARTING_SLOT from 259 to 260 and modified _getConnectiontoClientIdMapping to return address instead of uint256, with updated internal logic for client ID mapping.

Poem

In the code where connections play,
A rabbit hops and clears the way.
With checks to see if links are there,
And mappings changed with utmost care.
A little tweak, a constant shift,
In the world of code, we find our gift! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
test/Dispatcher/Dispatcher.multiclient.sol (2)

92-93: Approve: Good addition of pre-condition check.

The added assertion improves the test by ensuring the initial state is as expected before proceeding with the connection removal. This helps to catch potential issues early and makes the test more robust.

Consider adding a comment explaining the purpose of this assertion, e.g.:

+        // Verify the initial state: ensure the connection exists and is mapped to the correct light client
         assertEq(_getConnectiontoClientIdMapping(connectionHops1[0]), address(opLightClient));

104-104: Approve: Improved assertion for connection removal.

The modified assertion correctly checks if the connection has been removed by verifying that the mapping now returns address(0). This change aligns with the expected behavior and provides a clear verification of the connection removal.

Consider adding a comment to explain the expected outcome:

+        // Verify the connection has been removed: mapping should return address(0)
         assertEq(_getConnectiontoClientIdMapping(connectionHops1[0]), address(0));
test/utils/Dispatcher.base.t.sol (1)

282-285: Add view modifier to _getConnectiontoClientIdMapping function

The function only reads from contract storage and does not modify any state. Adding the view modifier makes the function's intent clear and can lead to gas optimizations.

Apply this change to add the view modifier:

-function _getConnectiontoClientIdMapping(string memory connection) internal returns (address clientId) {
+function _getConnectiontoClientIdMapping(string memory connection) internal view returns (address clientId) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between e4f5184 and 26fe659.

📒 Files selected for processing (2)
  • test/Dispatcher/Dispatcher.multiclient.sol (2 hunks)
  • test/utils/Dispatcher.base.t.sol (2 hunks)
🔇 Additional comments (1)
test/Dispatcher/Dispatcher.multiclient.sol (1)

Line range hint 92-104: Overall improvement in test reliability.

The changes in this test function enhance its reliability by verifying both the initial state (connection exists) and the final state (connection removed) of the removeConnection operation. This aligns well with the PR objectives of fixing a low-level calculation and implementing tests.

To ensure consistency across the codebase, let's verify if similar improvements have been made in other test files:

This will help us identify if similar improvements have been made in other test files or if we need to consider applying this pattern more broadly.

✅ Verification successful

Verification Successful: Test Enhancements Applied Correctly.

The updated assertions in test/Dispatcher/Dispatcher.multiclient.sol effectively ensure the reliability of the removeConnection operation by verifying both the initial and final states. No similar assertions were found in other Solidity test files, indicating that the changes are appropriately localized.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for similar assertions in other test files

# Test: Search for similar assertions in other test files
rg --type solidity -g 'test/**/*.sol' -e 'assertEq.*getConnectiontoClientIdMapping.*address\(0\)' -e 'assertEq.*getConnectiontoClientIdMapping.*opLightClient'

Length of output: 193


Script:

#!/bin/bash
# Description: Check for similar assertions in other Solidity test files

# Search for assertions that verify connection mappings to address(0) or opLightClient
rg -g "*.sol" -e 'assertEq\s*\(\s*_getConnectiontoClientIdMapping\s*\(.*\),\s*address\(0\)\s*\)' -e 'assertEq\s*\(\s*_getConnectiontoClientIdMapping\s*\(.*\),\s*address\(opLightClient\)\s*\)'

Length of output: 457

test/utils/Dispatcher.base.t.sol Show resolved Hide resolved
@RnkSngh RnkSngh force-pushed the raunak/fix-connection-to-client-calculation branch 2 times, most recently from b64605c to 4883b75 Compare September 27, 2024 13:31
@RnkSngh RnkSngh force-pushed the raunak/fix-connection-to-client-calculation branch 2 times, most recently from ee3e789 to e00dda2 Compare October 22, 2024 15:28
@RnkSngh RnkSngh changed the title fix low-level connectiontolightclientmapping calculation fix low-level connectiontolightclientmapping calculation in unit tests Oct 22, 2024
@RnkSngh RnkSngh force-pushed the raunak/fix-connection-to-client-calculation branch from e00dda2 to 2768074 Compare October 22, 2024 15:30
@RnkSngh RnkSngh merged commit d2c9eae into main Oct 22, 2024
3 checks passed
@RnkSngh RnkSngh deleted the raunak/fix-connection-to-client-calculation branch October 22, 2024 15:34
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

Successfully merging this pull request may close these issues.

2 participants