diff options
author | Steve Klebanoff <steve.klebanoff@gmail.com> | 2019-01-11 06:00:16 +0800 |
---|---|---|
committer | Steve Klebanoff <steve.klebanoff@gmail.com> | 2019-01-11 06:00:16 +0800 |
commit | 2360b8282fe40e1c1b1336b17872b5699bde610e (patch) | |
tree | b5965d3ef0fe24645e7e9beaae71e71d2999f8b4 | |
parent | 0dade8624c0935a26bed9b9c53a94a8211dabdee (diff) | |
download | dexon-sol-tools-2360b8282fe40e1c1b1336b17872b5699bde610e.tar.gz dexon-sol-tools-2360b8282fe40e1c1b1336b17872b5699bde610e.tar.zst dexon-sol-tools-2360b8282fe40e1c1b1336b17872b5699bde610e.zip |
rename tokensAvailableInUnitAmount to tokensAvailableInBaseUnits and use test helpers
-rw-r--r-- | packages/asset-buyer/src/asset_buyer.ts | 8 | ||||
-rw-r--r-- | packages/asset-buyer/src/types.ts | 2 | ||||
-rw-r--r-- | packages/asset-buyer/test/asset_buyer_test.ts | 51 |
3 files changed, 29 insertions, 32 deletions
diff --git a/packages/asset-buyer/src/asset_buyer.ts b/packages/asset-buyer/src/asset_buyer.ts index 511c99fb1..92a99c28c 100644 --- a/packages/asset-buyer/src/asset_buyer.ts +++ b/packages/asset-buyer/src/asset_buyer.ts @@ -45,19 +45,19 @@ const calculateLiquidity = (ordersAndFillableAmounts: OrdersAndFillableAmounts): const tokensAvailableForCurrentOrder = availableMakerAssetAmount; const ethValueAvailableForCurrentOrder = orderUtils.getTakerFillAmount(order, availableMakerAssetAmount); return { - tokensAvailableInUnitAmount: acc.tokensAvailableInUnitAmount.plus(tokensAvailableForCurrentOrder), + tokensAvailableInBaseUnits: acc.tokensAvailableInBaseUnits.plus(tokensAvailableForCurrentOrder), ethValueAvailableInWei: acc.ethValueAvailableInWei.plus(ethValueAvailableForCurrentOrder), }; }, { - tokensAvailableInUnitAmount: new BigNumber(0), + tokensAvailableInBaseUnits: new BigNumber(0), ethValueAvailableInWei: new BigNumber(0), }, ); // Turn into regular numbers return { - tokensAvailableInUnitAmount: liquidityInBigNumbers.tokensAvailableInUnitAmount.toNumber(), + tokensAvailableInBaseUnits: liquidityInBigNumbers.tokensAvailableInBaseUnits.toNumber(), ethValueAvailableInWei: liquidityInBigNumbers.ethValueAvailableInWei.toNumber(), }; }; @@ -225,7 +225,7 @@ export class AssetBuyer { const assetPairs = await this.orderProvider.getAvailableMakerAssetDatasAsync(assetData); if (!assetPairs.includes(assetData)) { return { - tokensAvailableInUnitAmount: 0, + tokensAvailableInBaseUnits: 0, ethValueAvailableInWei: 0, }; } diff --git a/packages/asset-buyer/src/types.ts b/packages/asset-buyer/src/types.ts index 84434aa7f..71822c4d7 100644 --- a/packages/asset-buyer/src/types.ts +++ b/packages/asset-buyer/src/types.ts @@ -126,6 +126,6 @@ export interface OrdersAndFillableAmounts { * Represents available liquidity for a given assetData */ export interface LiquidityForAssetData { - tokensAvailableInUnitAmount: number; + tokensAvailableInBaseUnits: number; ethValueAvailableInWei: number; } diff --git a/packages/asset-buyer/test/asset_buyer_test.ts b/packages/asset-buyer/test/asset_buyer_test.ts index fd31b9843..5e05d5564 100644 --- a/packages/asset-buyer/test/asset_buyer_test.ts +++ b/packages/asset-buyer/test/asset_buyer_test.ts @@ -81,7 +81,7 @@ describe('AssetBuyer', () => { const assetBuyer = new AssetBuyer(mockWeb3Provider.object, mockOrderProvider.object); const liquidityResult = await assetBuyer.getLiquidityForAssetDataAsync(FAKE_ASSET_DATA); expect(liquidityResult).to.deep.equal({ - tokensAvailableInUnitAmount: 0, + tokensAvailableInBaseUnits: 0, ethValueAvailableInWei: 0, }); }); @@ -106,41 +106,38 @@ describe('AssetBuyer', () => { orders: [], remainingFillableMakerAssetAmounts: [], }; - const mockedAssetBuyer = mockedAssetBuyerWithOrdersAndFillableAmounts( + const expectedResult = { + tokensAvailableInBaseUnits: 0, + ethValueAvailableInWei: 0, + }; + await expectLiquidityResult( mockWeb3Provider.object, mockOrderProvider.object, - FAKE_ASSET_DATA, ordersAndFillableAmounts, + expectedResult, ); - - const liquidityResult = await mockedAssetBuyer.object.getLiquidityForAssetDataAsync(FAKE_ASSET_DATA); - expect(liquidityResult).to.deep.equal({ - tokensAvailableInUnitAmount: 0, - ethValueAvailableInWei: 0, - }); }); it('should return correct computed value when orders provided with full fillableAmounts', async () => { const orders: SignedOrder[] = [sellTwoTokensFor1Weth, sellTenTokensFor10Weth]; - const remainingFillableMakerAssetAmounts: BigNumber[] = orders.map(o => o.makerAssetAmount); - const mockedAssetBuyer = mockedAssetBuyerWithOrdersAndFillableAmounts( - mockWeb3Provider.object, - mockOrderProvider.object, - FAKE_ASSET_DATA, - { - orders, - remainingFillableMakerAssetAmounts, - }, - ); + const ordersAndFillableAmounts = { + orders: [sellTwoTokensFor1Weth, sellTenTokensFor10Weth], + remainingFillableMakerAssetAmounts: orders.map(o => o.makerAssetAmount), + }; const expectedTokensAvailable = orders[0].makerAssetAmount.plus(orders[1].makerAssetAmount); const expectedEthValueAvailable = orders[0].takerAssetAmount.plus(orders[1].takerAssetAmount); - - const liquidityResult = await mockedAssetBuyer.object.getLiquidityForAssetDataAsync(FAKE_ASSET_DATA); - expect(liquidityResult).to.deep.equal({ - tokensAvailableInUnitAmount: expectedTokensAvailable.toNumber(), + const expectedResult = { + tokensAvailableInBaseUnits: expectedTokensAvailable.toNumber(), ethValueAvailableInWei: expectedEthValueAvailable.toNumber(), - }); + }; + + await expectLiquidityResult( + mockWeb3Provider.object, + mockOrderProvider.object, + ordersAndFillableAmounts, + expectedResult, + ); }); it('should return correct computed value with one partial fillableAmounts', async () => { @@ -149,7 +146,7 @@ describe('AssetBuyer', () => { remainingFillableMakerAssetAmounts: [baseUnitAmount(1)], }; const expectedResult = { - tokensAvailableInUnitAmount: baseUnitAmount(1).toNumber(), + tokensAvailableInBaseUnits: baseUnitAmount(1).toNumber(), ethValueAvailableInWei: baseUnitAmount(0.5, WETH_DECIMALS).toNumber(), }; @@ -167,7 +164,7 @@ describe('AssetBuyer', () => { remainingFillableMakerAssetAmounts: [baseUnitAmount(1), baseUnitAmount(3)], }; const expectedResult = { - tokensAvailableInUnitAmount: baseUnitAmount(4).toNumber(), + tokensAvailableInBaseUnits: baseUnitAmount(4).toNumber(), ethValueAvailableInWei: baseUnitAmount(3.5, WETH_DECIMALS).toNumber(), }; @@ -185,7 +182,7 @@ describe('AssetBuyer', () => { remainingFillableMakerAssetAmounts: [baseUnitAmount(0), baseUnitAmount(0)], }; const expectedResult = { - tokensAvailableInUnitAmount: baseUnitAmount(0).toNumber(), + tokensAvailableInBaseUnits: baseUnitAmount(0).toNumber(), ethValueAvailableInWei: baseUnitAmount(0, WETH_DECIMALS).toNumber(), }; |