aboutsummaryrefslogtreecommitdiffstats
path: root/packages/forwarder-helper/test
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-08-22 08:08:44 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-08-23 06:39:03 +0800
commit68dfd1bb22c1d6d33a46ca1eff5fa6f62cde62ed (patch)
treeb951b52ab55cbd2d1b931ea2d91b59bbc4468514 /packages/forwarder-helper/test
parent67d33ec10c3d2467d2d073d22bfe2957353a0cc8 (diff)
downloaddexon-sol-tools-68dfd1bb22c1d6d33a46ca1eff5fa6f62cde62ed.tar
dexon-sol-tools-68dfd1bb22c1d6d33a46ca1eff5fa6f62cde62ed.tar.gz
dexon-sol-tools-68dfd1bb22c1d6d33a46ca1eff5fa6f62cde62ed.tar.bz2
dexon-sol-tools-68dfd1bb22c1d6d33a46ca1eff5fa6f62cde62ed.tar.lz
dexon-sol-tools-68dfd1bb22c1d6d33a46ca1eff5fa6f62cde62ed.tar.xz
dexon-sol-tools-68dfd1bb22c1d6d33a46ca1eff5fa6f62cde62ed.tar.zst
dexon-sol-tools-68dfd1bb22c1d6d33a46ca1eff5fa6f62cde62ed.zip
Add tests for getMarketBuyOrdersInfo
Diffstat (limited to 'packages/forwarder-helper/test')
-rw-r--r--packages/forwarder-helper/test/forwarder_helper_impl_test.ts57
1 files changed, 49 insertions, 8 deletions
diff --git a/packages/forwarder-helper/test/forwarder_helper_impl_test.ts b/packages/forwarder-helper/test/forwarder_helper_impl_test.ts
index 150ba5f0b..3e2667a01 100644
--- a/packages/forwarder-helper/test/forwarder_helper_impl_test.ts
+++ b/packages/forwarder-helper/test/forwarder_helper_impl_test.ts
@@ -5,6 +5,7 @@ import * as _ from 'lodash';
import 'mocha';
import { ForwarderHelperImpl, ForwarderHelperImplConfig } from '../src/forwarder_helper_impl';
+import { ForwarderHelperError } from '../src/types';
import { chaiSetup } from './utils/chai_setup';
@@ -26,6 +27,7 @@ describe('ForwarderHelperImpl', () => {
const testOrder3 = testOrderFactory.generateTestSignedOrder({
makerAssetAmount: new BigNumber(100),
takerAssetAmount: new BigNumber(300),
+ takerFee: new BigNumber(1),
});
// rate: 3 WETH / ZRX
const testFeeOrder1 = testOrderFactory.generateTestSignedOrder({
@@ -42,13 +44,13 @@ describe('ForwarderHelperImpl', () => {
makerAssetAmount: new BigNumber(100),
takerAssetAmount: new BigNumber(100),
});
+ const inputForwarderHelperConfig: ForwarderHelperImplConfig = {
+ orders: [testOrder1, testOrder2, testOrder3],
+ feeOrders: [testFeeOrder1, testFeeOrder2, testFeeOrder3],
+ remainingFillableMakerAssetAmounts: [new BigNumber(1), new BigNumber(2), new BigNumber(3)],
+ remainingFillableFeeAmounts: [new BigNumber(4), new BigNumber(5), new BigNumber(6)],
+ };
describe('#constructor', () => {
- const inputForwarderHelperConfig: ForwarderHelperImplConfig = {
- orders: [testOrder1, testOrder2, testOrder3],
- feeOrders: [testFeeOrder1, testFeeOrder2, testFeeOrder3],
- remainingFillableMakerAssetAmounts: [new BigNumber(1), new BigNumber(2), new BigNumber(3)],
- remainingFillableFeeAmounts: [new BigNumber(4), new BigNumber(5), new BigNumber(6)],
- };
const inputForwarderHelperConfigNoRemainingAmounts: ForwarderHelperImplConfig = {
orders: [testOrder1, testOrder2, testOrder3],
feeOrders: [testFeeOrder1, testFeeOrder2, testFeeOrder3],
@@ -90,6 +92,45 @@ describe('ForwarderHelperImpl', () => {
expect(forwarderHelper.config.remainingFillableFeeAmounts).to.be.undefined();
});
});
- // describe('#getMarketBuyOrdersInfo', () => {});
- // describe('#getMarketSellOrdersInfo', () => {});
+ describe('#getMarketBuyOrdersInfo', () => {
+ it('throws if not enough makerAsset liquidity', () => {
+ const forwarderHelper = new ForwarderHelperImpl(inputForwarderHelperConfig);
+ expect(() => {
+ // request for 6 makerAsset units, because we have exactly 6 available we should throw because there is a built in slippage buffer
+ const info = forwarderHelper.getMarketBuyOrdersInfo({
+ makerAssetFillAmount: new BigNumber(6),
+ });
+ }).to.throw(ForwarderHelperError.InsufficientMakerAssetLiquidity);
+ });
+ it('throws if not enough ZRX liquidity', () => {
+ const inputForwarderHelperConfigNoFees: ForwarderHelperImplConfig = {
+ orders: [testOrder1, testOrder2, testOrder3],
+ feeOrders: [],
+ };
+ const forwarderHelper = new ForwarderHelperImpl(inputForwarderHelperConfigNoFees);
+ expect(() => {
+ // request for 4 makerAsset units, we need fees but no fee orders exist, show we should throw
+ const info = forwarderHelper.getMarketBuyOrdersInfo({
+ makerAssetFillAmount: new BigNumber(250),
+ });
+ }).to.throw(ForwarderHelperError.InsufficientZrxLiquidity);
+ });
+ it('passes the makerAssetFillAmount from the request to the info response', () => {
+ const forwarderHelper = new ForwarderHelperImpl(inputForwarderHelperConfig);
+ const makerAssetFillAmount = new BigNumber(4);
+ const info = forwarderHelper.getMarketBuyOrdersInfo({
+ makerAssetFillAmount,
+ });
+ expect(info.makerAssetFillAmount).to.bignumber.equal(makerAssetFillAmount);
+ });
+ it('passes the feePercentage from the request to the info response', () => {
+ const forwarderHelper = new ForwarderHelperImpl(inputForwarderHelperConfig);
+ const feePercentage = new BigNumber(0.2);
+ const info = forwarderHelper.getMarketBuyOrdersInfo({
+ makerAssetFillAmount: new BigNumber(4),
+ feePercentage,
+ });
+ expect(info.feePercentage).to.bignumber.equal(feePercentage);
+ });
+ });
});