diff --git a/packages/core/src/errors/customErrors.ts b/packages/core/src/errors/customErrors.ts deleted file mode 100644 index 1a74fae78..000000000 --- a/packages/core/src/errors/customErrors.ts +++ /dev/null @@ -1,17 +0,0 @@ -class SygmaSdkError extends Error { - constructor(message: string) { - super(message); - this.name = this.constructor.name; - } -} - -export class LiquidityError extends SygmaSdkError { - availableLiquidity: bigint; - - constructor(destinationLiquidity: bigint) { - super( - `Destination chain liquidity is too low to perform this transfer. Transfer is limited to ${destinationLiquidity.toString()}`, - ); - this.availableLiquidity = destinationLiquidity; - } -} diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 3a9512be5..13d7eeed9 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -1,6 +1,5 @@ export * from './baseTransfer.js'; export * from './config/config.js'; export * from './constants.js'; -export * from './errors/customErrors.js'; export * from './types.js'; export * from './utils.js'; diff --git a/packages/core/test/baseTransfer.test.ts b/packages/core/test/baseTransfer.test.ts new file mode 100644 index 000000000..f32a035fa --- /dev/null +++ b/packages/core/test/baseTransfer.test.ts @@ -0,0 +1,72 @@ +import { enableFetchMocks } from 'jest-fetch-mock'; +import { BaseTransfer, BaseTransferParams } from '../src/baseTransfer.js'; +import { ConfigUrl } from '../src/constants.js'; +import { Config, Environment, EvmResource, ResourceType } from '../src/index.js'; +import { mockedDevnetConfig } from './constants.js'; + +enableFetchMocks(); + +const TRANSFER_PARAMS: BaseTransferParams = { + source: 111, + destination: 111, + resource: '0x0000000000000000000000000000000000000000000000000000000000000000', + sourceAddress: '0x00', +}; + +class Transfer extends BaseTransfer { + constructor(params: BaseTransferParams, config: Config) { + super(params, config); + } +} + +describe('BaseTransfer', () => { + let config: Config; + + beforeAll(async () => { + jest.clearAllMocks(); + fetchMock.resetMocks(); + fetchMock.doMock(); + fetchMock.mockIf(ConfigUrl.DEVNET.toString(), JSON.stringify(mockedDevnetConfig)); + config = new Config(); + await config.init(Environment.DEVNET); + }); + + it('should be able to instantiate a transfer object', async () => { + const transfer = new Transfer(TRANSFER_PARAMS, config); + expect(transfer).toBeInstanceOf(Transfer); + }); + + it('should not be able to instantiate a transfer object with an invalid domain', async () => { + const config = new Config(); + await config.init(Environment.DEVNET); + + expect(() => new Transfer({ ...TRANSFER_PARAMS, destination: 54 }, config)).toThrow( + 'Domain configuration not found.', + ); + }); + + it('should be able to set resource', async () => { + const config = new Config(); + await config.init(Environment.DEVNET); + const transfer = new Transfer(TRANSFER_PARAMS, config); + + const resource: EvmResource = { + resourceId: '0x00', + caip19: 'caip:id', + type: ResourceType.FUNGIBLE, + address: '0x00', + }; + + transfer.setResource(resource); + expect(transfer.resource.caip19).toEqual(resource.caip19); + }); + + it('should be able to set destination domain', async () => { + const config = new Config(); + await config.init(Environment.DEVNET); + const transfer = new Transfer(TRANSFER_PARAMS, config); + + transfer.setDesinationDomain('ethereum:1'); + expect(transfer.destination).toBeTruthy(); + }); +}); diff --git a/packages/core/test/constants.ts b/packages/core/test/constants.ts index 09ad802ec..018f50405 100644 --- a/packages/core/test/constants.ts +++ b/packages/core/test/constants.ts @@ -76,5 +76,45 @@ export const mockedDevnetConfig = { }, ], }, + { + chainId: 222, + id: 221, + caipId: 'ethereum:1', + name: 'ethereum:1', + type: 'evm', + bridge: '0xb36C801f644908bAAe89b7C28ad57Af18638A6a9', + handlers: [ + { + type: 'erc20', + address: '0xAf2DB8059Bd69ba9Ac4c59D25de1C87931e62448', + }, + ], + parachainId: undefined, + nativeTokenSymbol: 'eth', + nativeTokenFullName: 'ether', + nativeTokenDecimals: 18, + blockConfirmations: 5, + startBlock: 7225328, + feeHandlers: [ + { + address: '0x81bbFC4aC5E731d9EAdb749a7e7A6E973CF7E399', + type: 'basic', + }, + { + address: '0xF5703Fcf2bfFC33625857D8ae8994b3260AA3c1f', + type: 'oracle', + }, + ], + resources: [ + { + resourceId: '0x0000000000000000000000000000000000000000000000000000000000000000', + caip19: 'caip19', + type: 'erc20', + address: '0x3D151A97A446C9ea6893038e7C0db73466f3f3af', + symbol: 'ERC20TST', + decimals: 18, + }, + ], + }, ], }; diff --git a/tsconfig.base.json b/tsconfig.base.json index e33324f76..eca1dada2 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -27,5 +27,12 @@ "ts-node": { "esm": true, "experimentalSpecifierResolution": "node" - } + }, + "references": [ + { "path": "packages/core" }, + { "path": "packages/evm" }, + { "path": "packages/substrate" }, + { "path": "packages/utils" } + ], + "exclude": ["**/node_modules/**"] }