Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/lovely-mails-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/sdk': patch
---

Updates the CCM to throw a better error for missing or invalid chain IDs
14 changes: 12 additions & 2 deletions packages/sdk/src/cross-chain-messenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,18 @@ export class CrossChainMessenger implements ICrossChainMessenger {
}) {
this.l1SignerOrProvider = toSignerOrProvider(opts.l1SignerOrProvider)
this.l2SignerOrProvider = toSignerOrProvider(opts.l2SignerOrProvider)
this.l1ChainId = toNumber(opts.l1ChainId)
this.l2ChainId = toNumber(opts.l2ChainId)

try {
this.l1ChainId = toNumber(opts.l1ChainId)
} catch (err) {
throw new Error(`L1 chain ID is missing or invalid: ${opts.l1ChainId}`)
}

try {
this.l2ChainId = toNumber(opts.l2ChainId)
} catch (err) {
throw new Error(`L2 chain ID is missing or invalid: ${opts.l2ChainId}`)
}

this.depositConfirmationBlocks =
opts?.depositConfirmationBlocks !== undefined
Expand Down
26 changes: 26 additions & 0 deletions packages/sdk/test/cross-chain-messenger.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,32 @@ describe('CrossChainMessenger', () => {
})
})

describe('when given a bad L1 chain ID', () => {
it('should throw an error', () => {
expect(() => {
new CrossChainMessenger({
l1SignerOrProvider: ethers.provider,
l2SignerOrProvider: ethers.provider,
l1ChainId: undefined as any,
l2ChainId: L2ChainID.OPTIMISM,
})
}).to.throw('L1 chain ID is missing or invalid')
})
})

describe('when given a bad L2 chain ID', () => {
it('should throw an error', () => {
expect(() => {
new CrossChainMessenger({
l1SignerOrProvider: ethers.provider,
l2SignerOrProvider: ethers.provider,
l1ChainId: L1ChainID.MAINNET,
l2ChainId: undefined as any,
})
}).to.throw('L2 chain ID is missing or invalid')
})
})

describe('when no custom contract addresses are provided', () => {
describe('when given a known chain ID', () => {
it('should use the contract addresses for the known chain ID', () => {
Expand Down