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: deep stack call mocks removed #383

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open

Conversation

mani99brar
Copy link
Contributor

@mani99brar mani99brar commented Dec 16, 2024

PR-Codex overview

This PR focuses on enhancing the ArbToGnosis bridge functionality by adding a new method to retrieve call data and modifying the sendTxToL1 function to emit an event. It also updates test cases to utilize the new mock contract and ensure proper integration.

Detailed summary

  • Added getCallData function in VeaInboxArbToGnosisMock to encode call data.
  • Introduced L2toL1Transaction event in ArbSysMockWithBridge.
  • Modified sendTxToL1 to emit L2toL1Transaction and return a constant value.
  • Updated tests to use VeaInboxArbToGnosisMock instead of VeaInboxArbToGnosis.
  • Included hardcoded TICKET_ID in tests.
  • Adjusted snapshot emission expectations in tests to use TICKET_ID.
  • Refactored claim object creation for clarity in tests.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Introduced a new public function getCallData for retrieving encoded call data.
    • Added a new event L2toL1Transaction to log transactions from Layer 2 to Layer 1.
  • Bug Fixes

    • Updated sendTxToL1 functionality to emit the new event instead of interacting with the bridge.
  • Tests

    • Enhanced integration tests with a new mock contract and updated event assertions.
    • Refined logic for handling disputes and withdrawals in the test suite.

Copy link
Contributor

coderabbitai bot commented Dec 16, 2024

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

contracts/test/integration/ArbToGnosis.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: Failed to load parser '@typescript-eslint/parser' declared in 'contracts/.eslintrc.js': Cannot find module '@typescript-eslint/parser'
Require stack:

  • /contracts/.eslintrc.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
    at Function.resolve (node:internal/modules/helpers:145:19)
    at Object.resolve (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2346:46)
    at ConfigArrayFactory._loadParser (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3325:39)
    at ConfigArrayFactory._normalizeObjectConfigDataBody (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3099:43)
    at _normalizeObjectConfigDataBody.next ()
    at ConfigArrayFactory._normalizeObjectConfigData (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3040:20)
    at _normalizeObjectConfigData.next ()
    at ConfigArrayFactory.loadInDirectory (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2886:28)
    at CascadingConfigArrayFactory._loadConfigInAncestors (/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3871:46)

Walkthrough

This pull request introduces modifications to the Arbitrum to Gnosis bridge testing infrastructure. The changes focus on enhancing mock contracts for VeaInboxArbToGnosisMock and ArbSysMockWithBridge, adding new functionality for retrieving call data and simulating Layer 2 to Layer 1 transactions. The integration tests have been updated to incorporate these mock contracts, improving the testing approach for bridge-related interactions and dispute resolution scenarios.

Changes

File Change Summary
contracts/src/test/ArbToGnosis/VeaInboxArbToGnosisMock.sol Added getCallData function to retrieve encoded call data, modified sendSnapshot to use mockArbSys and include epoch validation
contracts/src/test/bridge-mocks/arbitrum/ArbSysMockWithBridge.sol Added L2toL1Transaction event, updated sendTxToL1 to emit event and return constant withdrawal ID
contracts/test/integration/ArbToGnosis.ts Replaced VeaInboxArbToGnosis with VeaInboxArbToGnosisMock, added BridgeMock, introduced TICKET_ID, updated dispute resolution simulation

Sequence Diagram

sequenceDiagram
    participant User
    participant VeaInboxMock
    participant MockArbSys
    participant Router

    User->>VeaInboxMock: sendSnapshot(epoch, claim)
    VeaInboxMock->>MockArbSys: sendTxToL1
    MockArbSys-->>VeaInboxMock: Generate ticket ID
    VeaInboxMock->>Router: Encode route call data
    VeaInboxMock->>VeaInboxMock: Emit SnapshotSent event
Loading

Possibly related PRs

Suggested labels

Package: Contracts

Suggested reviewers

  • jaybuidl
  • alcercu

Poem

🐰 Bridging worlds with mock and might,
Transactions dance in rabbit's light,
Epochs whisper, tickets take flight,
Code hops forward with testing delight,
A rabbit's journey of protocol height! 🌉

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request.


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 or @coderabbitai title 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

netlify bot commented Dec 16, 2024

Deploy Preview for veascan failed. Why did it fail? →

Name Link
🔨 Latest commit bbf6052
🔍 Latest deploy log https://app.netlify.com/sites/veascan/deploys/675fd7f97fce8b0008554353

