-
Notifications
You must be signed in to change notification settings - Fork 202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: add tests for isDepositMode #2031
Open
fionnachan
wants to merge
3
commits into
master
Choose a base branch
from
isDepositMode-tests
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+150
−3
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
121 changes: 121 additions & 0 deletions
121
packages/arb-token-bridge-ui/src/util/__tests__/isDepositMode.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,121 @@ | ||
import { registerCustomArbitrumNetwork } from '@arbitrum/sdk' | ||
|
||
import { isDepositMode } from '../isDepositMode' | ||
import { ChainId } from '../networks' | ||
import { orbitMainnets } from '../orbitChainsList' | ||
|
||
beforeAll(() => { | ||
const xaiMainnetChainId = 660279 | ||
|
||
const xaiMainnet = orbitMainnets[xaiMainnetChainId] | ||
|
||
if (!xaiMainnet) { | ||
throw new Error(`Could not find Xai Mainnet in the Orbit chains list.`) | ||
} | ||
|
||
registerCustomArbitrumNetwork(xaiMainnet) | ||
|
||
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('isDepositMode', () => { | ||
it('should return true for L1 source chain and L2 destination chain', () => { | ||
const result1 = isDepositMode({ | ||
sourceChainId: ChainId.Ethereum, | ||
destinationChainId: ChainId.ArbitrumOne | ||
}) | ||
expect(result1).toBe(true) | ||
|
||
const result2 = isDepositMode({ | ||
sourceChainId: ChainId.Ethereum, | ||
destinationChainId: ChainId.ArbitrumNova | ||
}) | ||
|
||
expect(result2).toBe(true) | ||
}) | ||
it('should return true for L2 source chain and L3 destination chain', () => { | ||
const result1 = isDepositMode({ | ||
sourceChainId: ChainId.ArbitrumOne, | ||
destinationChainId: 660279 // Xai | ||
}) | ||
expect(result1).toBe(true) | ||
|
||
const result2 = isDepositMode({ | ||
sourceChainId: ChainId.ArbitrumOne, | ||
destinationChainId: 1380012617 // RARI mainnet | ||
}) | ||
|
||
expect(result2).toBe(true) | ||
}) | ||
it('should return false for L2 source chain and L1 destination chain', () => { | ||
const result1 = isDepositMode({ | ||
sourceChainId: ChainId.ArbitrumOne, | ||
destinationChainId: ChainId.Ethereum | ||
}) | ||
expect(result1).toBe(false) | ||
|
||
const result2 = isDepositMode({ | ||
sourceChainId: ChainId.ArbitrumNova, | ||
destinationChainId: ChainId.Ethereum | ||
}) | ||
|
||
expect(result2).toBe(false) | ||
}) | ||
it('should return false for L3 source chain and L2 destination chain', () => { | ||
const result1 = isDepositMode({ | ||
sourceChainId: 1380012617, // RARI mainnet | ||
destinationChainId: ChainId.ArbitrumOne | ||
}) | ||
expect(result1).toBe(false) | ||
|
||
const result2 = isDepositMode({ | ||
sourceChainId: 660279, // Xai | ||
destinationChainId: ChainId.ArbitrumOne | ||
}) | ||
|
||
expect(result2).toBe(false) | ||
}) | ||
it('should return false for L1 source chain and L3 destination chain', () => { | ||
fionnachan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const result1 = isDepositMode({ | ||
sourceChainId: ChainId.Ethereum, | ||
destinationChainId: 1380012617 // RARI mainnet | ||
}) | ||
expect(result1).toBe(false) | ||
|
||
const result2 = isDepositMode({ | ||
sourceChainId: ChainId.Ethereum, | ||
destinationChainId: 660279 // Xai | ||
}) | ||
|
||
expect(result2).toBe(false) | ||
}) | ||
it('should return false for L3 source chain and L1 destination chain', () => { | ||
const result1 = isDepositMode({ | ||
sourceChainId: 1380012617, // RARI mainnet | ||
destinationChainId: ChainId.Ethereum | ||
}) | ||
expect(result1).toBe(false) | ||
|
||
const result2 = isDepositMode({ | ||
sourceChainId: 660279, // Xai | ||
destinationChainId: ChainId.Ethereum | ||
}) | ||
|
||
expect(result2).toBe(false) | ||
}) | ||
it('should return false for L2 source chain and L2 destination chain', () => { | ||
fionnachan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const result1 = isDepositMode({ | ||
sourceChainId: ChainId.ArbitrumOne, | ||
destinationChainId: ChainId.ArbitrumNova | ||
}) | ||
expect(result1).toBe(false) | ||
}) | ||
}) |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this PR, but it would be nice to have enum for chain ids somewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps we can generate enums from the orbit chains data json, but i think the original idea was to only keep core chain's ids as enum
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for this test at least, we could move the definition of the chain ids to the outer scope so we don't need to add comments every time.