Skip to content

Commit

Permalink
Merge pull request OffchainLabs#72 from OffchainLabs/test-weth-reg
Browse files Browse the repository at this point in the history
Check that Weth gateways are registered in the deployment test
  • Loading branch information
gzeoneth authored Mar 5, 2024
2 parents c59eb4a + b2a9a46 commit d6f2e03
Showing 1 changed file with 58 additions and 9 deletions.
67 changes: 58 additions & 9 deletions test-e2e/tokenBridgeDeploymentTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,35 @@ describe('tokenBridge', () => {
UpgradeExecutorABI,
l1Provider
)
await checkL1UpgradeExecutorInitialization(l1UpgradeExecutor, rollupAddresses);
await checkL1UpgradeExecutorInitialization(
l1UpgradeExecutor,
rollupAddresses
)

const l2UpgradeExecutor = new ethers.Contract(
l2Deployment.upgradeExecutor,
UpgradeExecutorABI,
l2Provider
)
await checkL2UpgradeExecutorInitialization(l2UpgradeExecutor, rollupAddresses)
await checkL2UpgradeExecutorInitialization(
l2UpgradeExecutor,
rollupAddresses
)

await checkL1Ownership(l1Deployment, rollupAddresses)
await checkL2Ownership(l2Deployment, usingFeeToken)
await checkLogicContracts(usingFeeToken, l2Deployment)

// This should always be the last check, because WETH gateway registration is a
// separate step that should be done after token bridge is atomically deployed
if (!usingFeeToken) {
await checkWethGatewayIsRegistered(
L1WethGateway__factory.connect(l1Deployment.wethGateway, l1Provider),
L1GatewayRouter__factory.connect(l1Deployment.router, l1Provider),
L2WethGateway__factory.connect(l2Deployment.wethGateway, l2Provider),
L2GatewayRouter__factory.connect(l2Deployment.router, l2Provider)
)
}
})
})

Expand Down Expand Up @@ -296,9 +313,8 @@ async function checkL1WethGatewayInitialization(
rollupAddresses.inbox.toLowerCase()
)

expect((await l1WethGateway.l1Weth()).toLowerCase()).to.not.be.eq(
ethers.constants.AddressZero
)
const l1WethAddress = await l1WethGateway.l1Weth()
expect(l1WethAddress.toLowerCase()).to.not.be.eq(ethers.constants.AddressZero)

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

expect(await l1Executor.hasRole(adminRole, l1Executor.address)).to.be.true
expect(await l1Executor.hasRole(executorRole, rollupAddresses.rollupOwner)).to.be.true
expect(await l1Executor.hasRole(executorRole, rollupAddresses.rollupOwner)).to
.be.true
}

async function checkL2UpgradeExecutorInitialization(
Expand Down Expand Up @@ -447,9 +464,8 @@ async function checkL2WethGatewayInitialization(
l2Deployment.router.toLowerCase()
)

expect((await l2WethGateway.l1Weth()).toLowerCase()).to.not.be.eq(
ethers.constants.AddressZero
)
const l1WethAddress = await l2WethGateway.l1Weth()
expect(l1WethAddress.toLowerCase()).to.not.be.eq(ethers.constants.AddressZero)

expect((await l2WethGateway.l2Weth()).toLowerCase()).to.not.be.eq(
ethers.constants.AddressZero
Expand Down Expand Up @@ -595,6 +611,39 @@ async function checkLogicContracts(
}
}

async function checkWethGatewayIsRegistered(
l1WethGateway: L1WethGateway,
l1Router: L1GatewayRouter,
l2WethGateway: L2WethGateway,
l2Router: L2GatewayRouter
) {
console.log('checkWethGatewayIsRegistered')

const MSG =
'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.'

// check parent chain
const l1WethAddress = await l1WethGateway.l1Weth()
expect(await l1Router.l1TokenToGateway(l1WethAddress)).to.be.eq(
l1WethGateway.address,
MSG
)
expect(await l1Router.getGateway(l1WethAddress)).to.be.eq(
l1WethGateway.address,
MSG
)

// check child chain
expect(await l2Router.l1TokenToGateway(l1WethAddress)).to.be.eq(
l2WethGateway.address,
MSG
)
expect(await l2Router.getGateway(l1WethAddress)).to.be.eq(
l2WethGateway.address,
MSG
)
}

//// utils
async function _isUsingFeeToken(inbox: string, l1Provider: JsonRpcProvider) {
const bridge = await IInbox__factory.connect(inbox, l1Provider).bridge()
Expand Down

0 comments on commit d6f2e03

Please sign in to comment.