diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-10-23 05:20:20 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-10-23 05:20:20 +0800 |
commit | 48e4452a0442acb992c204ca1fbec36df1a75d6d (patch) | |
tree | c4c47ba4585686a27d27f9665fa17dc424d3d824 /packages/instant | |
parent | 37c5165319d5962aedc683c105df446ce62cd72f (diff) | |
download | dexon-sol-tools-48e4452a0442acb992c204ca1fbec36df1a75d6d.tar.gz dexon-sol-tools-48e4452a0442acb992c204ca1fbec36df1a75d6d.tar.zst dexon-sol-tools-48e4452a0442acb992c204ca1fbec36df1a75d6d.zip |
feat: add tests for assetUtils
Diffstat (limited to 'packages/instant')
-rw-r--r-- | packages/instant/src/util/asset.ts | 3 | ||||
-rw-r--r-- | packages/instant/test/util/asset.test.ts | 36 |
2 files changed, 30 insertions, 9 deletions
diff --git a/packages/instant/src/util/asset.ts b/packages/instant/src/util/asset.ts index bf6cd663d..4e3b2b946 100644 --- a/packages/instant/src/util/asset.ts +++ b/packages/instant/src/util/asset.ts @@ -16,11 +16,10 @@ export const assetUtils = { }; }, getMetaDataOrThrow: (assetData: string, metaDataMap: ObjectMap<AssetMetaData>, network: Network): AssetMetaData => { - let mainnetAssetData: string | undefined; + let mainnetAssetData: string | undefined = assetData; if (network !== Network.Mainnet) { mainnetAssetData = assetUtils.getAssociatedAssetDataIfExists(assetData, network); } - mainnetAssetData = assetData; if (_.isUndefined(mainnetAssetData)) { throw new Error(ZeroExInstantError.AssetMetaDataNotAvailable); } diff --git a/packages/instant/test/util/asset.test.ts b/packages/instant/test/util/asset.test.ts index 9ca4a3d52..2c357d25c 100644 --- a/packages/instant/test/util/asset.test.ts +++ b/packages/instant/test/util/asset.test.ts @@ -1,16 +1,21 @@ -import { AssetProxyId } from '@0x/types'; +import { AssetData, AssetProxyId, ObjectMap } from '@0x/types'; -import { Asset } from '../../src/types'; +import { Asset, AssetMetaData, ERC20AssetMetaData, Network, ZeroExInstantError } from '../../src/types'; import { assetUtils } from '../../src/util/asset'; const ZRX_ASSET_DATA = '0xf47261b0000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498'; +const ZRX_ASSET_DATA_KOVAN = '0xf47261b00000000000000000000000002002d3812f58e35f0ea1ffbf80a75a38c32175fa'; +const ZRX_META_DATA: ERC20AssetMetaData = { + assetProxyId: AssetProxyId.ERC20, + symbol: 'zrx', + decimals: 18, +}; const ZRX_ASSET: Asset = { assetData: ZRX_ASSET_DATA, - metaData: { - assetProxyId: AssetProxyId.ERC20, - symbol: 'zrx', - decimals: 18, - }, + metaData: ZRX_META_DATA, +}; +const META_DATA_MAP: ObjectMap<AssetMetaData> = { + [ZRX_ASSET_DATA]: ZRX_META_DATA, }; describe('assetDataUtil', () => { @@ -22,4 +27,21 @@ describe('assetDataUtil', () => { expect(assetUtils.bestNameForAsset(ZRX_ASSET, 'mah default')).toEqual('ZRX'); }); }); + describe('getMetaDataOrThrow', () => { + it('should return the metaData for the supplied mainnet asset data', () => { + expect(assetUtils.getMetaDataOrThrow(ZRX_ASSET_DATA, META_DATA_MAP, Network.Mainnet)).toEqual( + ZRX_META_DATA, + ); + }); + it('should return the metaData for the supplied non-mainnet asset data', () => { + expect(assetUtils.getMetaDataOrThrow(ZRX_ASSET_DATA_KOVAN, META_DATA_MAP, Network.Kovan)).toEqual( + ZRX_META_DATA, + ); + }); + it('should throw if the metaData for the asset is not available', () => { + expect(() => + assetUtils.getMetaDataOrThrow('asset data we dont have', META_DATA_MAP, Network.Mainnet), + ).toThrowError(ZeroExInstantError.AssetMetaDataNotAvailable); + }); + }); }); |