Skip to content

Commit d6f2e03

Browse files
authored
Merge pull request #72 from OffchainLabs/test-weth-reg
Check that Weth gateways are registered in the deployment test
2 parents c59eb4a + b2a9a46 commit d6f2e03

File tree

1 file changed

+58
-9
lines changed

1 file changed

+58
-9
lines changed

test-e2e/tokenBridgeDeploymentTest.ts

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,35 @@ describe('tokenBridge', () => {
174174
UpgradeExecutorABI,
175175
l1Provider
176176
)
177-
await checkL1UpgradeExecutorInitialization(l1UpgradeExecutor, rollupAddresses);
177+
await checkL1UpgradeExecutorInitialization(
178+
l1UpgradeExecutor,
179+
rollupAddresses
180+
)
178181

179182
const l2UpgradeExecutor = new ethers.Contract(
180183
l2Deployment.upgradeExecutor,
181184
UpgradeExecutorABI,
182185
l2Provider
183186
)
184-
await checkL2UpgradeExecutorInitialization(l2UpgradeExecutor, rollupAddresses)
187+
await checkL2UpgradeExecutorInitialization(
188+
l2UpgradeExecutor,
189+
rollupAddresses
190+
)
185191

186192
await checkL1Ownership(l1Deployment, rollupAddresses)
187193
await checkL2Ownership(l2Deployment, usingFeeToken)
188194
await checkLogicContracts(usingFeeToken, l2Deployment)
195+
196+
// This should always be the last check, because WETH gateway registration is a
197+
// separate step that should be done after token bridge is atomically deployed
198+
if (!usingFeeToken) {
199+
await checkWethGatewayIsRegistered(
200+
L1WethGateway__factory.connect(l1Deployment.wethGateway, l1Provider),
201+
L1GatewayRouter__factory.connect(l1Deployment.router, l1Provider),
202+
L2WethGateway__factory.connect(l2Deployment.wethGateway, l2Provider),
203+
L2GatewayRouter__factory.connect(l2Deployment.router, l2Provider)
204+
)
205+
}
189206
})
190207
})
191208

@@ -296,9 +313,8 @@ async function checkL1WethGatewayInitialization(
296313
rollupAddresses.inbox.toLowerCase()
297314
)
298315

299-
expect((await l1WethGateway.l1Weth()).toLowerCase()).to.not.be.eq(
300-
ethers.constants.AddressZero
301-
)
316+
const l1WethAddress = await l1WethGateway.l1Weth()
317+
expect(l1WethAddress.toLowerCase()).to.not.be.eq(ethers.constants.AddressZero)
302318

303319
expect((await l1WethGateway.l2Weth()).toLowerCase()).to.not.be.eq(
304320
ethers.constants.AddressZero
@@ -316,7 +332,8 @@ async function checkL1UpgradeExecutorInitialization(
316332
const executorRole = await l1Executor.EXECUTOR_ROLE()
317333

318334
expect(await l1Executor.hasRole(adminRole, l1Executor.address)).to.be.true
319-
expect(await l1Executor.hasRole(executorRole, rollupAddresses.rollupOwner)).to.be.true
335+
expect(await l1Executor.hasRole(executorRole, rollupAddresses.rollupOwner)).to
336+
.be.true
320337
}
321338

322339
async function checkL2UpgradeExecutorInitialization(
@@ -447,9 +464,8 @@ async function checkL2WethGatewayInitialization(
447464
l2Deployment.router.toLowerCase()
448465
)
449466

450-
expect((await l2WethGateway.l1Weth()).toLowerCase()).to.not.be.eq(
451-
ethers.constants.AddressZero
452-
)
467+
const l1WethAddress = await l2WethGateway.l1Weth()
468+
expect(l1WethAddress.toLowerCase()).to.not.be.eq(ethers.constants.AddressZero)
453469

454470
expect((await l2WethGateway.l2Weth()).toLowerCase()).to.not.be.eq(
455471
ethers.constants.AddressZero
@@ -595,6 +611,39 @@ async function checkLogicContracts(
595611
}
596612
}
597613

614+
async function checkWethGatewayIsRegistered(
615+
l1WethGateway: L1WethGateway,
616+
l1Router: L1GatewayRouter,
617+
l2WethGateway: L2WethGateway,
618+
l2Router: L2GatewayRouter
619+
) {
620+
console.log('checkWethGatewayIsRegistered')
621+
622+
const MSG =
623+
'WETH gateway is not registered in the router. After token bridge is successfully deployed, use setGateways function to register the WETH gateway in the router, then re-run this test.'
624+
625+
// check parent chain
626+
const l1WethAddress = await l1WethGateway.l1Weth()
627+
expect(await l1Router.l1TokenToGateway(l1WethAddress)).to.be.eq(
628+
l1WethGateway.address,
629+
MSG
630+
)
631+
expect(await l1Router.getGateway(l1WethAddress)).to.be.eq(
632+
l1WethGateway.address,
633+
MSG
634+
)
635+
636+
// check child chain
637+
expect(await l2Router.l1TokenToGateway(l1WethAddress)).to.be.eq(
638+
l2WethGateway.address,
639+
MSG
640+
)
641+
expect(await l2Router.getGateway(l1WethAddress)).to.be.eq(
642+
l2WethGateway.address,
643+
MSG
644+
)
645+
}
646+
598647
//// utils
599648
async function _isUsingFeeToken(inbox: string, l1Provider: JsonRpcProvider) {
600649
const bridge = await IInbox__factory.connect(inbox, l1Provider).bridge()

0 commit comments

Comments
 (0)