aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contract-wrappers/test/calldata_optimization_utils_test.ts
diff options
context:
space:
mode:
authorBrandon Millman <brandon@0xproject.com>2018-08-06 05:47:42 +0800
committerGitHub <noreply@github.com>2018-08-06 05:47:42 +0800
commit47fef1f8ff583879fa83a7a44086b14f69c09e21 (patch)
tree333f93d99e32e75739e3f76bbaa8c393249f71ff /packages/contract-wrappers/test/calldata_optimization_utils_test.ts
parent9f7f61085c1a6989b79df575beb0b5d8f2b3652d (diff)
parent3cb955c136bf47b5f40cdbc44bcc4d19ec6d6453 (diff)
downloaddexon-0x-contracts-47fef1f8ff583879fa83a7a44086b14f69c09e21.tar.gz
dexon-0x-contracts-47fef1f8ff583879fa83a7a44086b14f69c09e21.tar.zst
dexon-0x-contracts-47fef1f8ff583879fa83a7a44086b14f69c09e21.zip
Merge pull request #936 from 0xProject/feature/contract-wrappers/forwader-optimizations
ForwarderWrapper order optimizations
Diffstat (limited to 'packages/contract-wrappers/test/calldata_optimization_utils_test.ts')
-rw-r--r--packages/contract-wrappers/test/calldata_optimization_utils_test.ts60
1 files changed, 60 insertions, 0 deletions
diff --git a/packages/contract-wrappers/test/calldata_optimization_utils_test.ts b/packages/contract-wrappers/test/calldata_optimization_utils_test.ts
new file mode 100644
index 000000000..a4cea772f
--- /dev/null
+++ b/packages/contract-wrappers/test/calldata_optimization_utils_test.ts
@@ -0,0 +1,60 @@
+import { orderFactory } from '@0xproject/order-utils';
+import * as chai from 'chai';
+import * as _ from 'lodash';
+import 'mocha';
+
+import { assert } from '../src/utils/assert';
+import { calldataOptimizationUtils } from '../src/utils/calldata_optimization_utils';
+import { constants } from '../src/utils/constants';
+
+import { chaiSetup } from './utils/chai_setup';
+
+chaiSetup.configure();
+const expect = chai.expect;
+
+// utility for generating a set of order objects with mostly NULL values
+// except for a specified makerAssetData and takerAssetData
+const FAKE_ORDERS_COUNT = 5;
+const generateFakeOrders = (makerAssetData: string, takerAssetData: string) =>
+ _.map(_.range(FAKE_ORDERS_COUNT), index => {
+ const order = orderFactory.createOrder(
+ constants.NULL_ADDRESS,
+ constants.ZERO_AMOUNT,
+ makerAssetData,
+ constants.ZERO_AMOUNT,
+ takerAssetData,
+ constants.NULL_ADDRESS,
+ );
+ return {
+ ...order,
+ signature: 'dummy signature',
+ };
+ });
+
+describe('calldataOptimizationUtils', () => {
+ const fakeMakerAssetData = 'fakeMakerAssetData';
+ const fakeTakerAssetData = 'fakeTakerAssetData';
+ const orders = generateFakeOrders(fakeMakerAssetData, fakeTakerAssetData);
+ describe('#optimizeForwarderOrders', () => {
+ it('should make makerAssetData `0x` unless first order', () => {
+ const optimizedOrders = calldataOptimizationUtils.optimizeForwarderOrders(orders);
+ expect(optimizedOrders[0].makerAssetData).to.equal(fakeMakerAssetData);
+ const ordersWithoutHead = _.slice(optimizedOrders, 1);
+ _.forEach(ordersWithoutHead, order => expect(order.makerAssetData).to.equal(constants.NULL_BYTES));
+ });
+ it('should make all takerAssetData `0x`', () => {
+ const optimizedOrders = calldataOptimizationUtils.optimizeForwarderOrders(orders);
+ _.forEach(optimizedOrders, order => expect(order.takerAssetData).to.equal(constants.NULL_BYTES));
+ });
+ });
+ describe('#optimizeForwarderFeeOrders', () => {
+ it('should make all makerAssetData `0x`', () => {
+ const optimizedOrders = calldataOptimizationUtils.optimizeForwarderFeeOrders(orders);
+ _.forEach(optimizedOrders, order => expect(order.makerAssetData).to.equal(constants.NULL_BYTES));
+ });
+ it('should make all takerAssetData `0x`', () => {
+ const optimizedOrders = calldataOptimizationUtils.optimizeForwarderFeeOrders(orders);
+ _.forEach(optimizedOrders, order => expect(order.takerAssetData).to.equal(constants.NULL_BYTES));
+ });
+ });
+});