@avalabs/bridge-unified
Advanced tools
Comparing version 0.0.0-feat-unified-api-interface-20231127104332 to 0.0.0-feat-unified-api-interface-20231127130236
# @avalabs/unified-bridge | ||
## 0.0.0-feat-unified-api-interface-20231127104332 | ||
## 0.0.0-feat-unified-api-interface-20231127130236 | ||
@@ -5,0 +5,0 @@ ### Major Changes |
{ | ||
"name": "@avalabs/bridge-unified", | ||
"version": "0.0.0-feat-unified-api-interface-20231127104332", | ||
"version": "0.0.0-feat-unified-api-interface-20231127130236", | ||
"main": "dist/index.js", | ||
@@ -18,3 +18,3 @@ "type": "module", | ||
"@internal/tsup-config": "0.0.1", | ||
"eslint-config-custom": "0.0.0-feat-unified-api-interface-20231127104332" | ||
"eslint-config-custom": "0.0.0-feat-unified-api-interface-20231127130236" | ||
}, | ||
@@ -21,0 +21,0 @@ "scripts": { |
@@ -7,3 +7,5 @@ import { TokenType } from '../../../types/asset'; | ||
rpcUrl: 'https://source-chain/rpc', | ||
multicallAddress: '0x0000000000000000000000000000000000000007', | ||
utilityAddresses: { | ||
multicall: '0x0000000000000000000000000000000000000007', | ||
}, | ||
networkToken: { | ||
@@ -21,3 +23,5 @@ decimals: 18, | ||
rpcUrl: 'https://target-chain/rpc', | ||
multicallAddress: '0x0000000000000000000000000000000000000008', | ||
utilityAddresses: { | ||
multicall: '0x0000000000000000000000000000000000000008', | ||
}, | ||
networkToken: { | ||
@@ -24,0 +28,0 @@ decimals: 18, |
@@ -1,11 +0,26 @@ | ||
import { BridgeType, type BridgeService } from '../../types/bridge'; | ||
import { | ||
BridgeType, | ||
type BridgeService, | ||
type FeeParams, | ||
type TransferParams, | ||
type TrackingParams, | ||
} from '../../types/bridge'; | ||
import { Environment } from '../../types/environment'; | ||
import { ensureHasConfig } from '../../utils/ensure-config'; | ||
import { CCTP_CONFIG } from './__mocks__/config.mock'; | ||
import { cctpBridgeFactory } from './factory'; | ||
import { getAssets } from './handlers/get-assets'; | ||
import { getFees } from './handlers/get-fees'; | ||
import { trackTransfer } from './handlers/track-transfer'; | ||
import { transferAsset } from './handlers/transfer-asset'; | ||
import { getConfig } from './utils/config'; | ||
jest.mock('../../utils/client'); | ||
jest.mock('./utils/config'); | ||
jest.mock('../../utils/ensure-config'); | ||
jest.mock('./handlers/get-assets'); | ||
jest.mock('./handlers/get-fees'); | ||
jest.mock('./handlers/transfer-asset'); | ||
jest.mock('./handlers/track-transfer'); | ||
describe('cctp factory', () => { | ||
describe('CCTP factory', () => { | ||
let service: BridgeService; | ||
@@ -29,69 +44,31 @@ const environment = Environment.TEST; | ||
/* it('returns error while fetching assets if config is not available', async () => { | ||
await expect(service.getAssets()).rejects.toThrow('Config is not available'); | ||
}); | ||
describe('handlers', () => { | ||
it('calls ensureHasConfig correctly', async () => { | ||
await service.ensureHasConfig(); | ||
expect(ensureHasConfig).toHaveBeenCalledWith(service); | ||
}); | ||
it('returns the correct asset list', async () => { | ||
await service.updateConfig(); | ||
const assets = await service.getAssets(); | ||
it('calls ensureHasConfig correctly', async () => { | ||
await service.getAssets(); | ||
expect(getAssets).toHaveBeenCalledWith(service); | ||
}); | ||
expect(assets).toStrictEqual({ | ||
[SOURCE_CHAIN.chainId]: [ | ||
{ | ||
address: SOURCE_TOKEN_ADDRESS, | ||
name: 'USD Coin', | ||
symbol: 'USDC', | ||
decimals: 6, | ||
type: TokenType.ERC20, | ||
destinations: { | ||
[TARGET_CHAIN.chainId]: [BridgeType.CCTP], | ||
}, | ||
}, | ||
], | ||
[TARGET_CHAIN.chainId]: [ | ||
{ | ||
address: TARGET_TOKEN_ADDRESS, | ||
name: 'USD Coin', | ||
symbol: 'USDC', | ||
decimals: 6, | ||
type: TokenType.ERC20, | ||
destinations: { | ||
[SOURCE_CHAIN.chainId]: [BridgeType.CCTP], | ||
}, | ||
}, | ||
], | ||
it('calls getFees correctly', async () => { | ||
const feeParams = { foo: 'bar' } as unknown as FeeParams; | ||
await service.getFees(feeParams); | ||
expect(getFees).toHaveBeenCalledWith(service, feeParams); | ||
}); | ||
}); | ||
it('returns the correct fees', async () => { | ||
const getTransferDataSpy = jest.spyOn(transferData, 'getTransferData'); | ||
const amount = 1000000n; | ||
const feeAmountMock = 50000n; | ||
clientMock.readContract.mockResolvedValueOnce(feeAmountMock); | ||
it('calls transferAsset correctly', async () => { | ||
const transferAssetParams = { foo: 'bar' } as unknown as TransferParams; | ||
await service.transferAsset(transferAssetParams); | ||
expect(transferAsset).toHaveBeenCalledWith(service, transferAssetParams, environment); | ||
}); | ||
await service.updateConfig(); | ||
const params = { | ||
sourceChain: SOURCE_CHAIN, | ||
targetChain: TARGET_CHAIN, | ||
asset: BRIDGE_ASSET, | ||
amount, | ||
}; | ||
const fees = await service.getFees(params); | ||
expect(getTransferDataSpy).toHaveBeenCalledWith(params, service.config); | ||
expect(clientMock.readContract).toHaveBeenCalledWith({ | ||
address: SOURCE_ROUTER_ADDRESS, | ||
abi: TOKEN_ROUTER_ABI, | ||
functionName: 'calculateFee', | ||
args: [amount, 1], | ||
it('calls trackTransfer correctly', () => { | ||
const trackTransferParams = { foo: 'bar' } as unknown as TrackingParams; | ||
service.trackTransfer(trackTransferParams); | ||
expect(trackTransfer).toHaveBeenCalledWith(service, trackTransferParams); | ||
}); | ||
expect(fees).toStrictEqual({ | ||
// TODO | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
[BRIDGE_ASSET.address]: feeAmountMock, | ||
}); | ||
}); */ | ||
}); | ||
}); |
@@ -10,3 +10,2 @@ import type { AssetFeeMap, BridgeService, FeeParams } from '../../../types'; | ||
const { sourceChain, targetChain, asset, amount, provider } = params; | ||
const { sourceChainData, targetChainData, burnToken } = getTransferData( | ||
@@ -13,0 +12,0 @@ { sourceChain, targetChain, asset, amount }, |
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"verbatimModuleSyntax": false | ||
"verbatimModuleSyntax": false, | ||
"esModuleInterop": true | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
261050
52
2678