From f2f7598c0edcbef2a190595f835870c0b76af0cc Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Wed, 17 Oct 2018 14:19:18 -0700 Subject: asset data util tests --- packages/instant/test/util/asset_data.test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 packages/instant/test/util/asset_data.test.ts (limited to 'packages/instant/test') diff --git a/packages/instant/test/util/asset_data.test.ts b/packages/instant/test/util/asset_data.test.ts new file mode 100644 index 000000000..cf247142a --- /dev/null +++ b/packages/instant/test/util/asset_data.test.ts @@ -0,0 +1,17 @@ +import { assetDataUtil } from '../../src/util/asset_data'; + +const ZRX_ASSET_DATA = '0xf47261b0000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498'; + +describe('assetDataUtil', () => { + describe('bestNameForAsset', () => { + it('should return default string if assetData is undefined', () => { + expect(assetDataUtil.bestNameForAsset(undefined, 'xyz')).toEqual('xyz'); + }); + it('should return default string if assetData isnt found', () => { + expect(assetDataUtil.bestNameForAsset('fake', 'mah default')).toEqual('mah default'); + }); + it('should return ZRX for ZRX assetData', () => { + expect(assetDataUtil.bestNameForAsset(ZRX_ASSET_DATA, 'mah default')).toEqual('ZRX'); + }); + }); +}); -- cgit From 7b43cd14b305e3f01081e7ea7d0385966e4529be Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Wed, 17 Oct 2018 14:34:04 -0700 Subject: error test --- packages/instant/test/util/error.test.ts | 48 ++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 packages/instant/test/util/error.test.ts (limited to 'packages/instant/test') diff --git a/packages/instant/test/util/error.test.ts b/packages/instant/test/util/error.test.ts new file mode 100644 index 000000000..56f3a1e86 --- /dev/null +++ b/packages/instant/test/util/error.test.ts @@ -0,0 +1,48 @@ +import { AssetBuyerError } from '@0xproject/asset-buyer'; + +import { errorUtil } from '../../src/util/error'; + +const ZRX_ASSET_DATA = '0xf47261b0000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498'; + +describe('errorUtil', () => { + describe('errorFlasher', () => { + it('should return error and asset name for InsufficientAssetLiquidity', () => { + const insufficientAssetError = new Error(AssetBuyerError.InsufficientAssetLiquidity); + expect(errorUtil.errorDescription(insufficientAssetError, ZRX_ASSET_DATA).message).toEqual( + 'Not enough ZRX available', + ); + }); + it('should return error default name for InsufficientAssetLiquidity', () => { + const insufficientZrxError = new Error(AssetBuyerError.InsufficientZrxLiquidity); + expect(errorUtil.errorDescription(insufficientZrxError).message).toEqual( + 'Not enough of this asset available', + ); + }); + it('should return asset name for InsufficientAssetLiquidity', () => { + const insufficientZrxError = new Error(AssetBuyerError.InsufficientZrxLiquidity); + expect(errorUtil.errorDescription(insufficientZrxError, ZRX_ASSET_DATA).message).toEqual( + 'Not enough ZRX available', + ); + }); + it('should return unavailable error and asset name for StandardRelayerApiError', () => { + const standardRelayerError = new Error(AssetBuyerError.StandardRelayerApiError); + expect(errorUtil.errorDescription(standardRelayerError, ZRX_ASSET_DATA).message).toEqual( + 'ZRX is currently unavailable', + ); + }); + it('should return error for AssetUnavailable error', () => { + const assetUnavailableError = new Error( + `${AssetBuyerError.AssetUnavailable}: For assetData ${ZRX_ASSET_DATA}`, + ); + expect(errorUtil.errorDescription(assetUnavailableError, ZRX_ASSET_DATA).message).toEqual( + 'ZRX is currently unavailable', + ); + }); + it('should return default for AssetUnavailable error', () => { + const assetUnavailableError = new Error(`${AssetBuyerError.AssetUnavailable}: For assetData xyz`); + expect(errorUtil.errorDescription(assetUnavailableError, 'xyz').message).toEqual( + 'This asset is currently unavailable', + ); + }); + }); +}); -- cgit From 9f924e459c43c023e35ab7222cd9824cc0e67411 Mon Sep 17 00:00:00 2001 From: Jacob Evans Date: Thu, 18 Oct 2018 21:51:56 +1100 Subject: chore: change package org from 0xproject to 0x --- packages/instant/test/util/error.test.ts | 2 +- packages/instant/test/util/format.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/instant/test') diff --git a/packages/instant/test/util/error.test.ts b/packages/instant/test/util/error.test.ts index 56f3a1e86..78b742f06 100644 --- a/packages/instant/test/util/error.test.ts +++ b/packages/instant/test/util/error.test.ts @@ -1,4 +1,4 @@ -import { AssetBuyerError } from '@0xproject/asset-buyer'; +import { AssetBuyerError } from '@0x/asset-buyer'; import { errorUtil } from '../../src/util/error'; diff --git a/packages/instant/test/util/format.test.ts b/packages/instant/test/util/format.test.ts index 073b86b19..141df9275 100644 --- a/packages/instant/test/util/format.test.ts +++ b/packages/instant/test/util/format.test.ts @@ -1,5 +1,5 @@ -import { BigNumber } from '@0xproject/utils'; -import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import { BigNumber } from '@0x/utils'; +import { Web3Wrapper } from '@0x/web3-wrapper'; import { ethDecimals } from '../../src/constants'; import { format } from '../../src/util/format'; -- cgit