Skip to content

Commit

Permalink
responds to pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
douglance committed Nov 30, 2023
1 parent 0b194c2 commit 49e7aea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
7 changes: 6 additions & 1 deletion src/lib/dataEntities/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,12 @@ export const Networks: Record<string, Chain> = {
}

const isParentChain = (chain: Chain): chain is ParentChain => {
return chain && 'partnerChainIDs' in chain
return (
chain &&
'partnerChainIDs' in chain &&
!!chain.partnerChainIDs &&
chain.partnerChainIDs.length > 0
)
}

const isChildChain = (chain: Chain): chain is ChildChain => {
Expand Down
26 changes: 15 additions & 11 deletions tests/unit/network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ describe('Network', () => {
const fetchErrorMessage =
'Network fetched successfully but the chain ID is invalid.'

it('Adds a custom Orbit chain', async function () {
it('adds a custom Orbit chain', async function () {
const arbOneNetwork = await getL2Network(arbOneId)

addCustomNetwork({
const mockCustomNetwork = {
customL2Network: {
// we partially copy Arbitrum One network because we only want to mimic a custom chain
...arbOneNetwork,
Expand All @@ -24,15 +24,19 @@ describe('Network', () => {
isCustom: true,
isOrbit: true,
},
})
} as const

addCustomNetwork(mockCustomNetwork)

expect(await getNetwork(mockOrbitChainId)).to.be.ok
})

it('Successfully fetches an L1 network with `getL1Network`', async function () {
it('successfully fetches an L1 network with `getL1Network`', async function () {
const network = await getL1Network(mainnetId)
expect(network.chainID, fetchErrorMessage).to.be.eq(mainnetId)
})

it('Fails to fetch an L2 network with `getL1Network`', async function () {
it('fails to fetch an L2 network with `getL1Network`', async function () {
let network
try {
network = await getL1Network(arbOneId)
Expand All @@ -48,12 +52,12 @@ describe('Network', () => {
}
})

it('Successfully fetches an L2 network with `getL2Network`', async function () {
it('successfully fetches an L2 network with `getL2Network`', async function () {
const network = await getL2Network(arbOneId)
expect(network.chainID, fetchErrorMessage).to.be.eq(arbOneId)
})

it('Fails to fetch an L1 network with `getL2Network`', async function () {
it('fails to fetch an L1 network with `getL2Network`', async function () {
let network
try {
network = await getL2Network(mainnetId)
Expand All @@ -69,12 +73,12 @@ describe('Network', () => {
}
})

it('Successfully fetches a parent chain with `getNetwork`', async function () {
it('successfully fetches a parent chain with `getNetwork`', async function () {
const parentChain = await getNetwork(arbOneId)
expect(parentChain.chainID, fetchErrorMessage).to.be.eq(arbOneId)
})

it('Fails to fetch an Orbit chain with `getNetwork`', async function () {
it('fails to fetch an Orbit chain with `getNetwork` because it is in the wrong layer', async function () {
let parentChain
try {
parentChain = await getNetwork(mockOrbitChainId, 1)
Expand All @@ -90,12 +94,12 @@ describe('Network', () => {
}
})

it('Successfully fetches an Orbit chain with `getNetwork`', async function () {
it('successfully fetches an Orbit chain with `getNetwork`', async function () {
const chain = await getNetwork(mockOrbitChainId)
expect(chain.chainID, fetchErrorMessage).to.be.eq(mockOrbitChainId)
})

it('Fails to fetch a parent chain with `getNetwork`', async function () {
it('fails to fetch a parent chain with `getNetwork` because it is the wrong layer', async function () {
let chain
try {
chain = await getNetwork(mainnetId, 2)
Expand Down

0 comments on commit 49e7aea

Please sign in to comment.