-
Notifications
You must be signed in to change notification settings - Fork 270
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
base: main
Are you sure you want to change the base?
Interop testing tutorial #1654
Conversation
✅ Deploy Preview for docs-optimism ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
📝 WalkthroughWalkthroughThis 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 ( 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
Possibly related PRs
Suggested reviewers
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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 frontmattertitle
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 usingbytes4(keccak256("crossDomainMessageContext()"))
. ```solidity file=/public/...(AI_EN_LECTOR_MISSING_PUNCTUATION)
pages/interop/tutorials/unit-tests/hardhat.mdx (1)
2-6
: Use Title Case for frontmattertitle
Ensure the metadata title follows Title Case:- title: Interop and unit tests using Hardhat + title: Interop and Unit Tests Using Hardhatpublic/tutorials/setup-for-testing.sh (7)
7-13
: Guard directory changes and command failuresApply 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 consistencyInsert 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 inGreetingSender.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 definitionYou’ve defined
IL2ToL2CrossDomainMessenger
inline inGreeter.sol
but imported it inGreetingSender.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 setupThe
cd ..
andcd 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 contractsThe
hardhat.config.js
specifies Solidity0.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 inMockL2ToL2Messenger.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
📒 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:
- 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] ---
- 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] ---
- 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:
- Use sentence case, capitalizing only the first word.
- 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.
- 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>
There was a problem hiding this 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
📒 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:
- 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] ---
- 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] ---
- 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:
- Use sentence case, capitalizing only the first word.
- 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.
- 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.
TheInteropCallout
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 thefile=
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.
TheInteropCallout
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 thefile=
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.
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