diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-08-17 07:08:02 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-08-17 07:08:02 +0800 |
commit | 89174cd63fb8c178c33d456d3b9d1d645ee07e91 (patch) | |
tree | 1d3b1932bdb4ff435d7a4d44ca443605d78b9bd0 /packages/order-utils/test/sorting_utils_test.ts | |
parent | 8cb1d2a0af2df12e0b628a7b016a2b96a4a66860 (diff) | |
parent | d0d6a6a500cf8bbaf5da144490056d0275675eb3 (diff) | |
download | dexon-sol-tools-89174cd63fb8c178c33d456d3b9d1d645ee07e91.tar dexon-sol-tools-89174cd63fb8c178c33d456d3b9d1d645ee07e91.tar.gz dexon-sol-tools-89174cd63fb8c178c33d456d3b9d1d645ee07e91.tar.bz2 dexon-sol-tools-89174cd63fb8c178c33d456d3b9d1d645ee07e91.tar.lz dexon-sol-tools-89174cd63fb8c178c33d456d3b9d1d645ee07e91.tar.xz dexon-sol-tools-89174cd63fb8c178c33d456d3b9d1d645ee07e91.tar.zst dexon-sol-tools-89174cd63fb8c178c33d456d3b9d1d645ee07e91.zip |
Merge branch 'development' of https://github.com/0xProject/0x-monorepo into feature/connect/sra-api-v2
Diffstat (limited to 'packages/order-utils/test/sorting_utils_test.ts')
-rw-r--r-- | packages/order-utils/test/sorting_utils_test.ts | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/packages/order-utils/test/sorting_utils_test.ts b/packages/order-utils/test/sorting_utils_test.ts new file mode 100644 index 000000000..016432505 --- /dev/null +++ b/packages/order-utils/test/sorting_utils_test.ts @@ -0,0 +1,67 @@ +import { BigNumber } from '@0xproject/utils'; +import * as chai from 'chai'; +import 'mocha'; + +import { sortingUtils } from '../src'; + +import { chaiSetup } from './utils/chai_setup'; +import { testOrderFactory } from './utils/test_order_factory'; + +chaiSetup.configure(); +const expect = chai.expect; + +describe('sortingUtils', () => { + describe('#sortOrdersByFeeAdjustedRate', () => { + const feeRate = new BigNumber(1); // ZRX costs 1 unit of takerAsset per 1 unit of ZRX + // rate: 2 takerAsset / makerAsset + const testOrder1 = testOrderFactory.generateTestSignedOrder({ + makerAssetAmount: new BigNumber(100), + takerAssetAmount: new BigNumber(200), + }); + // rate: 1 takerAsset / makerAsset + const testOrder2 = testOrderFactory.generateTestSignedOrder({ + makerAssetAmount: new BigNumber(100), + takerAssetAmount: new BigNumber(100), + }); + // rate: 2.5 takerAsset / makerAsset + const testOrder3 = testOrderFactory.generateTestSignedOrder({ + makerAssetAmount: new BigNumber(100), + takerAssetAmount: new BigNumber(200), + takerFee: new BigNumber(50), + }); + it('correctly sorts by fee adjusted rate when feeRate is Provided', async () => { + const orders = [testOrder1, testOrder2, testOrder3]; + const sortedOrders = sortingUtils.sortOrdersByFeeAdjustedRate(orders, feeRate); + expect(sortedOrders).to.deep.equal([testOrder2, testOrder1, testOrder3]); + }); + it('correctly sorts by fee adjusted rate when no feeRate is Provided', async () => { + const orders = [testOrder1, testOrder2, testOrder3]; + const sortedOrders = sortingUtils.sortOrdersByFeeAdjustedRate(orders); + expect(sortedOrders).to.deep.equal([testOrder2, testOrder1, testOrder3]); + }); + }); + describe('#sortFeeOrdersByFeeAdjustedRate', () => { + // rate: 200 takerAsset / makerAsset + const testOrder1 = testOrderFactory.generateTestSignedOrder({ + makerAssetAmount: new BigNumber(100), + takerAssetAmount: new BigNumber(200), + takerFee: new BigNumber(99), + }); + // rate: 1 takerAsset / makerAsset + const testOrder2 = testOrderFactory.generateTestSignedOrder({ + makerAssetAmount: new BigNumber(100), + takerAssetAmount: new BigNumber(100), + }); + // rate: 4 takerAsset / makerAsset + const testOrder3 = testOrderFactory.generateTestSignedOrder({ + makerAssetAmount: new BigNumber(100), + takerAssetAmount: new BigNumber(200), + takerFee: new BigNumber(50), + }); + it('correctly sorts by fee adjusted rate', async () => { + const orders = [testOrder1, testOrder2, testOrder3]; + const sortedOrders = sortingUtils.sortFeeOrdersByFeeAdjustedRate(orders); + expect(sortedOrders).to.deep.equal([testOrder2, testOrder3, testOrder1]); + }); + }); +}); |