Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tricky-bees-sneeze.md
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
1 change: 1 addition & 0 deletions integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@eth-optimism/contracts": "0.5.11",
"@eth-optimism/core-utils": "0.7.5",
"@eth-optimism/message-relayer": "0.2.15",
"@eth-optimism/sdk": "0.0.7",
"@ethersproject/abstract-provider": "^5.5.1",
"@ethersproject/providers": "^5.4.5",
"@ethersproject/transactions": "^5.4.0",
Expand Down
134 changes: 62 additions & 72 deletions integration-tests/test/basic-l1-l2-communication.spec.ts
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'

Expand Down Expand Up @@ -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(
Copy link
Contributor Author

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 sendMessageToL1 and sendMessageToL2 functions to avoid needing the direction parameter

{
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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm really happy with how simple this is

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)
Expand All @@ -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)
Expand All @@ -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', [
Expand All @@ -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 () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of making this a second test, we can just assert this inside of the above test which does exactly the same L1 to L2 message. Slightly speeds up the integration tests, which will add up as we start consolidating more tests.

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 () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this test because we should just handle this as part of 1.0. No need to have a dead test here for behavior we haven't specified.

// 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)
})
})
})
11 changes: 11 additions & 0 deletions integration-tests/test/shared/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TransactionResponse } from '@ethersproject/providers'
import { getContractFactory, predeploys } from '@eth-optimism/contracts'
import { Watcher } from '@eth-optimism/core-utils'
import { getMessagesAndProofsForL2Transaction } from '@eth-optimism/message-relayer'
import { CrossChainMessenger } from '@eth-optimism/sdk'

/* Imports: Internal */
import {
Expand Down Expand Up @@ -55,6 +56,7 @@ export class OptimismEnv {
l2Wallet: Wallet

// The providers
messenger: CrossChainMessenger
l1Provider: providers.JsonRpcProvider
l2Provider: providers.JsonRpcProvider
replicaProvider: providers.JsonRpcProvider
Expand All @@ -73,6 +75,7 @@ export class OptimismEnv {
this.watcher = args.watcher
this.l1Wallet = args.l1Wallet
this.l2Wallet = args.l2Wallet
this.messenger = args.messenger
this.l1Provider = args.l1Provider
this.l2Provider = args.l2Provider
this.replicaProvider = args.replicaProvider
Expand Down Expand Up @@ -126,6 +129,13 @@ export class OptimismEnv {
.connect(l2Wallet)
.attach(predeploys.OVM_L1BlockNumber)

const network = await l1Provider.getNetwork()
const messenger = new CrossChainMessenger({
l1SignerOrProvider: l1Wallet,
l2SignerOrProvider: l2Wallet,
l1ChainId: network.chainId,
})

return new OptimismEnv({
addressManager,
l1Bridge,
Expand All @@ -141,6 +151,7 @@ export class OptimismEnv {
watcher,
l1Wallet,
l2Wallet,
messenger,
l1Provider,
l2Provider,
verifierProvider,
Expand Down
3 changes: 3 additions & 0 deletions ops/docker/Dockerfile.integration-tests
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ COPY --from=builder /optimism/*.json /optimism/yarn.lock ./
COPY --from=builder /optimism/node_modules ./node_modules

# copy deps (would have been nice if docker followed the symlinks required)
COPY --from=builder /optimism/packages/sdk/package.json ./packages/sdk/package.json
COPY --from=builder /optimism/packages/sdk/dist ./packages/sdk/dist

COPY --from=builder /optimism/packages/core-utils/package.json ./packages/core-utils/package.json
COPY --from=builder /optimism/packages/core-utils/dist ./packages/core-utils/dist

Expand Down
1 change: 1 addition & 0 deletions ops/docker/Dockerfile.packages
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ RUN apt-get update -y && apt-get install -y git curl jq python3
# us to cache the installation steps
WORKDIR /opt/optimism
COPY *.json yarn.lock ./
COPY packages/sdk/package.json ./packages/sdk/package.json
COPY packages/core-utils/package.json ./packages/core-utils/package.json
COPY packages/common-ts/package.json ./packages/common-ts/package.json
COPY packages/contracts/package.json ./packages/contracts/package.json
Expand Down
14 changes: 6 additions & 8 deletions packages/sdk/src/utils/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,14 @@ export const CONTRACT_ADDRESSES: {
l2: DEFAULT_L2_CONTRACT_ADDRESSES,
},
// Hardhat local
// TODO: Get the actual addresses for this, temporary addresses here are fine for now until we
// start using this package in the integration tests.
31337: {
l1: {
AddressManager: '0x2F7E3cAC91b5148d336BbffB224B4dC79F09f01D',
L1CrossDomainMessenger: '0xEcC89b9EDD804850C4F343A278Be902be11AaF42',
L1StandardBridge: '0x73298186A143a54c20ae98EEE5a025bD5979De02',
StateCommitmentChain: '0x1afcA918eff169eE20fF8AB6Be75f3E872eE1C1A',
CanonicalTransactionChain: '0x2ebA8c4EfDB39A8Cd8f9eD65c50ec079f7CEBD81',
BondManager: '0xE5AE60bD6F8DEe4D0c2BC9268e23B92F1cacC58F',
AddressManager: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
L1CrossDomainMessenger: '0x8A791620dd6260079BF849Dc5567aDC3F2FdC318',
L1StandardBridge: '0x610178dA211FEF7D417bC0e6FeD39F05609AD788',
StateCommitmentChain: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9',
CanonicalTransactionChain: '0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9',
BondManager: '0x5FC8d32690cc91D4c39d9d3abcBD16989F875707',
},
l2: DEFAULT_L2_CONTRACT_ADDRESSES,
},
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/utils/merkle-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
toRpcHexString,
} from '@eth-optimism/core-utils'
import { MerkleTree } from 'merkletreejs'
import rlp from 'rlp'
import * as rlp from 'rlp'

/**
* Generates a Merkle proof (using the particular scheme we use within Lib_MerkleTree).
Expand Down