Commit fb27103f authored by smartcontracts's avatar smartcontracts Committed by GitHub

maint(ctb): clean up config check task (#3468)

Cleans up the config check task so it's slightly easier to maintain.
Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 515685f4
...@@ -5,15 +5,6 @@ import 'hardhat-deploy' ...@@ -5,15 +5,6 @@ import 'hardhat-deploy'
import { predeploys } from '../src' import { predeploys } from '../src'
const checkCode = async (provider: providers.JsonRpcProvider) => {
for (const [name, address] of Object.entries(predeploys)) {
const code = await provider.getCode(address)
if (code === '0x') {
throw new Error(`Missing code for ${name}`)
}
}
}
task('check-l2-config', 'Validate L2 config') task('check-l2-config', 'Validate L2 config')
.addParam( .addParam(
'l2ProviderUrl', 'l2ProviderUrl',
...@@ -22,69 +13,67 @@ task('check-l2-config', 'Validate L2 config') ...@@ -22,69 +13,67 @@ task('check-l2-config', 'Validate L2 config')
types.string types.string
) )
.setAction(async (args, hre) => { .setAction(async (args, hre) => {
const { l2ProviderUrl } = args const l2Provider = new providers.JsonRpcProvider(args.l2ProviderUrl)
const l2Provider = new providers.JsonRpcProvider(l2ProviderUrl)
await checkCode(l2Provider) const loadPredeploy = async (name: string): Promise<Contract> => {
const artifact = await hre.artifacts.readArtifact(name)
return new Contract(predeploys[name], artifact.abi, l2Provider)
}
const Artifact__L2CrossDomainMessenger = await hre.artifacts.readArtifact( const getContractAddress = async (name: string): Promise<string> => {
'L2CrossDomainMessenger' const deployment = await hre.deployments.get(name)
) return deployment.address
const Artifact__L2StandardBridge = await hre.artifacts.readArtifact( }
'L2StandardBridge'
)
const Artifact__OptimismMintableERC20Factory =
await hre.artifacts.readArtifact('OptimismMintableERC20Factory')
const L2CrossDomainMessenger = new Contract( // Verify that all predeploys have code.
predeploys.L2CrossDomainMessenger, // TODO: Actually check that the predeploys have the expected code.
Artifact__L2CrossDomainMessenger.abi, for (const [name, address] of Object.entries(predeploys)) {
l2Provider const code = await l2Provider.getCode(address)
) if (code === '0x') {
throw new Error(`Missing code for ${name}`)
}
}
const Deployment__L1CrossDomainMessenger = await hre.deployments.get( // Confirming that L2CrossDomainMessenger.otherMessenger() is set properly.
const L2CrossDomainMessenger = await loadPredeploy('L2CrossDomainMessenger')
const actualOtherMessenger = await getContractAddress(
'L1CrossDomainMessengerProxy' 'L1CrossDomainMessengerProxy'
) )
const otherMessenger = await L2CrossDomainMessenger.otherMessenger() const expectedOtherMessenger = await L2CrossDomainMessenger.otherMessenger()
if (otherMessenger !== Deployment__L1CrossDomainMessenger.address) { if (expectedOtherMessenger !== actualOtherMessenger) {
throw new Error( throw new Error(
`L2CrossDomainMessenger otherMessenger not set correctly. Got ${otherMessenger}, expected ${Deployment__L1CrossDomainMessenger.address}` `L2CrossDomainMessenger otherMessenger not set correctly. Got ${actualOtherMessenger}, expected ${actualOtherMessenger}`
) )
} }
const L2StandardBridge = new Contract( // Confirming that L2StandardBridge.messenger() is set properly.
predeploys.L2StandardBridge, const L2StandardBridge = await loadPredeploy('L2StandardBridge')
Artifact__L2StandardBridge.abi, const actualMessenger = await L2StandardBridge.messenger()
l2Provider const expectedMessenger = predeploys.L2CrossDomainMessenger
) if (expectedMessenger !== actualMessenger) {
const messenger = await L2StandardBridge.messenger()
if (messenger !== predeploys.L2CrossDomainMessenger) {
throw new Error( throw new Error(
`L2StandardBridge messenger not set correctly. Got ${messenger}, expected ${predeploys.L2CrossDomainMessenger}` `L2StandardBridge messenger not set correctly. Got ${actualMessenger}, expected ${expectedMessenger}`
) )
} }
const Deployment__L1StandardBridge = await hre.deployments.get( // Confirming that L2StandardBridge.otherBridge() is set properly.
'L1StandardBridgeProxy' const actualOtherBridge = await getContractAddress('L1StandardBridgeProxy')
) const expectedOtherBridge = await L2StandardBridge.otherBridge()
const otherBridge = await L2StandardBridge.otherBridge() if (expectedOtherBridge !== actualOtherBridge) {
if (otherBridge !== Deployment__L1StandardBridge.address) {
throw new Error( throw new Error(
`L2StandardBridge otherBridge not set correctly. Got ${otherBridge}, expected ${Deployment__L1StandardBridge.address}` `L2StandardBridge otherBridge not set correctly. Got ${actualMessenger}, expected ${expectedOtherBridge}`
) )
} }
const OptimismMintableERC20Factory = new Contract( // Confirming that OptimismMintableERC20Factory.bridge() is set properly.
predeploys.OptimismMintableERC20Factory, const OptimismMintableERC20Factory = await loadPredeploy(
Artifact__OptimismMintableERC20Factory.abi, 'OptimismMintableERC20Factory'
l2Provider
) )
const actualBridge = await OptimismMintableERC20Factory.bridge()
const bridge = await OptimismMintableERC20Factory.bridge() const expectedBridge = predeploys.L2StandardBridge
if (bridge !== predeploys.L2StandardBridge) { if (expectedBridge !== actualBridge) {
throw new Error( throw new Error(
`OptimismMintableERC20Factory bridge not set correctly. Got ${bridge}, expected ${predeploys.L2StandardBridge}` `OptimismMintableERC20Factory bridge not set correctly. Got ${actualBridge}, expected ${expectedBridge}`
) )
} }
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment