Skip to content

Interop testing tutorial #1654

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

qbzzt
Copy link
Contributor

@qbzzt qbzzt commented Jun 8, 2025

Description

How to do unit tests on code that relies on interop, either in Forge or Hardhat.

Tests

None, I just verified the tests work.

Additional context

N/A

Metadata

N/A

Copy link

netlify bot commented Jun 8, 2025

Deploy Preview for docs-optimism ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 746e01d
🔍 Latest deploy log https://app.netlify.com/projects/docs-optimism/deploys/68485decc9376e000899d1f1
😎 Deploy Preview https://deploy-preview-1654--docs-optimism.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@qbzzt qbzzt marked this pull request as ready for review June 9, 2025 00:55
@qbzzt qbzzt requested a review from a team as a code owner June 9, 2025 00:55
Copy link
Contributor

coderabbitai bot commented Jun 9, 2025

📝 Walkthrough

Walkthrough

This change introduces a comprehensive set of documentation and setup resources for unit testing interoperability protocols, specifically focusing on cross-domain message passing using the Optimism Bedrock system. It adds a new landing page for interop unit test tutorials, detailed step-by-step guides for both Foundry and Hardhat frameworks, and a shell script that automates the setup of development and testing environments. The provided resources include Solidity contracts (Greeter, GreetingSender, MockL2ToL2Messenger), corresponding test files, and configuration files to facilitate cross-chain testing scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant Tester
    participant TestFramework as Foundry/Hardhat
    participant MockMessenger
    participant Greeter
    participant GreetingSender

    Tester->>TestFramework: Run test suite
    TestFramework->>MockMessenger: Deploy mock messenger
    TestFramework->>Greeter: Deploy Greeter with messenger address
    TestFramework->>GreetingSender: Deploy GreetingSender with Greeter address

    Note over Tester,TestFramework: Test sending a message
    TestFramework->>GreetingSender: Call setGreeting("Hello")
    GreetingSender->>MockMessenger: sendMessage(chainId, Greeter, data)
    MockMessenger-->>TestFramework: Emit SentMessage event

    Note over Tester,TestFramework: Test receiving a message
    TestFramework->>MockMessenger: Simulate crossDomainMessageSender/source
    MockMessenger->>Greeter: setGreeting("Hi") (as cross-domain)
    Greeter-->>TestFramework: Emit CrossDomainSetGreeting event
Loading

Possibly related PRs

  • Fixed the OptimismPortal address #1369: Adds modifications to the Greeter contract and introduces the CrossDomainSetGreeting event, which are directly utilized in the new unit testing tutorials and setup scripts for cross-domain messaging.

Suggested reviewers

  • krofax

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

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
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: 5

🧹 Nitpick comments (12)
pages/interop/tutorials/unit-tests.mdx (2)

20-23: Hyphenate "Interop-related tutorials"
Consider rewriting line 22 for clarity:

- Documentation covering Interop related tutorials.
+ Documentation covering Interop-related tutorials.

25-28: Use title case for Card titles
Buttons and link titles should follow Title Case. Update card titles as follows:

- <Card title="Interop unit tests in Foundry" ...
+ <Card title="Interop Unit Tests in Foundry" ...
- <Card title="Interop unit tests in Hardhat" ...
+ <Card title="Interop Unit Tests in Hardhat" ...
pages/interop/tutorials/unit-tests/foundry.mdx (2)

2-6: Use Title Case for frontmatter title
Page metadata titles should follow Title Case:

- title: Interop and unit tests using Foundry
+ title: Interop and Unit Tests Using Foundry

126-126: Correct verb agreement
Change "When the tested code receive a message" to:

- When the tested code receive a message...
+ When the tested code receives a message...
🧰 Tools
🪛 LanguageTool

