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 mock messengers #344

Merged
merged 4 commits into from
Nov 10, 2020
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
4 changes: 2 additions & 2 deletions packages/ovm-toolchain/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@eth-optimism/ovm-toolchain",
"version": "0.0.1-alpha.11",
"version": "0.0.1-alpha.12",
"description": "Wrappers for Ethereum dev tools",
"main": "build/index.js",
"private": true,
Expand Down Expand Up @@ -74,7 +74,7 @@
"web3": "^1.2.11"
},
"dependencies": {
"@eth-optimism/contracts": "^0.0.2-alpha.1",
"@eth-optimism/contracts": "^0.0.2-alpha.7",
"@eth-optimism/core-utils": "^0.0.1-alpha.30",
"@eth-optimism/ethereumjs-vm": "4.2.0-alpha.0",
"@nomiclabs/buidler": "^1.4.4",
Expand Down
47 changes: 28 additions & 19 deletions packages/ovm-toolchain/src/x-domain-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ export const initCrossDomainMessengers = async (
l1CrossDomainMessenger: any
l2CrossDomainMessenger: any
}> => {
const l1CrossDomainMessenger = await getContractFromDefinition(
const l2CrossDomainMessenger = await getContractFromDefinition(
ethers,
signer,
'MockL1CrossDomainMessenger',
[l2ToL1MessageDelay]
'mockOVM_CrossDomainMessenger',
[l1ToL2MessageDelay]
)

const l2CrossDomainMessenger = await getContractFromDefinition(
const l1CrossDomainMessenger = await getContractFromDefinition(
ethers,
signer,
'MockL2CrossDomainMessenger',
[l1ToL2MessageDelay]
'mockOVM_CrossDomainMessenger',
[l2ToL1MessageDelay]
)

await l1CrossDomainMessenger.setTargetMessengerAddress(
Expand All @@ -71,26 +71,35 @@ export const initCrossDomainMessengers = async (
}

/**
* Relays all messages to their respective targets.
* Relays all L2 to L1 messages to their respective L1 targets.
* @param provider Ethers provider with attached messengers.
*/
export const waitForCrossDomainMessages = async (
export const relayL2ToL1Messages = async (signer: any): Promise<void> => {
return relayXDomainMessages(true, signer)
}

/**
* Relays all L1 to L2 messages to their respective L2 targets.
* @param provider Ethers provider with attached messengers.
*/
export const relayL1ToL2Messages = async (signer: any): Promise<void> => {
return relayXDomainMessages(false, signer)
}

const relayXDomainMessages = async (
isL1: boolean,
signer: any
): Promise<void> => {
const l1CrossDomainMessenger = signer.provider.__l1CrossDomainMessenger
const l2CrossDomainMessenger = signer.provider.__l2CrossDomainMessenger

if (!l1CrossDomainMessenger || !l2CrossDomainMessenger) {
const messenger = isL1
? signer.provider.__l1CrossDomainMessenger
: signer.provider.__l2CrossDomainMessenger
if (!messenger) {
throw new Error(
'Messengers are not initialized. Please make sure to call initCrossDomainMessengers!'
)
}

while (await l1CrossDomainMessenger.hasNextMessage()) {
await l1CrossDomainMessenger.relayNextMessage()
}

while (await l2CrossDomainMessenger.hasNextMessage()) {
await l2CrossDomainMessenger.relayNextMessage()
}
do {
await messenger.relayNextMessage()
} while (await messenger.hasNextMessage())
}
27 changes: 0 additions & 27 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@
resolved "https://registry.yarnpkg.com/@ensdomains/resolver/-/resolver-0.2.4.tgz#c10fe28bf5efbf49bff4666d909aed0265efbc89"
integrity sha512-bvaTH34PMCbv6anRa9I/0zjLJgY4EuznbEMgbV77JBCQ9KNC46rzi0avuxpOfu+xDjPEtSFGqVEOr5GlUSGudA==

"@eth-optimism/contracts@^0.0.2-alpha.1":
version "0.0.2-alpha.2"
resolved "https://registry.yarnpkg.com/@eth-optimism/contracts/-/contracts-0.0.2-alpha.2.tgz#3b69c4d4055d508f13c7c30c930a514a36215ce4"
integrity sha512-5L+owINbxyDIQUCZo+TSFriD4MjXNI6aniUS3TV2PkE4svPesCdKJiz2cV0P28+AIrMxQ+wa+KofTywyo+ZihA==
dependencies:
ethers "5.0.0"

"@eth-optimism/contracts@^0.0.2-alpha.7":
version "0.0.2-alpha.7"
resolved "https://registry.yarnpkg.com/@eth-optimism/contracts/-/contracts-0.0.2-alpha.7.tgz#1d77b59f504ee94d9f2f46e0d4c01889ba8f9fd5"
Expand Down Expand Up @@ -93,26 +86,6 @@
ethers-v4 "npm:ethers@4"
ethers-v5 "npm:ethers@5.0.7"

"@eth-optimism/provider@^0.0.1-alpha.8":
version "0.0.1-alpha.8"
resolved "https://registry.yarnpkg.com/@eth-optimism/provider/-/provider-0.0.1-alpha.8.tgz#ce9eb56098947e5b04450f035bec4d3a9aed50a8"
integrity sha512-HTorbC5/VlO02eBBr0Iom3Dc/BxaFVGJ7m9PwW4xAxLQ2J1FtKAYH+DK7YsnYne2FlGrvZlN/q9zWwFTKrWmtQ==
dependencies:
"@eth-optimism/core-utils" "0.0.1-alpha.30"
"@ethersproject/abstract-provider" "^5.0.3"
"@ethersproject/abstract-signer" "^5.0.3"
"@ethersproject/bignumber" "^5.0.6"
"@ethersproject/bytes" "^5.0.4"
"@ethersproject/keccak256" "^5.0.3"
"@ethersproject/logger" "^5.0.5"
"@ethersproject/networks" "^5.0.3"
"@ethersproject/properties" "^5.0.3"
"@ethersproject/providers" "^5.0.7"
"@ethersproject/transactions" "^5.0.4"
"@ethersproject/wallet" "^5.0.3"
"@ethersproject/web" "^5.0.5"
bn.js "^5.1.3"

"@eth-optimism/rollup-contracts@^0.0.1-alpha.32":
version "0.0.1-alpha.37"
resolved "https://registry.yarnpkg.com/@eth-optimism/rollup-contracts/-/rollup-contracts-0.0.1-alpha.37.tgz#770403aebcfd6c1bb1e1940150617808186134e4"
Expand Down