diff options
author | F. Eugene Aumson <feuGeneA@users.noreply.github.com> | 2018-08-17 06:32:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-17 06:32:09 +0800 |
commit | c1ec849554a1e55cd3e8d5bbee206f4bf1d67a5b (patch) | |
tree | 919eca787e6da6b6e1b28073d7a9e876f9497616 /packages/order-utils/test/rate_utils_test.ts | |
parent | 445177bf420049041ade4d7526a5f4a8194bd216 (diff) | |
parent | 72752bcb68bac29ff5897ed57de357ad7af09abe (diff) | |
download | dexon-sol-tools-c1ec849554a1e55cd3e8d5bbee206f4bf1d67a5b.tar dexon-sol-tools-c1ec849554a1e55cd3e8d5bbee206f4bf1d67a5b.tar.gz dexon-sol-tools-c1ec849554a1e55cd3e8d5bbee206f4bf1d67a5b.tar.bz2 dexon-sol-tools-c1ec849554a1e55cd3e8d5bbee206f4bf1d67a5b.tar.lz dexon-sol-tools-c1ec849554a1e55cd3e8d5bbee206f4bf1d67a5b.tar.xz dexon-sol-tools-c1ec849554a1e55cd3e8d5bbee206f4bf1d67a5b.tar.zst dexon-sol-tools-c1ec849554a1e55cd3e8d5bbee206f4bf1d67a5b.zip |
Merge branch 'development' into sol-compile-lot
Diffstat (limited to 'packages/order-utils/test/rate_utils_test.ts')
-rw-r--r-- | packages/order-utils/test/rate_utils_test.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/packages/order-utils/test/rate_utils_test.ts b/packages/order-utils/test/rate_utils_test.ts new file mode 100644 index 000000000..2e299c209 --- /dev/null +++ b/packages/order-utils/test/rate_utils_test.ts @@ -0,0 +1,55 @@ +import { BigNumber } from '@0xproject/utils'; +import * as chai from 'chai'; +import 'mocha'; + +import { rateUtils } from '../src'; + +import { chaiSetup } from './utils/chai_setup'; +import { testOrderFactory } from './utils/test_order_factory'; + +chaiSetup.configure(); +const expect = chai.expect; + +describe('rateUtils', () => { + const testOrder = testOrderFactory.generateTestSignedOrder({ + makerAssetAmount: new BigNumber(100), + takerAssetAmount: new BigNumber(100), + takerFee: new BigNumber(20), + }); + describe('#getFeeAdjustedRateOfOrder', () => { + it('throws when feeRate is less than zero', async () => { + const feeRate = new BigNumber(-1); + expect(() => rateUtils.getFeeAdjustedRateOfOrder(testOrder, feeRate)).to.throw( + 'Expected feeRate: -1 to be greater than or equal to 0', + ); + }); + it('correctly calculates fee adjusted rate when feeRate is provided', async () => { + const feeRate = new BigNumber(2); // ZRX costs 2 units of takerAsset per 1 unit of ZRX + const feeAdjustedRate = rateUtils.getFeeAdjustedRateOfOrder(testOrder, feeRate); + // the order actually takes 100 + (2 * 20) takerAsset units to fill 100 units of makerAsset + expect(feeAdjustedRate).to.bignumber.equal(new BigNumber(1.4)); + }); + it('correctly calculates fee adjusted rate when no feeRate is provided', async () => { + const feeAdjustedRate = rateUtils.getFeeAdjustedRateOfOrder(testOrder); + // because no feeRate was provided we just assume 0 fees + // the order actually takes 100 takerAsset units to fill 100 units of makerAsset + expect(feeAdjustedRate).to.bignumber.equal(new BigNumber(1)); + }); + }); + describe('#getFeeAdjustedRateOfFeeOrder', () => { + it('throws when takerFee exceeds makerAssetAmount', async () => { + const badOrder = testOrderFactory.generateTestSignedOrder({ + makerAssetAmount: new BigNumber(100), + takerFee: new BigNumber(101), + }); + expect(() => rateUtils.getFeeAdjustedRateOfFeeOrder(badOrder)).to.throw( + 'Expected takerFee: "101" to be less than makerAssetAmount: "100"', + ); + }); + it('correctly calculates fee adjusted rate', async () => { + const feeAdjustedRate = rateUtils.getFeeAdjustedRateOfFeeOrder(testOrder); + // the order actually takes 100 takerAsset units to fill (100 - 20) units of makerAsset + expect(feeAdjustedRate).to.bignumber.equal(new BigNumber(1.25)); + }); + }); +}); |