@mani99brar mani99brar marked this pull request as ready for review December 16, 2024 07:34
@mani99brar mani99brar requested a review from jaybuidl as a code owner December 16, 2024 07:34
Copy link
Contributor

@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: 2

🧹 Nitpick comments (2)
contracts/test/integration/ArbToGnosis.ts (1)

422-432: Refactor repeated code into a helper function

The logic for getting call data and executing L1 messages is repeated across tests. To improve maintainability, consider abstracting this into a helper function.

Apply this diff to create a helper function:

+ async function executeL1Message(epoch: number, claim: any) {
+   const callData = await veaInbox.connect(bridger).getCallData(epoch, 100000, claim);
+   const routerAddress = await router.getAddress();
+   await bridgeMock.connect(bridger).executeL1Message(routerAddress, callData);
+ }

Then replace repeated code with:

- const callData = await veaInbox.connect(bridger).getCallData(epoch, 100000, claim);
- const routerAddress = await router.getAddress();
- await bridgeMock.connect(bridger).executeL1Message(routerAddress, callData);
+ await executeL1Message(epoch, claim);
contracts/src/test/bridge-mocks/arbitrum/ArbSysMockWithBridge.sol (1)

21-24: Handle unused parameter calldataForL1 in sendTxToL1

The calldataForL1 parameter is not used in the function. To avoid compiler warnings and clarify intent, consider prefixing it with an underscore or emitting it in the event.

Option 1 - Prefix with underscore:

- function sendTxToL1(address destination, bytes calldata calldataForL1) external payable returns (uint256) {
+ function sendTxToL1(address destination, bytes calldata _calldataForL1) external payable returns (uint256) {
    emit L2toL1Transaction(msg.sender, destination);
    return 1;
}

Option 2 - Include in the event:

- event L2toL1Transaction(address caller, address destination);
+ event L2toL1Transaction(address caller, address destination, bytes calldataForL1);

function sendTxToL1(address destination, bytes calldata calldataForL1) external payable returns (uint256) {
    emit L2toL1Transaction(msg.sender, destination, calldataForL1);
    return 1;
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5041531 and bbf6052.

📒 Files selected for processing (3)
  • contracts/src/test/ArbToGnosis/VeaInboxArbToGnosisMock.sol (1 hunks)
  • contracts/src/test/bridge-mocks/arbitrum/ArbSysMockWithBridge.sol (1 hunks)
  • contracts/test/integration/ArbToGnosis.ts (8 hunks)
🔇 Additional comments (9)
contracts/test/integration/ArbToGnosis.ts (7)

15-16: Imports for mock contracts are correctly added

The imports for BridgeMock and VeaInboxArbToGnosisMock are appropriately added to utilize the mock contracts in the integration tests.


28-29: Hardcoded TICKET_ID is acceptable for testing purposes

The hardcoded TICKET_ID simplifies event assertions in the tests and is suitable for the mock environment.


40-40: Updated veaInbox to use the mock contract

The veaInbox variable is now using VeaInboxArbToGnosisMock, which aligns with the introduction of the mock contract for testing.


46-46: Declared bridgeMock for bridge interactions in tests

The bridgeMock variable is introduced to simulate bridge interactions within the testing environment.


63-66: Simulated dispute resolution using getCallData and bridgeMock

The simulateDisputeResolution function now retrieves call data using veaInbox.getCallData and executes the L1 message via bridgeMock.executeL1Message, which correctly reflects the new mock setup.


120-120: Initialized bridgeMock with the correct contract instance

The bridgeMock variable is correctly assigned the BridgeMock contract instance for testing purposes.


420-420: Added event assertion for SnapshotSent with TICKET_ID

The test now asserts that the SnapshotSent event is emitted with the correct epoch and TICKET_ID, enhancing the verification of snapshot sending.

contracts/src/test/bridge-mocks/arbitrum/ArbSysMockWithBridge.sol (1)

16-16: Added L2toL1Transaction event for testing

The L2toL1Transaction event is introduced to simulate and test Layer 2 to Layer 1 transactions within the mock environment.

contracts/src/test/ArbToGnosis/VeaInboxArbToGnosisMock.sol (1)

40-42: Added getCallData function to retrieve encoded data

The getCallData function allows external callers to retrieve the encoded call data for IRouterToGnosis.route, facilitating testing without executing transactions.

contracts/test/integration/ArbToGnosis.ts Show resolved Hide resolved
contracts/test/integration/ArbToGnosis.ts Show resolved Hide resolved
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.

3 participants