diff options
author | Fabio Berger <me@fabioberger.com> | 2019-01-11 07:47:57 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2019-01-11 07:47:57 +0800 |
commit | 583e690b7a028c85809a8be2c7afe3b65264adbe (patch) | |
tree | bc7ba2fe96833633455daaebf44d7382d0e20b7d /packages/instant/test | |
parent | a516b00a0397a567fd233bd955206d46321cc178 (diff) | |
parent | a5b7a351609a5e6689bb97990216153f64302462 (diff) | |
download | dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.tar dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.tar.gz dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.tar.bz2 dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.tar.lz dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.tar.xz dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.tar.zst dexon-sol-tools-583e690b7a028c85809a8be2c7afe3b65264adbe.zip |
Merge branch 'development' into fix/dev-tools-pages/finalTouches
* development: (49 commits)
upgrade to ddex api v3 (#1507)
Add new deployment related instructions to pipeline README (#1499)
feature: implement logging and friendly wallet name for Opera
Fix prettier
Add missing dependencies
Remove second yarn call
Add .gitkeep
Rename sol-trace-based-tools-common to sol-tracing-utils
Update packages/sol-trace/README.md
Update packages/sol-trace/CHANGELOG.json
Update packages/sol-trace-based-tools-common/src/source_maps.ts
Update packages/sol-trace-based-tools-common/CHANGELOG.json
Update packages/sol-profiler/CHANGELOG.json
Update packages/sol-coverage/CHANGELOG.json
Update packages/monorepo-scripts/src/test_installation.ts
chore: changelog update
fix: account for undefined errors in promisify, not only null
Clean up docs before publish
In README's, don't mention non-existent tests (#1497)
fix: use getBackendBaseUrl instead of hardcoded string
...
Diffstat (limited to 'packages/instant/test')
-rw-r--r-- | packages/instant/test/util/asset.test.ts | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/packages/instant/test/util/asset.test.ts b/packages/instant/test/util/asset.test.ts index fc4e4e2e4..402a556d5 100644 --- a/packages/instant/test/util/asset.test.ts +++ b/packages/instant/test/util/asset.test.ts @@ -1,5 +1,6 @@ -import { AssetBuyerError } from '@0x/asset-buyer'; +import { AssetBuyerError, BigNumber, InsufficientAssetLiquidityError } from '@0x/asset-buyer'; import { AssetProxyId, ObjectMap } from '@0x/types'; +import { Web3Wrapper } from '@0x/web3-wrapper'; import { Asset, AssetMetaData, ERC20Asset, ERC20AssetMetaData, Network, ZeroExInstantError } from '../../src/types'; import { assetUtils } from '../../src/util/asset'; @@ -19,6 +20,16 @@ const ZRX_ASSET: ERC20Asset = { const META_DATA_MAP: ObjectMap<AssetMetaData> = { [ZRX_ASSET_DATA]: ZRX_META_DATA, }; +const WAX_ASSET: ERC20Asset = { + assetData: '0xf47261b000000000000000000000000039bb259f66e1c59d5abef88375979b4d20d98022', + metaData: { + assetProxyId: AssetProxyId.ERC20, + decimals: 8, + primaryColor: '#EDB740', + symbol: 'wax', + name: 'WAX', + }, +}; describe('assetDataUtil', () => { describe('bestNameForAsset', () => { @@ -47,13 +58,39 @@ describe('assetDataUtil', () => { }); }); describe('assetBuyerErrorMessage', () => { - it('should return message for InsufficientAssetLiquidity', () => { + it('should return message for generic InsufficientAssetLiquidity error', () => { const insufficientAssetError = new Error(AssetBuyerError.InsufficientAssetLiquidity); expect(assetUtils.assetBuyerErrorMessage(ZRX_ASSET, insufficientAssetError)).toEqual( 'Not enough ZRX available', ); }); - it('should return message for InsufficientAssetLiquidity', () => { + describe('InsufficientAssetLiquidityError', () => { + it('should return custom message for token w/ 18 decimals', () => { + const amountAvailable = Web3Wrapper.toBaseUnitAmount(new BigNumber(20.059), 18); + expect( + assetUtils.assetBuyerErrorMessage(ZRX_ASSET, new InsufficientAssetLiquidityError(amountAvailable)), + ).toEqual('There are only 20.05 ZRX available to buy'); + }); + it('should return custom message for token w/ 18 decimals and small amount available', () => { + const amountAvailable = Web3Wrapper.toBaseUnitAmount(new BigNumber(0.01), 18); + expect( + assetUtils.assetBuyerErrorMessage(ZRX_ASSET, new InsufficientAssetLiquidityError(amountAvailable)), + ).toEqual('There are only 0.01 ZRX available to buy'); + }); + it('should return custom message for token w/ 8 decimals', () => { + const amountAvailable = Web3Wrapper.toBaseUnitAmount(new BigNumber(3), 8); + expect( + assetUtils.assetBuyerErrorMessage(WAX_ASSET, new InsufficientAssetLiquidityError(amountAvailable)), + ).toEqual('There are only 3 WAX available to buy'); + }); + it('should return generic message when amount available rounds to zero', () => { + const amountAvailable = Web3Wrapper.toBaseUnitAmount(new BigNumber(0.002), 18); + expect( + assetUtils.assetBuyerErrorMessage(ZRX_ASSET, new InsufficientAssetLiquidityError(amountAvailable)), + ).toEqual('Not enough ZRX available'); + }); + }); + it('should return message for InsufficientZrxLiquidity', () => { const insufficientZrxError = new Error(AssetBuyerError.InsufficientZrxLiquidity); expect(assetUtils.assetBuyerErrorMessage(ZRX_ASSET, insufficientZrxError)).toEqual( 'Not enough ZRX available', |