-
Notifications
You must be signed in to change notification settings - Fork 3.9k
feat(sdk): start using sdk in integration tests #2122
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@eth-optimism/integration-tests': patch | ||
| --- | ||
|
|
||
| Updates integration tests to start using SDK |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,20 @@ | ||
| /* Imports: External */ | ||
| import { Contract, ContractFactory } from 'ethers' | ||
| import { ethers } from 'hardhat' | ||
| import { applyL1ToL2Alias, awaitCondition } from '@eth-optimism/core-utils' | ||
| import { MessageDirection, MessageStatus } from '@eth-optimism/sdk' | ||
| import { | ||
| applyL1ToL2Alias, | ||
| awaitCondition, | ||
| sleep, | ||
| } from '@eth-optimism/core-utils' | ||
|
|
||
| /* Imports: Internal */ | ||
| import { expect } from './shared/setup' | ||
| import { Direction } from './shared/watcher-utils' | ||
| import { OptimismEnv } from './shared/env' | ||
| import { | ||
| DEFAULT_TEST_GAS_L1, | ||
| DEFAULT_TEST_GAS_L2, | ||
| envConfig, | ||
| sleep, | ||
| withdrawalTest, | ||
| } from './shared/utils' | ||
|
|
||
|
|
@@ -56,23 +59,35 @@ describe('Basic L1<>L2 Communication', async () => { | |
| const value = `0x${'77'.repeat(32)}` | ||
|
|
||
| // Send L2 -> L1 message. | ||
| const transaction = await env.l2Messenger.sendMessage( | ||
| L1SimpleStorage.address, | ||
| L1SimpleStorage.interface.encodeFunctionData('setValue', [value]), | ||
| 5000000, | ||
| const transaction = await env.messenger.sendMessage( | ||
| { | ||
| direction: MessageDirection.L2_TO_L1, | ||
| target: L1SimpleStorage.address, | ||
| message: L1SimpleStorage.interface.encodeFunctionData('setValue', [ | ||
| value, | ||
| ]), | ||
| }, | ||
| { | ||
| gasLimit: DEFAULT_TEST_GAS_L2, | ||
| overrides: { | ||
| gasLimit: DEFAULT_TEST_GAS_L2, | ||
| }, | ||
| } | ||
| ) | ||
| await transaction.wait() | ||
| await env.relayXDomainMessages(transaction) | ||
| await env.waitForXDomainTransaction(transaction, Direction.L2ToL1) | ||
|
|
||
| let status: MessageStatus | ||
| while (status !== MessageStatus.READY_FOR_RELAY) { | ||
|
||
| status = await env.messenger.getMessageStatus(transaction) | ||
| await sleep(1000) | ||
| } | ||
|
|
||
| await env.messenger.finalizeMessage(transaction) | ||
| await env.messenger.waitForMessageReceipt(transaction) | ||
|
|
||
| expect(await L1SimpleStorage.msgSender()).to.equal( | ||
| env.l1Messenger.address | ||
| env.messenger.contracts.l1.L1CrossDomainMessenger.address | ||
| ) | ||
| expect(await L1SimpleStorage.xDomainSender()).to.equal( | ||
| env.l2Wallet.address | ||
| await env.messenger.l2Signer.getAddress() | ||
| ) | ||
| expect(await L1SimpleStorage.value()).to.equal(value) | ||
| expect((await L1SimpleStorage.totalCount()).toNumber()).to.equal(1) | ||
|
|
@@ -85,25 +100,36 @@ describe('Basic L1<>L2 Communication', async () => { | |
| const value = `0x${'42'.repeat(32)}` | ||
|
|
||
| // Send L1 -> L2 message. | ||
| const transaction = await env.l1Messenger.sendMessage( | ||
| L2SimpleStorage.address, | ||
| L2SimpleStorage.interface.encodeFunctionData('setValue', [value]), | ||
| 5000000, | ||
| const transaction = await env.messenger.sendMessage( | ||
| { | ||
| direction: MessageDirection.L1_TO_L2, | ||
| target: L2SimpleStorage.address, | ||
| message: L2SimpleStorage.interface.encodeFunctionData('setValue', [ | ||
| value, | ||
| ]), | ||
| }, | ||
| { | ||
| gasLimit: DEFAULT_TEST_GAS_L1, | ||
| l2GasLimit: 5000000, | ||
| overrides: { | ||
| gasLimit: DEFAULT_TEST_GAS_L1, | ||
| }, | ||
| } | ||
| ) | ||
|
|
||
| await env.waitForXDomainTransaction(transaction, Direction.L1ToL2) | ||
| const receipt = await env.messenger.waitForMessageReceipt(transaction) | ||
|
|
||
| console.log(await env.messenger.l2Signer.getAddress()) | ||
| expect(receipt.transactionReceipt.status).to.equal(1) | ||
| expect(await L2SimpleStorage.msgSender()).to.equal( | ||
| env.l2Messenger.address | ||
| env.messenger.contracts.l2.L2CrossDomainMessenger.address | ||
| ) | ||
| expect(await L2SimpleStorage.txOrigin()).to.equal( | ||
| applyL1ToL2Alias(env.l1Messenger.address) | ||
| applyL1ToL2Alias( | ||
| env.messenger.contracts.l1.L1CrossDomainMessenger.address | ||
| ) | ||
| ) | ||
| expect(await L2SimpleStorage.xDomainSender()).to.equal( | ||
| env.l1Wallet.address | ||
| await env.messenger.l1Signer.getAddress() | ||
| ) | ||
| expect(await L2SimpleStorage.value()).to.equal(value) | ||
| expect((await L2SimpleStorage.totalCount()).toNumber()).to.equal(1) | ||
|
|
@@ -117,9 +143,10 @@ describe('Basic L1<>L2 Communication', async () => { | |
| const value = `0x${'42'.repeat(32)}` | ||
|
|
||
| // Send L1 -> L2 message. | ||
| const tx = await env.ctc | ||
| .connect(env.l1Wallet) | ||
| .enqueue( | ||
| const tx = | ||
| await env.messenger.contracts.l1.CanonicalTransactionChain.connect( | ||
| env.messenger.l1Signer | ||
| ).enqueue( | ||
| L2SimpleStorage.address, | ||
| 5000000, | ||
| L2SimpleStorage.interface.encodeFunctionData('setValueNotXDomain', [ | ||
|
|
@@ -129,78 +156,41 @@ describe('Basic L1<>L2 Communication', async () => { | |
| gasLimit: DEFAULT_TEST_GAS_L1, | ||
| } | ||
| ) | ||
|
|
||
| const receipt = await tx.wait() | ||
|
|
||
| const waitUntilBlock = | ||
| receipt.blockNumber + envConfig.DTL_ENQUEUE_CONFIRMATIONS | ||
| let currBlock = await env.l1Provider.getBlockNumber() | ||
| let currBlock = await env.messenger.l1Provider.getBlockNumber() | ||
| while (currBlock <= waitUntilBlock) { | ||
| const progress = | ||
| envConfig.DTL_ENQUEUE_CONFIRMATIONS - (waitUntilBlock - currBlock) | ||
| console.log( | ||
| `Waiting for ${progress}/${envConfig.DTL_ENQUEUE_CONFIRMATIONS} confirmations.` | ||
| ) | ||
| await sleep(5000) | ||
| currBlock = await env.l1Provider.getBlockNumber() | ||
| currBlock = await env.messenger.l1Provider.getBlockNumber() | ||
| } | ||
| console.log('Enqueue should be confirmed.') | ||
|
|
||
| await awaitCondition( | ||
| async () => { | ||
| const sender = await L2SimpleStorage.msgSender() | ||
| return sender === env.l1Wallet.address | ||
| return sender === (await env.messenger.l1Signer.getAddress()) | ||
| }, | ||
| 2000, | ||
| 60 | ||
| ) | ||
|
|
||
| // No aliasing when an EOA goes directly to L2. | ||
| expect(await L2SimpleStorage.msgSender()).to.equal(env.l1Wallet.address) | ||
| expect(await L2SimpleStorage.txOrigin()).to.equal(env.l1Wallet.address) | ||
| expect(await L2SimpleStorage.value()).to.equal(value) | ||
| expect((await L2SimpleStorage.totalCount()).toNumber()).to.equal(1) | ||
| }) | ||
|
|
||
| it('should have a receipt with a status of 1 for a successful message', async () => { | ||
|
||
| const value = `0x${'42'.repeat(32)}` | ||
|
|
||
| // Send L1 -> L2 message. | ||
| const transaction = await env.l1Messenger.sendMessage( | ||
| L2SimpleStorage.address, | ||
| L2SimpleStorage.interface.encodeFunctionData('setValue', [value]), | ||
| 5000000, | ||
| { | ||
| gasLimit: DEFAULT_TEST_GAS_L1, | ||
| } | ||
| ) | ||
| await transaction.wait() | ||
|
|
||
| const { remoteReceipt } = await env.waitForXDomainTransaction( | ||
| transaction, | ||
| Direction.L1ToL2 | ||
| ) | ||
|
|
||
| expect(remoteReceipt.status).to.equal(1) | ||
| }) | ||
|
|
||
| // SKIP: until we decide what should be done in this case | ||
| it.skip('should have a receipt with a status of 0 for a failed message', async () => { | ||
|
||
| // Send L1 -> L2 message. | ||
| const transaction = await env.l1Messenger.sendMessage( | ||
| L2Reverter.address, | ||
| L2Reverter.interface.encodeFunctionData('doRevert', []), | ||
| 5000000, | ||
| { | ||
| gasLimit: DEFAULT_TEST_GAS_L1, | ||
| } | ||
| expect(await L2SimpleStorage.msgSender()).to.equal( | ||
| await env.messenger.l1Signer.getAddress() | ||
| ) | ||
|
|
||
| const { remoteReceipt } = await env.waitForXDomainTransaction( | ||
| transaction, | ||
| Direction.L1ToL2 | ||
| expect(await L2SimpleStorage.txOrigin()).to.equal( | ||
| await env.messenger.l1Signer.getAddress() | ||
| ) | ||
|
|
||
| expect(remoteReceipt.status).to.equal(0) | ||
| expect(await L2SimpleStorage.value()).to.equal(value) | ||
| expect((await L2SimpleStorage.totalCount()).toNumber()).to.equal(1) | ||
| }) | ||
| }) | ||
| }) | ||
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.
Note to self: maybe worth having
sendMessageToL1andsendMessageToL2functions to avoid needing thedirectionparameter