-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82dccc5
commit b2c7fb4
Showing
7 changed files
with
259 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
packages/arb-token-bridge-ui/src/util/__tests__/getTransferMode.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
import { registerCustomArbitrumNetwork } from '@arbitrum/sdk' | ||
|
||
import { getTransferMode } from '../getTransferMode' | ||
import { ChainId } from '../networks' | ||
import { orbitMainnets } from '../orbitChainsList' | ||
|
||
beforeAll(() => { | ||
const popApexChainId = 70700 | ||
|
||
const popApex = orbitMainnets[popApexChainId] | ||
|
||
if (!popApex) { | ||
throw new Error(`Could not find Pop Apex in the Orbit chains list.`) | ||
} | ||
|
||
registerCustomArbitrumNetwork(popApex) | ||
|
||
const rariMainnetChainId = 1380012617 | ||
|
||
const rariMainnet = orbitMainnets[rariMainnetChainId] | ||
|
||
if (!rariMainnet) { | ||
throw new Error(`Could not find Rari Mainnet in the Orbit chains list.`) | ||
} | ||
|
||
registerCustomArbitrumNetwork(rariMainnet) | ||
}) | ||
|
||
describe('getTransferMode', () => { | ||
it('should return correctly for L1 source chain and L2 destination chain', () => { | ||
const result1 = getTransferMode({ | ||
sourceChainId: ChainId.Ethereum, | ||
destinationChainId: ChainId.ArbitrumOne | ||
}) | ||
expect(result1).toEqual({ | ||
isDepositMode: true, | ||
isWithdrawalMode: false, | ||
isTeleportMode: false | ||
}) | ||
|
||
const result2 = getTransferMode({ | ||
sourceChainId: ChainId.Ethereum, | ||
destinationChainId: ChainId.ArbitrumNova | ||
}) | ||
|
||
expect(result2).toEqual({ | ||
isDepositMode: true, | ||
isWithdrawalMode: false, | ||
isTeleportMode: false | ||
}) | ||
}) | ||
|
||
it('should return correctly for L2 source chain and L3 destination chain', () => { | ||
const result1 = getTransferMode({ | ||
sourceChainId: ChainId.ArbitrumOne, | ||
destinationChainId: 70700 // PopApex | ||
}) | ||
expect(result1).toEqual({ | ||
isDepositMode: true, | ||
isWithdrawalMode: false, | ||
isTeleportMode: false | ||
}) | ||
|
||
const result2 = getTransferMode({ | ||
sourceChainId: ChainId.ArbitrumOne, | ||
destinationChainId: 1380012617 // RARI mainnet | ||
}) | ||
|
||
expect(result2).toEqual({ | ||
isDepositMode: true, | ||
isWithdrawalMode: false, | ||
isTeleportMode: false | ||
}) | ||
}) | ||
|
||
it('should return correctly for L2 source chain and L1 destination chain', () => { | ||
const result1 = getTransferMode({ | ||
sourceChainId: ChainId.ArbitrumOne, | ||
destinationChainId: ChainId.Ethereum | ||
}) | ||
expect(result1).toEqual({ | ||
isDepositMode: false, | ||
isWithdrawalMode: true, | ||
isTeleportMode: false | ||
}) | ||
|
||
const result2 = getTransferMode({ | ||
sourceChainId: ChainId.ArbitrumNova, | ||
destinationChainId: ChainId.Ethereum | ||
}) | ||
|
||
expect(result2).toEqual({ | ||
isDepositMode: false, | ||
isWithdrawalMode: true, | ||
isTeleportMode: false | ||
}) | ||
}) | ||
|
||
it('should return correctly for L3 source chain and L2 destination chain', () => { | ||
const result1 = getTransferMode({ | ||
sourceChainId: 1380012617, // RARI mainnet | ||
destinationChainId: ChainId.ArbitrumOne | ||
}) | ||
expect(result1).toEqual({ | ||
isDepositMode: false, | ||
isWithdrawalMode: true, | ||
isTeleportMode: false | ||
}) | ||
|
||
const result2 = getTransferMode({ | ||
sourceChainId: 70700, // PopApex | ||
destinationChainId: ChainId.ArbitrumOne | ||
}) | ||
|
||
expect(result2).toEqual({ | ||
isDepositMode: false, | ||
isWithdrawalMode: true, | ||
isTeleportMode: false | ||
}) | ||
}) | ||
|
||
it('should return correctly for L1 source chain and L3 destination chain', () => { | ||
const result1 = getTransferMode({ | ||
sourceChainId: ChainId.Ethereum, | ||
destinationChainId: 1380012617 // RARI mainnet | ||
}) | ||
expect(result1).toEqual({ | ||
isDepositMode: false, | ||
isWithdrawalMode: false, | ||
isTeleportMode: true | ||
}) | ||
|
||
const result2 = getTransferMode({ | ||
sourceChainId: ChainId.Ethereum, | ||
destinationChainId: 70700 // PopApex | ||
}) | ||
|
||
expect(result2).toEqual({ | ||
isDepositMode: false, | ||
isWithdrawalMode: false, | ||
isTeleportMode: true | ||
}) | ||
}) | ||
|
||
it('should return correctly for L3 source chain and L1 destination chain', () => { | ||
expect(() => | ||
getTransferMode({ | ||
sourceChainId: 1380012617, // RARI mainnet | ||
destinationChainId: ChainId.Ethereum | ||
}) | ||
).toThrow(new Error('Unsupported source and destination chain pair.')) | ||
|
||
expect(() => | ||
getTransferMode({ | ||
sourceChainId: 70700, // PopApex | ||
destinationChainId: ChainId.Ethereum | ||
}) | ||
).toThrow(new Error('Unsupported source and destination chain pair.')) | ||
}) | ||
|
||
it('should throw error for L2 source chain and L2 destination chain', () => { | ||
expect(() => | ||
getTransferMode({ | ||
sourceChainId: ChainId.ArbitrumOne, | ||
destinationChainId: ChainId.ArbitrumNova | ||
}) | ||
).toThrow(new Error('Unsupported source and destination chain pair.')) | ||
|
||
expect(() => | ||
getTransferMode({ | ||
sourceChainId: ChainId.ArbitrumNova, | ||
destinationChainId: ChainId.ArbitrumOne | ||
}) | ||
).toThrow(new Error('Unsupported source and destination chain pair.')) | ||
}) | ||
}) |
Oops, something went wrong.