aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2018-12-15 03:06:15 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2018-12-15 07:34:45 +0800
commitc3884dfa32d0d8292163892934d7f243e813590f (patch)
tree64f7aefad24f6e0889b22f9586a622e61814b108 /packages/instant
parenta3d93d17cdefc2258a9f08e6fc680df1fb2b8456 (diff)
downloaddexon-sol-tools-c3884dfa32d0d8292163892934d7f243e813590f.tar
dexon-sol-tools-c3884dfa32d0d8292163892934d7f243e813590f.tar.gz
dexon-sol-tools-c3884dfa32d0d8292163892934d7f243e813590f.tar.bz2
dexon-sol-tools-c3884dfa32d0d8292163892934d7f243e813590f.tar.lz
dexon-sol-tools-c3884dfa32d0d8292163892934d7f243e813590f.tar.xz
dexon-sol-tools-c3884dfa32d0d8292163892934d7f243e813590f.tar.zst
dexon-sol-tools-c3884dfa32d0d8292163892934d7f243e813590f.zip
More tests for assetBuyerErrorMessage
Diffstat (limited to 'packages/instant')
-rw-r--r--packages/instant/test/util/asset.test.ts41
1 files changed, 38 insertions, 3 deletions
diff --git a/packages/instant/test/util/asset.test.ts b/packages/instant/test/util/asset.test.ts
index fc4e4e2e4..c13424685 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, InsufficientAssetLiquidityError, BigNumber } 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,37 @@ 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', () => {
+ it('should return custom message for InsufficientAssetLiquidityError error 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 InsufficientAssetLiquidityError error 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 InsufficientAssetLiquidityError error 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 generic message for InsufficientAssetLiquidityError error 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',