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/test | |
parent | 37c5165319d5962aedc683c105df446ce62cd72f (diff) | |
download | dexon-0x-contracts-48e4452a0442acb992c204ca1fbec36df1a75d6d.tar dexon-0x-contracts-48e4452a0442acb992c204ca1fbec36df1a75d6d.tar.gz dexon-0x-contracts-48e4452a0442acb992c204ca1fbec36df1a75d6d.tar.bz2 dexon-0x-contracts-48e4452a0442acb992c204ca1fbec36df1a75d6d.tar.lz dexon-0x-contracts-48e4452a0442acb992c204ca1fbec36df1a75d6d.tar.xz dexon-0x-contracts-48e4452a0442acb992c204ca1fbec36df1a75d6d.tar.zst dexon-0x-contracts-48e4452a0442acb992c204ca1fbec36df1a75d6d.zip |
feat: add tests for assetUtils
Diffstat (limited to 'packages/instant/test')
-rw-r--r-- | packages/instant/test/util/asset.test.ts | 36 |
1 files changed, 29 insertions, 7 deletions
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); + }); + }); }); |