diff options
Diffstat (limited to 'packages/instant/test')
-rw-r--r-- | packages/instant/test/components/zero_ex_instant.test.tsx | 15 | ||||
-rw-r--r-- | packages/instant/test/util/asset.test.ts | 114 | ||||
-rw-r--r-- | packages/instant/test/util/format.test.ts | 117 | ||||
-rw-r--r-- | packages/instant/test/util/time.test.ts | 48 |
4 files changed, 0 insertions, 294 deletions
diff --git a/packages/instant/test/components/zero_ex_instant.test.tsx b/packages/instant/test/components/zero_ex_instant.test.tsx deleted file mode 100644 index e373bb002..000000000 --- a/packages/instant/test/components/zero_ex_instant.test.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { configure, shallow } from 'enzyme'; -import * as Adapter from 'enzyme-adapter-react-16'; -import * as React from 'react'; - -configure({ adapter: new Adapter() }); - -// TODO: Write non-trivial tests. -// At time of writing we cannot render ZeroExInstant -// because we are looking for a provider on window. -// But in the future it will be dependency injected. -describe('<Test />', () => { - it('runs a test', () => { - shallow(<div />); - }); -}); diff --git a/packages/instant/test/util/asset.test.ts b/packages/instant/test/util/asset.test.ts deleted file mode 100644 index 402a556d5..000000000 --- a/packages/instant/test/util/asset.test.ts +++ /dev/null @@ -1,114 +0,0 @@ -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'; - -const ZRX_ASSET_DATA = '0xf47261b0000000000000000000000000e41d2489571d322189246dafa5ebde1f4699f498'; -const ZRX_ASSET_DATA_KOVAN = '0xf47261b00000000000000000000000002002d3812f58e35f0ea1ffbf80a75a38c32175fa'; -const ZRX_META_DATA: ERC20AssetMetaData = { - assetProxyId: AssetProxyId.ERC20, - symbol: 'zrx', - decimals: 18, - name: '0x', -}; -const ZRX_ASSET: ERC20Asset = { - assetData: ZRX_ASSET_DATA, - metaData: ZRX_META_DATA, -}; -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', () => { - it('should return default string if assetData is undefined', () => { - expect(assetUtils.bestNameForAsset(undefined, 'xyz')).toEqual('xyz'); - }); - it('should return ZRX for ZRX assetData', () => { - 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); - }); - }); - describe('assetBuyerErrorMessage', () => { - 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', - ); - }); - 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', - ); - }); - it('should message for StandardRelayerApiError', () => { - const standardRelayerError = new Error(AssetBuyerError.StandardRelayerApiError); - expect(assetUtils.assetBuyerErrorMessage(ZRX_ASSET, standardRelayerError)).toEqual( - 'ZRX is currently unavailable', - ); - }); - it('should return error for AssetUnavailable error', () => { - const assetUnavailableError = new Error( - `${AssetBuyerError.AssetUnavailable}: For assetData ${ZRX_ASSET_DATA}`, - ); - expect(assetUtils.assetBuyerErrorMessage(ZRX_ASSET, assetUnavailableError)).toEqual( - 'ZRX is currently unavailable', - ); - }); - }); -}); diff --git a/packages/instant/test/util/format.test.ts b/packages/instant/test/util/format.test.ts deleted file mode 100644 index 38bf356ec..000000000 --- a/packages/instant/test/util/format.test.ts +++ /dev/null @@ -1,117 +0,0 @@ -import { BigNumber } from '@0x/utils'; -import { Web3Wrapper } from '@0x/web3-wrapper'; - -import { ETH_DECIMALS } from '../../src/constants'; -import { format } from '../../src/util/format'; - -const BIG_NUMBER_ONE = new BigNumber(1); -const BIG_NUMBER_DECIMAL = new BigNumber(0.432414); -const BIG_NUMBER_IRRATIONAL = new BigNumber(5.3014059295032); -const ONE_ETH_IN_BASE_UNITS = Web3Wrapper.toBaseUnitAmount(BIG_NUMBER_ONE, ETH_DECIMALS); -const DECIMAL_ETH_IN_BASE_UNITS = Web3Wrapper.toBaseUnitAmount(BIG_NUMBER_DECIMAL, ETH_DECIMALS); -const IRRATIONAL_ETH_IN_BASE_UNITS = Web3Wrapper.toBaseUnitAmount(BIG_NUMBER_IRRATIONAL, ETH_DECIMALS); -const BIG_NUMBER_FAKE_ETH_USD_PRICE = new BigNumber(2.534); - -describe('format', () => { - describe('ethBaseAmount', () => { - it('converts 1 ETH in base units to the string `1 ETH`', () => { - expect(format.ethBaseUnitAmount(ONE_ETH_IN_BASE_UNITS)).toBe('1 ETH'); - }); - it('converts .432414 ETH in base units to the string `.4324 ETH`', () => { - expect(format.ethBaseUnitAmount(DECIMAL_ETH_IN_BASE_UNITS)).toBe('0.4324 ETH'); - }); - it('converts 5.3014059295032 ETH in base units to the string `5.301 ETH`', () => { - expect(format.ethBaseUnitAmount(IRRATIONAL_ETH_IN_BASE_UNITS)).toBe('5.301 ETH'); - }); - it('returns defaultText param when ethBaseAmount is not defined', () => { - const defaultText = 'defaultText'; - expect(format.ethBaseUnitAmount(undefined, 4, defaultText)).toBe(defaultText); - }); - it('it allows for configurable decimal places', () => { - expect(format.ethBaseUnitAmount(DECIMAL_ETH_IN_BASE_UNITS, 2)).toBe('0.43 ETH'); - }); - }); - describe('ethUnitAmount', () => { - it('converts BigNumber(1) to the string `1 ETH`', () => { - expect(format.ethUnitAmount(BIG_NUMBER_ONE)).toBe('1 ETH'); - }); - it('converts BigNumer(.432414) to the string `.4324 ETH`', () => { - expect(format.ethUnitAmount(BIG_NUMBER_DECIMAL)).toBe('0.4324 ETH'); - }); - it('converts BigNumber(5.3014059295032) to the string `5.301 ETH`', () => { - expect(format.ethUnitAmount(BIG_NUMBER_IRRATIONAL)).toBe('5.301 ETH'); - }); - it('shows 1 significant digit when rounded amount would be 0', () => { - expect(format.ethUnitAmount(new BigNumber(0.00003))).toBe('0.00003 ETH'); - expect(format.ethUnitAmount(new BigNumber(0.000034))).toBe('0.00003 ETH'); - expect(format.ethUnitAmount(new BigNumber(0.000035))).toBe('0.00004 ETH'); - }); - it('shows < 0.00001 when hits threshold', () => { - expect(format.ethUnitAmount(new BigNumber(0.000011))).toBe('0.00001 ETH'); - expect(format.ethUnitAmount(new BigNumber(0.00001))).toBe('0.00001 ETH'); - expect(format.ethUnitAmount(new BigNumber(0.000009))).toBe('< 0.00001 ETH'); - expect(format.ethUnitAmount(new BigNumber(0.0000000009))).toBe('< 0.00001 ETH'); - expect(format.ethUnitAmount(new BigNumber(0))).toBe('0 ETH'); - }); - it('returns defaultText param when ethUnitAmount is not defined', () => { - const defaultText = 'defaultText'; - expect(format.ethUnitAmount(undefined, 4, defaultText)).toBe(defaultText); - expect(format.ethUnitAmount(BIG_NUMBER_ONE, 4, defaultText)).toBe('1 ETH'); - }); - it('it allows for configurable decimal places', () => { - expect(format.ethUnitAmount(BIG_NUMBER_DECIMAL, 2)).toBe('0.43 ETH'); - }); - }); - describe('ethBaseAmountInUsd', () => { - it('correctly formats 1 ETH to usd according to some price', () => { - expect(format.ethBaseUnitAmountInUsd(ONE_ETH_IN_BASE_UNITS, BIG_NUMBER_FAKE_ETH_USD_PRICE)).toBe('$2.53'); - }); - it('correctly formats .432414 ETH to usd according to some price', () => { - expect(format.ethBaseUnitAmountInUsd(DECIMAL_ETH_IN_BASE_UNITS, BIG_NUMBER_FAKE_ETH_USD_PRICE)).toBe( - '$1.10', - ); - }); - it('correctly formats 5.3014059295032 ETH to usd according to some price', () => { - expect(format.ethBaseUnitAmountInUsd(IRRATIONAL_ETH_IN_BASE_UNITS, BIG_NUMBER_FAKE_ETH_USD_PRICE)).toBe( - '$13.43', - ); - }); - it('returns defaultText param when ethBaseAmountInUsd or ethUsdPrice is not defined', () => { - const defaultText = 'defaultText'; - expect(format.ethBaseUnitAmountInUsd(undefined, undefined, 2, defaultText)).toBe(defaultText); - expect(format.ethBaseUnitAmountInUsd(BIG_NUMBER_ONE, undefined, 2, defaultText)).toBe(defaultText); - expect(format.ethBaseUnitAmountInUsd(undefined, BIG_NUMBER_ONE, 2, defaultText)).toBe(defaultText); - }); - it('it allows for configurable decimal places', () => { - expect(format.ethBaseUnitAmountInUsd(DECIMAL_ETH_IN_BASE_UNITS, BIG_NUMBER_FAKE_ETH_USD_PRICE, 4)).toBe( - '$1.0957', - ); - }); - }); - describe('ethUnitAmountInUsd', () => { - it('correctly formats 1 ETH to usd according to some price', () => { - expect(format.ethUnitAmountInUsd(BIG_NUMBER_ONE, BIG_NUMBER_FAKE_ETH_USD_PRICE)).toBe('$2.53'); - }); - it('correctly formats .432414 ETH to usd according to some price', () => { - expect(format.ethUnitAmountInUsd(BIG_NUMBER_DECIMAL, BIG_NUMBER_FAKE_ETH_USD_PRICE)).toBe('$1.10'); - }); - it('correctly formats 5.3014059295032 ETH to usd according to some price', () => { - expect(format.ethUnitAmountInUsd(BIG_NUMBER_IRRATIONAL, BIG_NUMBER_FAKE_ETH_USD_PRICE)).toBe('$13.43'); - }); - it('correctly formats amount that is less than 1 cent', () => { - expect(format.ethUnitAmountInUsd(new BigNumber(0.000001), BIG_NUMBER_FAKE_ETH_USD_PRICE)).toBe('<$0.01'); - }); - it('correctly formats exactly 1 cent', () => { - expect(format.ethUnitAmountInUsd(new BigNumber(0.0039), BIG_NUMBER_FAKE_ETH_USD_PRICE)).toBe('$0.01'); - }); - it('returns defaultText param when ethUnitAmountInUsd or ethUsdPrice is not defined', () => { - const defaultText = 'defaultText'; - expect(format.ethUnitAmountInUsd(undefined, undefined, 2, defaultText)).toBe(defaultText); - expect(format.ethUnitAmountInUsd(BIG_NUMBER_ONE, undefined, 2, defaultText)).toBe(defaultText); - expect(format.ethUnitAmountInUsd(undefined, BIG_NUMBER_ONE, 2, defaultText)).toBe(defaultText); - }); - it('it allows for configurable decimal places', () => { - expect(format.ethUnitAmountInUsd(BIG_NUMBER_DECIMAL, BIG_NUMBER_FAKE_ETH_USD_PRICE, 4)).toBe('$1.0957'); - }); - }); -}); diff --git a/packages/instant/test/util/time.test.ts b/packages/instant/test/util/time.test.ts deleted file mode 100644 index fcb4e1875..000000000 --- a/packages/instant/test/util/time.test.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { timeUtil } from '../../src/util/time'; - -describe('timeUtil', () => { - describe('secondsToHumanDescription', () => { - const numsToResults: { - [aNumber: number]: string; - } = { - 1: '1 second', - 59: '59 seconds', - 60: '1 minute', - 119: '1 minute 59 seconds', - 120: '2 minutes', - 121: '2 minutes 1 second', - 122: '2 minutes 2 seconds', - }; - - const nums = Object.keys(numsToResults); - nums.forEach(aNum => { - const numInt = parseInt(aNum, 10); - it(`should work for ${aNum} seconds`, () => { - const expectedResult = numsToResults[numInt]; - expect(timeUtil.secondsToHumanDescription(numInt)).toEqual(expectedResult); - }); - }); - }); - describe('secondsToStopwatchTime', () => { - const numsToResults: { - [aNumber: number]: string; - } = { - 1: '00:01', - 59: '00:59', - 60: '01:00', - 119: '01:59', - 120: '02:00', - 121: '02:01', - 2701: '45:01', - }; - - const nums = Object.keys(numsToResults); - nums.forEach(aNum => { - const numInt = parseInt(aNum, 10); - it(`should work for ${aNum} seconds`, () => { - const expectedResult = numsToResults[numInt]; - expect(timeUtil.secondsToStopwatchTime(numInt)).toEqual(expectedResult); - }); - }); - }); -}); |