-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
8b0554a
commit f597f2f
Showing
5 changed files
with
172 additions
and
35 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
30 changes: 0 additions & 30 deletions
30
packages/bridge-ui-v2/src/libs/bridge/getContractAddressBasedOnType.test.ts
This file was deleted.
Oops, something went wrong.
166 changes: 166 additions & 0 deletions
166
packages/bridge-ui-v2/src/libs/bridge/getContractAddressByType.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,166 @@ | ||
import { routingContractsMap } from '$bridgeConfig'; | ||
import { ContractType, type GetContractAddressType } from '$libs/bridge'; | ||
import { TokenType } from '$libs/token'; | ||
|
||
import { getContractAddressByType } from './getContractAddressByType'; | ||
|
||
const SRC_CHAIN_ID = 1; | ||
const DEST_CHAIN_ID = 2; | ||
|
||
vi.mock('$customToken', () => ({ customToken: [] })); | ||
|
||
vi.mock('$bridgeConfig', () => ({ | ||
routingContractsMap: { | ||
1: { | ||
2: { | ||
erc20VaultAddress: '0x00001', | ||
bridgeAddress: '0x00002', | ||
erc721VaultAddress: '0x00003', | ||
erc1155VaultAddress: '0x00004', | ||
crossChainSyncAddress: '0x00005', | ||
signalServiceAddress: '0x00006', | ||
}, | ||
}, | ||
2: { | ||
1: { | ||
erc20VaultAddress: '0x00007', | ||
bridgeAddress: '0x00008', | ||
erc721VaultAddress: '0x00009', | ||
erc1155VaultAddress: '0x00010', | ||
crossChainSyncAddress: '0x00011', | ||
signalServiceAddress: '0x00012', | ||
}, | ||
}, | ||
}, | ||
})); | ||
|
||
describe('getContractAddressBasedOnType', () => { | ||
it('should return the correct vault contract address based on contract type (ERC20)', () => { | ||
// Given | ||
const args: GetContractAddressType = { | ||
srcChainId: SRC_CHAIN_ID, | ||
destChainId: DEST_CHAIN_ID, | ||
tokenType: TokenType.ERC20, | ||
contractType: ContractType.VAULT, | ||
}; | ||
|
||
const expectedAddress = routingContractsMap[SRC_CHAIN_ID][DEST_CHAIN_ID].erc20VaultAddress; | ||
|
||
// When | ||
const address = getContractAddressByType(args); | ||
|
||
// Then | ||
expect(address).to.equal(expectedAddress); | ||
expect(address).not.toBeUndefined(); | ||
}); | ||
|
||
it('should return the correct vault contract address based on token type (ERC721)', () => { | ||
// Given | ||
const args: GetContractAddressType = { | ||
srcChainId: SRC_CHAIN_ID, | ||
destChainId: DEST_CHAIN_ID, | ||
tokenType: TokenType.ERC721, | ||
contractType: ContractType.VAULT, | ||
}; | ||
|
||
const expectedAddress = routingContractsMap[SRC_CHAIN_ID][DEST_CHAIN_ID].erc721VaultAddress; | ||
|
||
// When | ||
const address = getContractAddressByType(args); | ||
|
||
// Then | ||
expect(address).to.equal(expectedAddress); | ||
expect(address).not.toBeUndefined(); | ||
}); | ||
|
||
it('should return the correct vault contract address based on token type (ERC1155)', () => { | ||
// Given | ||
const args: GetContractAddressType = { | ||
srcChainId: SRC_CHAIN_ID, | ||
destChainId: DEST_CHAIN_ID, | ||
tokenType: TokenType.ERC1155, | ||
contractType: ContractType.VAULT, | ||
}; | ||
|
||
const expectedAddress = routingContractsMap[SRC_CHAIN_ID][DEST_CHAIN_ID].erc1155VaultAddress; | ||
|
||
// When | ||
const address = getContractAddressByType(args); | ||
|
||
// Then | ||
expect(address).to.equal(expectedAddress); | ||
expect(address).not.toBeUndefined(); | ||
}); | ||
|
||
it('should return the correct bridge contract address', () => { | ||
// Given | ||
const args: GetContractAddressType = { | ||
srcChainId: SRC_CHAIN_ID, | ||
destChainId: DEST_CHAIN_ID, | ||
contractType: ContractType.BRIDGE, | ||
}; | ||
|
||
const expectedAddress = routingContractsMap[SRC_CHAIN_ID][DEST_CHAIN_ID].bridgeAddress; | ||
|
||
// When | ||
const address = getContractAddressByType(args); | ||
|
||
// Then | ||
expect(address).to.equal(expectedAddress); | ||
expect(address).not.toBeUndefined(); | ||
}); | ||
|
||
it('should return the correct crosschain sync contract address', () => { | ||
// Given | ||
const args: GetContractAddressType = { | ||
srcChainId: SRC_CHAIN_ID, | ||
destChainId: DEST_CHAIN_ID, | ||
contractType: ContractType.CROSSCHAINSYNC, | ||
}; | ||
|
||
const expectedAddress = routingContractsMap[SRC_CHAIN_ID][DEST_CHAIN_ID].crossChainSyncAddress; | ||
|
||
// When | ||
const address = getContractAddressByType(args); | ||
|
||
// Then | ||
expect(address).to.equal(expectedAddress); | ||
expect(address).not.toBeUndefined(); | ||
}); | ||
|
||
it('should return the correct signalservice contract address', () => { | ||
// Given | ||
const args: GetContractAddressType = { | ||
srcChainId: SRC_CHAIN_ID, | ||
destChainId: DEST_CHAIN_ID, | ||
contractType: ContractType.SIGNALSERVICE, | ||
}; | ||
|
||
const expectedAddress = routingContractsMap[SRC_CHAIN_ID][DEST_CHAIN_ID].signalServiceAddress; | ||
|
||
// When | ||
const address = getContractAddressByType(args); | ||
|
||
// Then | ||
expect(address).to.equal(expectedAddress); | ||
expect(address).not.toBeUndefined(); | ||
}); | ||
|
||
it('should return the correct contract address for different configs', () => { | ||
// Given | ||
const args: GetContractAddressType = { | ||
srcChainId: DEST_CHAIN_ID, | ||
destChainId: SRC_CHAIN_ID, | ||
contractType: ContractType.SIGNALSERVICE, | ||
}; | ||
|
||
const expectedAddress = routingContractsMap[DEST_CHAIN_ID][SRC_CHAIN_ID].signalServiceAddress; | ||
|
||
// When | ||
const address = getContractAddressByType(args); | ||
|
||
// Then | ||
expect(address).to.equal(expectedAddress); | ||
expect(address).not.toBeUndefined(); | ||
}); | ||
}); |
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