[uncategorized] ~126-~126: A punctuation mark might be missing here.
Context: ...e calculate the selector directly using bytes4(keccak256("crossDomainMessageContext()")). ```solidity file=/public/...

(AI_EN_LECTOR_MISSING_PUNCTUATION)

pages/interop/tutorials/unit-tests/hardhat.mdx (1)

2-6: Use Title Case for frontmatter title
Ensure the metadata title follows Title Case:

- title: Interop and unit tests using Hardhat
+ title: Interop and Unit Tests Using Hardhat
public/tutorials/setup-for-testing.sh (7)

7-13: Guard directory changes and command failures

Apply the same error handling guard for subsequent cd commands.

-cd lib
+cd lib || exit 1
-cd ..
+cd .. || exit 1
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 9-9: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)


15-16: Ensure SPDX header formatting consistency

Insert a space after // for SPDX identifiers to adhere to the recommended format.

-cat > src/Greeter.sol <<EOF
-//SPDX-License-Identifier: MIT
+cat > src/Greeter.sol <<EOF
+// SPDX-License-Identifier: MIT

58-60: SPDX header formatting in GreetingSender.sol

Apply the same SPDX formatting fix in the GreetingSender.sol heredoc.

-cat > src/GreetingSender.sol <<EOF
-//SPDX-License-Identifier: MIT
+cat > src/GreetingSender.sol <<EOF
+// SPDX-License-Identifier: MIT

18-22: Unify messenger interface import vs inline definition

You’ve defined IL2ToL2CrossDomainMessenger inline in Greeter.sol but imported it in GreetingSender.sol. For consistency and DRY, import the interface directly from the @eth-optimism/contracts-bedrock package.

-cat > src/Greeter.sol <<EOF
-pragma solidity ^0.8.0;
-
-import { Predeploys } from "@eth-optimism/contracts-bedrock/src/libraries/Predeploys.sol";
-
-interface IL2ToL2CrossDomainMessenger {
-    function crossDomainMessageContext() external view returns (address sender_, uint256 source_);
-}
+cat > src/Greeter.sol <<EOF
+pragma solidity ^0.8.0;
+
+import { Predeploys } from "@eth-optimism/contracts-bedrock/src/libraries/Predeploys.sol";
+import { IL2ToL2CrossDomainMessenger } from "@eth-optimism/contracts-bedrock/src/L2/IL2ToL2CrossDomainMessenger.sol";

214-217: Add error guards to Hardhat project setup

The cd .. and cd hardhat commands should also be guarded to prevent silent failures.

-cd ..
+cd .. || exit 1
-mkdir hardhat
+mkdir hardhat
+cd hardhat || exit 1
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 216-216: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)


227-241: Align Hardhat Solidity version with contracts

The hardhat.config.js specifies Solidity 0.8.28, but your contracts use ^0.8.0 and ^0.8.20. For consistency and to avoid compiler conflicts, consider using a version that matches the highest pragma.

 module.exports = {
-  solidity: "0.8.28",
+  solidity: "0.8.20",

369-415: Fix typo in nonce comment in MockL2ToL2Messenger.sol

There's a small typo in the comment for the nonce variable.

-        uint256 nonce = 0xdead60a7;   // nonoce
+        uint256 nonce = 0xdead60a7;   // nonce
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 427afd2 and ebae0a5.

📒 Files selected for processing (6)
  • pages/interop/tutorials/unit-tests.mdx (1 hunks)
  • pages/interop/tutorials/unit-tests/_meta.json (1 hunks)
  • pages/interop/tutorials/unit-tests/foundry.mdx (1 hunks)
  • pages/interop/tutorials/unit-tests/hardhat.mdx (1 hunks)
  • public/tutorials/setup-for-testing.sh (1 hunks)
  • words.txt (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.mdx`: "ALWAYS review Markdown content THOROUGHLY with the following criteria: - First, check the frontmatter section at the top of the file: 1. For regular pages, ensure AL...

