aboutsummaryrefslogtreecommitdiffstats
path: root/packages/forwarder-helper/test
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-08-22 05:45:16 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-08-23 06:39:03 +0800
commit05ba049f5937be3a3a47ed90898f6a0267a67fd8 (patch)
treeadb642a716e641fe952ce86498e166867896e159 /packages/forwarder-helper/test
parent867ff3c5ece61c9119dd1dff9a769b15b39c96c6 (diff)
downloaddexon-sol-tools-05ba049f5937be3a3a47ed90898f6a0267a67fd8.tar.gz
dexon-sol-tools-05ba049f5937be3a3a47ed90898f6a0267a67fd8.tar.zst
dexon-sol-tools-05ba049f5937be3a3a47ed90898f6a0267a67fd8.zip
Add test for sorting that happens in constructor
Diffstat (limited to 'packages/forwarder-helper/test')
-rw-r--r--packages/forwarder-helper/test/forwarder_helper_impl_test.ts87
1 files changed, 85 insertions, 2 deletions
diff --git a/packages/forwarder-helper/test/forwarder_helper_impl_test.ts b/packages/forwarder-helper/test/forwarder_helper_impl_test.ts
index 1d3347d48..150ba5f0b 100644
--- a/packages/forwarder-helper/test/forwarder_helper_impl_test.ts
+++ b/packages/forwarder-helper/test/forwarder_helper_impl_test.ts
@@ -1,12 +1,95 @@
+import { testOrderFactory } from '@0xproject/order-utils/lib/test/utils/test_order_factory';
+import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
+import * as _ from 'lodash';
import 'mocha';
+import { ForwarderHelperImpl, ForwarderHelperImplConfig } from '../src/forwarder_helper_impl';
+
import { chaiSetup } from './utils/chai_setup';
chaiSetup.configure();
const expect = chai.expect;
describe('ForwarderHelperImpl', () => {
- describe('#getMarketBuyOrdersInfo', () => {});
- describe('#getMarketSellOrdersInfo', () => {});
+ // 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: 3 takerAsset / makerAsset
+ const testOrder3 = testOrderFactory.generateTestSignedOrder({
+ makerAssetAmount: new BigNumber(100),
+ takerAssetAmount: new BigNumber(300),
+ });
+ // rate: 3 WETH / ZRX
+ const testFeeOrder1 = testOrderFactory.generateTestSignedOrder({
+ makerAssetAmount: new BigNumber(100),
+ takerAssetAmount: new BigNumber(300),
+ });
+ // rate: 2 WETH / ZRX
+ const testFeeOrder2 = testOrderFactory.generateTestSignedOrder({
+ makerAssetAmount: new BigNumber(100),
+ takerAssetAmount: new BigNumber(200),
+ });
+ // rate: 1 WETH / ZRX
+ const testFeeOrder3 = testOrderFactory.generateTestSignedOrder({
+ makerAssetAmount: new BigNumber(100),
+ takerAssetAmount: new BigNumber(100),
+ });
+ 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],
+ };
+ it('sorts orders', () => {
+ const forwarderHelper = new ForwarderHelperImpl(inputForwarderHelperConfig);
+ expect(forwarderHelper.config.orders).deep.equals([testOrder2, testOrder1, testOrder3]);
+ });
+ it('sorts fee orders', () => {
+ const forwarderHelper = new ForwarderHelperImpl(inputForwarderHelperConfig);
+ expect(forwarderHelper.config.feeOrders).deep.equals([testFeeOrder3, testFeeOrder2, testFeeOrder1]);
+ });
+ it('sorts remainingFillableMakerAssetAmounts', () => {
+ const forwarderHelper = new ForwarderHelperImpl(inputForwarderHelperConfig);
+ expect(forwarderHelper.config.remainingFillableMakerAssetAmounts).to.be.not.undefined();
+ expect(_.nth(forwarderHelper.config.remainingFillableMakerAssetAmounts, 0)).to.bignumber.equal(
+ new BigNumber(2),
+ );
+ expect(_.nth(forwarderHelper.config.remainingFillableMakerAssetAmounts, 1)).to.bignumber.equal(
+ new BigNumber(1),
+ );
+ expect(_.nth(forwarderHelper.config.remainingFillableMakerAssetAmounts, 2)).to.bignumber.equal(
+ new BigNumber(3),
+ );
+ });
+ it('sorts remainingFillableFeeAmounts', () => {
+ const forwarderHelper = new ForwarderHelperImpl(inputForwarderHelperConfig);
+ expect(forwarderHelper.config.remainingFillableFeeAmounts).to.be.not.undefined();
+ expect(_.nth(forwarderHelper.config.remainingFillableFeeAmounts, 0)).to.bignumber.equal(new BigNumber(6));
+ expect(_.nth(forwarderHelper.config.remainingFillableFeeAmounts, 1)).to.bignumber.equal(new BigNumber(5));
+ expect(_.nth(forwarderHelper.config.remainingFillableFeeAmounts, 2)).to.bignumber.equal(new BigNumber(4));
+ });
+ it('remainingFillableMakerAssetAmounts is undefined if none provided', () => {
+ const forwarderHelper = new ForwarderHelperImpl(inputForwarderHelperConfigNoRemainingAmounts);
+ expect(forwarderHelper.config.remainingFillableMakerAssetAmounts).to.be.undefined();
+ });
+ it('remainingFillableFeeAmounts is undefined if none provided', () => {
+ const forwarderHelper = new ForwarderHelperImpl(inputForwarderHelperConfigNoRemainingAmounts);
+ expect(forwarderHelper.config.remainingFillableFeeAmounts).to.be.undefined();
+ });
+ });
+ // describe('#getMarketBuyOrdersInfo', () => {});
+ // describe('#getMarketSellOrdersInfo', () => {});
});