aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrandon Millman <brandon.millman@gmail.com>2018-10-04 14:14:55 +0800
committerBrandon Millman <brandon.millman@gmail.com>2018-10-04 14:22:13 +0800
commit059162a90a3d26e5fdfefd8553bb1f721a3116fc (patch)
treebb3dfc2ef2cefb1d78d65fb7318e8e1c6884a09e
parent250a9a480940ae4fca48109aae97ee0323d57a52 (diff)
downloaddexon-sol-tools-059162a90a3d26e5fdfefd8553bb1f721a3116fc.tar.gz
dexon-sol-tools-059162a90a3d26e5fdfefd8553bb1f721a3116fc.tar.zst
dexon-sol-tools-059162a90a3d26e5fdfefd8553bb1f721a3116fc.zip
Add additional order factory methods and refactor test to use them
-rw-r--r--packages/asset-buyer/test/buy_quote_calculator_test.ts83
-rw-r--r--packages/order-utils/src/order_factory.ts39
2 files changed, 61 insertions, 61 deletions
diff --git a/packages/asset-buyer/test/buy_quote_calculator_test.ts b/packages/asset-buyer/test/buy_quote_calculator_test.ts
index 37a429531..3bd0f8d4e 100644
--- a/packages/asset-buyer/test/buy_quote_calculator_test.ts
+++ b/packages/asset-buyer/test/buy_quote_calculator_test.ts
@@ -27,74 +27,37 @@ describe('buyQuoteCalculator', () => {
// the second order has a rate of 2 makerAsset / WETH with a takerFee of 100 ZRX and has 200 / 200 makerAsset units left to fill (completely fillable)
// generate one order for fees
// the fee order has a rate of 1 ZRX / WETH with no taker fee and has 100 ZRX left to fill (completely fillable)
- const firstOrder = orderFactory.createOrder(
- NULL_ADDRESS,
- new BigNumber(400),
- NULL_BYTES,
- new BigNumber(100),
- NULL_BYTES,
- NULL_ADDRESS,
- {
- takerFee: new BigNumber(200),
- },
- );
+ const firstOrder = orderFactory.createSignedOrderFromPartial({
+ makerAssetAmount: new BigNumber(400),
+ takerAssetAmount: new BigNumber(100),
+ takerFee: new BigNumber(200),
+ });
const firstRemainingFillAmount = new BigNumber(200);
- const secondOrder = orderFactory.createOrder(
- NULL_ADDRESS,
- new BigNumber(200),
- NULL_BYTES,
- new BigNumber(100),
- NULL_BYTES,
- NULL_ADDRESS,
- {
- takerFee: new BigNumber(100),
- },
- );
- const secondRemainingFillAmount = secondOrder.makerAssetAmount;
- const signedOrders = _.map([firstOrder, secondOrder], order => {
- return {
- ...order,
- signature: NULL_BYTES,
- };
+ const secondOrder = orderFactory.createSignedOrderFromPartial({
+ makerAssetAmount: new BigNumber(200),
+ takerAssetAmount: new BigNumber(100),
+ takerFee: new BigNumber(100),
});
+ const secondRemainingFillAmount = secondOrder.makerAssetAmount;
ordersAndFillableAmounts = {
- orders: signedOrders,
+ orders: [firstOrder, secondOrder],
remainingFillableMakerAssetAmounts: [firstRemainingFillAmount, secondRemainingFillAmount],
};
- const smallFeeOrder = orderFactory.createOrder(
- NULL_ADDRESS,
- new BigNumber(100),
- NULL_BYTES,
- new BigNumber(100),
- NULL_BYTES,
- NULL_ADDRESS,
- );
- const signedSmallFeeOrder = {
- ...smallFeeOrder,
- signature: NULL_BYTES,
- };
+ const smallFeeOrder = orderFactory.createSignedOrderFromPartial({
+ makerAssetAmount: new BigNumber(100),
+ takerAssetAmount: new BigNumber(100),
+ });
smallFeeOrderAndFillableAmount = {
- orders: [signedSmallFeeOrder],
- remainingFillableMakerAssetAmounts: [signedSmallFeeOrder.makerAssetAmount],
- };
- const largeFeeOrder = orderFactory.createOrder(
- NULL_ADDRESS,
- new BigNumber(100),
- NULL_BYTES,
- new BigNumber(200),
- NULL_BYTES,
- NULL_ADDRESS,
- );
- const signedLargeFeeOrder = {
- ...largeFeeOrder,
- signature: NULL_BYTES,
+ orders: [smallFeeOrder],
+ remainingFillableMakerAssetAmounts: [smallFeeOrder.makerAssetAmount],
};
+ const largeFeeOrder = orderFactory.createSignedOrderFromPartial({
+ makerAssetAmount: new BigNumber(100),
+ takerAssetAmount: new BigNumber(200),
+ });
allFeeOrdersAndFillableAmounts = {
- orders: [signedSmallFeeOrder, signedLargeFeeOrder],
- remainingFillableMakerAssetAmounts: [
- signedSmallFeeOrder.makerAssetAmount,
- largeFeeOrder.makerAssetAmount,
- ],
+ orders: [smallFeeOrder, largeFeeOrder],
+ remainingFillableMakerAssetAmounts: [smallFeeOrder.makerAssetAmount, largeFeeOrder.makerAssetAmount],
};
});
it('should throw if not enough maker asset liquidity', () => {
diff --git a/packages/order-utils/src/order_factory.ts b/packages/order-utils/src/order_factory.ts
index 46a69ae4d..b1292903a 100644
--- a/packages/order-utils/src/order_factory.ts
+++ b/packages/order-utils/src/order_factory.ts
@@ -8,8 +8,21 @@ import { orderHashUtils } from './order_hash';
import { generatePseudoRandomSalt } from './salt';
import { signatureUtils } from './signature_utils';
import { CreateOrderOpts } from './types';
-
export const orderFactory = {
+ createOrderFromPartial(partialOrder: Partial<Order>): Order {
+ const defaultOrder = generateEmptyOrder();
+ return {
+ ...defaultOrder,
+ ...partialOrder,
+ };
+ },
+ createSignedOrderFromPartial(partialSignedOrder: Partial<SignedOrder>): SignedOrder {
+ const defaultOrder = generateEmptySignedOrder();
+ return {
+ ...defaultOrder,
+ ...partialSignedOrder,
+ };
+ },
createOrder(
makerAddress: string,
makerAssetAmount: BigNumber,
@@ -69,6 +82,30 @@ export const orderFactory = {
},
};
+function generateEmptySignedOrder(): SignedOrder {
+ return {
+ ...generateEmptyOrder(),
+ signature: constants.NULL_BYTES,
+ };
+}
+function generateEmptyOrder(): Order {
+ return {
+ senderAddress: constants.NULL_ADDRESS,
+ makerAddress: constants.NULL_ADDRESS,
+ takerAddress: constants.NULL_ADDRESS,
+ makerFee: constants.ZERO_AMOUNT,
+ takerFee: constants.ZERO_AMOUNT,
+ makerAssetAmount: constants.ZERO_AMOUNT,
+ takerAssetAmount: constants.ZERO_AMOUNT,
+ makerAssetData: constants.NULL_BYTES,
+ takerAssetData: constants.NULL_BYTES,
+ salt: generatePseudoRandomSalt(),
+ exchangeAddress: constants.NULL_ADDRESS,
+ feeRecipientAddress: constants.NULL_ADDRESS,
+ expirationTimeSeconds: constants.INFINITE_TIMESTAMP_SEC,
+ };
+}
+
function generateDefaultCreateOrderOpts(): {
takerAddress: string;
senderAddress: string;