**/*.mdx: "ALWAYS review Markdown content THOROUGHLY with the following criteria:

  • First, check the frontmatter section at the top of the file:
    1. For regular pages, ensure ALL these fields are present and not empty:
    ---
    title: [non-empty]
    lang: [non-empty]
    description: [non-empty]
    topic: [non-empty]
    personas: [non-empty array]
    categories: [non-empty array]
    content_type: [valid type]
    ---
    1. For landing pages (index.mdx or files with ), only these fields are required:
    ---
    title: [non-empty]
    lang: [non-empty]
    description: [non-empty]
    topic: [non-empty]
    ---
    1. If any required fields are missing or empty, comment:
      'This file appears to be missing required metadata. Please check keywords.config.yaml for valid options and add the required fields manually. You can validate your changes by running:
    pnpm validate-metadata
    ```'
  • Use proper nouns in place of personal pronouns like 'We' and 'Our' to maintain consistency in communal documentation.
  • Avoid gender-specific language and use the imperative form.
  • Monitor capitalization for emphasis. Avoid using all caps, italics, or bold for emphasis.
  • Ensure proper nouns are capitalized in sentences.
  • Apply the Oxford comma.
  • Use proper title case for buttons, tab names, page names, and links. Sentence case should be used for body content and short phrases, even in links.
  • Use correct spelling and grammar at all times (IMPORTANT).
  • For H1, H2, and H3 headers:
    1. Use sentence case, capitalizing only the first word.
    2. Preserve the capitalization of proper nouns, technical terms, and acronyms as defined in the 'nouns.txt' file located in the root directory of the project.
    3. Do not automatically lowercase words that appear in the 'nouns.txt' file, regardless of their position in the header.
  • Flag any headers that seem to inconsistently apply these rules for manual review.
  • When reviewing capitalization, always refer to the 'nouns.txt' file for the correct capitalization of proper nouns and technical terms specific to the project.
    "
  • pages/interop/tutorials/unit-tests.mdx
  • pages/interop/tutorials/unit-tests/foundry.mdx
  • pages/interop/tutorials/unit-tests/hardhat.mdx
🪛 LanguageTool
pages/interop/tutorials/unit-tests/foundry.mdx

[grammar] ~25-~25: After ‘Most of’, you should use ‘the’ (“Most of the parts”) or simply say “Most parts”.
Context: ...# Interop and unit tests using Foundry Most of parts of the contracts can be [tested normall...

(MOST_SOME_OF_NNS)


[grammar] ~26-~26: The singular determiner ‘this’ may not agree with the plural noun ‘tutorials’. Did you mean “these”?
Context: ...ormally](/app-developers/testing-apps). This tutorials teaches you how to verify tha...

(THIS_NNS)


[grammar] ~27-~27: Consider using the singular form after the singular determiner “This”.
Context: ...ly](/app-developers/testing-apps). This tutorials teaches you how to verify that a messag...

(AGREEMENT_SENT_START)


[uncategorized] ~27-~27: This verb does not appear to agree with the subject. Consider using a different form.
Context: ...evelopers/testing-apps). This tutorials teaches you how to verify that a message has be...

(AI_EN_LECTOR_REPLACEMENT_VERB_AGREEMENT)


[uncategorized] ~126-~126: A punctuation mark might be missing here.
Context: ...e calculate the selector directly using bytes4(keccak256("crossDomainMessageContext()")). ```solidity file=/public/...

(AI_EN_LECTOR_MISSING_PUNCTUATION)

pages/interop/tutorials/unit-tests/hardhat.mdx

[grammar] ~25-~25: After ‘Most of’, you should use ‘the’ (“Most of the parts”) or simply say “Most parts”.
Context: ...# Interop and unit tests using Hardhat Most of parts of the contracts can be [tested normall...

(MOST_SOME_OF_NNS)


[grammar] ~26-~26: The singular determiner ‘this’ may not agree with the plural noun ‘tutorials’. Did you mean “these”?
Context: ...ormally](/app-developers/testing-apps). This tutorials teaches you how to verify tha...

(THIS_NNS)


[grammar] ~27-~27: Consider using the singular form after the singular determiner “This”.
Context: ...ly](/app-developers/testing-apps). This tutorials teaches you how to verify that a messag...

(AGREEMENT_SENT_START)


[grammar] ~117-~117: “Code” is a singular noun. It appears that the verb form is incorrect.
Context: ...9d584cea ``` When the tested code receive a message, these are the source chain a...

(PCT_SINGULAR_NOUN_PLURAL_VERB_AGREEMENT)


[style] ~149-~149: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...18ce8fead9bc8412e79303d026c16 ``` This is the code that first deploys `MockL2T...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

🪛 Shellcheck (0.10.0)
public/tutorials/setup-for-testing.sh

[warning] 5-5: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)


[warning] 9-9: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)


[warning] 216-216: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.

(SC2164)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules - docs-optimism
  • GitHub Check: Header rules - docs-optimism
  • GitHub Check: Pages changed - docs-optimism
🔇 Additional comments (2)
words.txt (1)

432-432: Addition of "unindexed" looks good
The new term complements the existing terminology and is correctly placed.

pages/interop/tutorials/unit-tests/_meta.json (1)

1-4: Metadata mapping is valid
The JSON correctly maps framework keys to display names and is well-formed.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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: 0

🧹 Nitpick comments (1)
pages/interop/tutorials/unit-tests/hardhat.mdx (1)

112-119: Fix singular verb agreement in explanation.
The sentence “When the tested code receive a message” should use “receives.”

Apply this diff:

- When the tested code receive a message, these are the source chain and address where it originates.
+ When the tested code receives a message, these are the source chain and address where it originates.
🧰 Tools
🪛 LanguageTool

[grammar] ~117-~117: “Code” is a singular noun. It appears that the verb form is incorrect.
Context: ...9d584cea ``` When the tested code receive a message, these are the source chain a...

(PCT_SINGULAR_NOUN_PLURAL_VERB_AGREEMENT)

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ebae0a5 and 746e01d.

📒 Files selected for processing (2)
  • pages/interop/tutorials/unit-tests/foundry.mdx (1 hunks)
  • pages/interop/tutorials/unit-tests/hardhat.mdx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.mdx`: "ALWAYS review Markdown content THOROUGHLY with the following criteria: - First, check the frontmatter section at the top of the file: 1. For regular pages, ensure AL...

**/*.mdx: "ALWAYS review Markdown content THOROUGHLY with the following criteria:

  • First, check the frontmatter section at the top of the file:
    1. For regular pages, ensure ALL these fields are present and not empty:
    ---
    title: [non-empty]
    lang: [non-empty]
    description: [non-empty]
    topic: [non-empty]
    personas: [non-empty array]
    categories: [non-empty array]
    content_type: [valid type]
    ---
    1. For landing pages (index.mdx or files with ), only these fields are required:
    ---
    title: [non-empty]
    lang: [non-empty]
    description: [non-empty]
    topic: [non-empty]
    ---
    1. If any required fields are missing or empty, comment:
      'This file appears to be missing required metadata. Please check keywords.config.yaml for valid options and add the required fields manually. You can validate your changes by running:
    pnpm validate-metadata
    ```'
  • Use proper nouns in place of personal pronouns like 'We' and 'Our' to maintain consistency in communal documentation.
  • Avoid gender-specific language and use the imperative form.
  • Monitor capitalization for emphasis. Avoid using all caps, italics, or bold for emphasis.
  • Ensure proper nouns are capitalized in sentences.
  • Apply the Oxford comma.
  • Use proper title case for buttons, tab names, page names, and links. Sentence case should be used for body content and short phrases, even in links.
  • Use correct spelling and grammar at all times (IMPORTANT).
  • For H1, H2, and H3 headers:
    1. Use sentence case, capitalizing only the first word.
    2. Preserve the capitalization of proper nouns, technical terms, and acronyms as defined in the 'nouns.txt' file located in the root directory of the project.
    3. Do not automatically lowercase words that appear in the 'nouns.txt' file, regardless of their position in the header.
  • Flag any headers that seem to inconsistently apply these rules for manual review.
  • When reviewing capitalization, always refer to the 'nouns.txt' file for the correct capitalization of proper nouns and technical terms specific to the project.
    "
  • pages/interop/tutorials/unit-tests/foundry.mdx
  • pages/interop/tutorials/unit-tests/hardhat.mdx
🪛 LanguageTool
pages/interop/tutorials/unit-tests/foundry.mdx

[uncategorized] ~126-~126: A punctuation mark might be missing here.
Context: ...e calculate the selector directly using bytes4(keccak256("crossDomainMessageContext()")). ```solidity file=/public/...

(AI_EN_LECTOR_MISSING_PUNCTUATION)

pages/interop/tutorials/unit-tests/hardhat.mdx

[grammar] ~117-~117: “Code” is a singular noun. It appears that the verb form is incorrect.
Context: ...9d584cea ``` When the tested code receive a message, these are the source chain a...

(PCT_SINGULAR_NOUN_PLURAL_VERB_AGREEMENT)


[style] ~149-~149: Three successive sentences begin with the same word. Consider rewording the sentence or use a thesaurus to find a synonym.
Context: ...18ce8fead9bc8412e79303d026c16 ``` This is the code that first deploys `MockL2T...

(ENGLISH_WORD_REPEAT_BEGINNING_RULE)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: Redirect rules - docs-optimism
  • GitHub Check: Header rules - docs-optimism
  • GitHub Check: Pages changed - docs-optimism
  • GitHub Check: pr-workflow
🔇 Additional comments (18)
pages/interop/tutorials/unit-tests/foundry.mdx (9)

1-17: Frontmatter metadata is complete and correct.
All required fields (title, lang, description, topic, personas, categories, content_type) are present, non-empty, and conform to guidelines.


19-22: Imports and WIP callout are correctly configured.
The InteropCallout component is imported and used appropriately.


24-29: Header and introduction are clear and grammatically sound.
The H1 is in sentence case, and the introductory sentences are concise and accurate.


30-36: Setup section is well-structured and follows style guidelines.
The instructions are clear, and header capitalization is correct.


37-38: Embedded script snippet is formatted correctly.
The MDX file embed uses the file= attribute as intended.


40-48: Test sending a message section is accurate and aligns with style rules.
Commands and links are properly formatted, and sentence case is used for headings.


50-90: Detailed explanation block is well-organized.
Nested <details> and code references are clear, and proper nouns are capitalized correctly.


91-100: Test receiving a message section follows guidelines.
Bullet list syntax and sentence case in headings are correct.


144-148: Next steps section uses imperative voice correctly.
Bullet entries are clear and actionable.

pages/interop/tutorials/unit-tests/hardhat.mdx (9)

1-17: Frontmatter metadata is complete and correct.
All required fields (title, lang, description, topic, personas, categories, content_type) are present, non-empty, and valid.


19-23: Imports and WIP callout are correctly configured.
The InteropCallout component is imported and rendered as expected.


24-29: Header and introduction are clear and grammatically sound.
The H1 is in sentence case, and the initial sentences are concise and consistent.


30-36: Setup section is well-structured and follows style guidelines.
Instructions are clear, and header capitalization is correct.


37-38: Embedded script snippet is formatted correctly.
The MDX file embed uses the file= attribute appropriately.


40-49: Test sending a message section is accurate and aligns with style rules.
Commands, code fences, and links are properly formatted; sentence case headings are used.


51-59: Context and details for the Hardhat test are well explained.
The narrative flows logically, and proper nouns are capitalized correctly.


92-101: Test receiving a message section follows guidelines.
Bullet syntax, nested lists, and sentence case headers are correct.


182-186: Next steps section uses imperative voice correctly.
Bullet entries are clear, actionable, and in sentence case.

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.

1 participant