diff --git a/contracts/exchange/test/utils/constants.ts b/contracts/exchange/test/utils/constants.ts new file mode 100644 index 0000000000..30a5081685 --- /dev/null +++ b/contracts/exchange/test/utils/constants.ts @@ -0,0 +1,35 @@ +import { ExchangeFunctionName } from './types'; + +export const constants = { + FUNCTIONS_WITH_MUTEX: [ + 'FILL_ORDER', + 'FILL_OR_KILL_ORDER', + 'BATCH_FILL_ORDERS', + 'BATCH_FILL_OR_KILL_ORDERS', + 'MARKET_BUY_ORDERS', + 'MARKET_SELL_ORDERS', + 'MATCH_ORDERS', + 'CANCEL_ORDER', + 'BATCH_CANCEL_ORDERS', + 'CANCEL_ORDERS_UP_TO', + 'PRE_SIGN', + 'SET_SIGNATURE_VALIDATOR_APPROVAL', + 'SET_ORDER_VALIDATOR_APPROVAL', + ], + SINGLE_FILL_FN_NAMES: [ + ExchangeFunctionName.FillOrder, + ExchangeFunctionName.FillOrKillOrder, + ExchangeFunctionName.FillOrderNoThrow, + ], + BATCH_FILL_FN_NAMES: [ + ExchangeFunctionName.BatchFillOrders, + ExchangeFunctionName.BatchFillOrKillOrders, + ExchangeFunctionName.BatchFillOrdersNoThrow, + ], + MARKET_FILL_FN_NAMES: [ + ExchangeFunctionName.MarketBuyOrders, + ExchangeFunctionName.MarketBuyOrdersNoThrow, + ExchangeFunctionName.MarketSellOrders, + ExchangeFunctionName.MarketSellOrdersNoThrow, + ], +}; diff --git a/contracts/test-utils/src/exchange_data_encoder.ts b/contracts/exchange/test/utils/exchange_data_encoder.ts similarity index 50% rename from contracts/test-utils/src/exchange_data_encoder.ts rename to contracts/exchange/test/utils/exchange_data_encoder.ts index b6e9815e76..51a6945b6e 100644 --- a/contracts/test-utils/src/exchange_data_encoder.ts +++ b/contracts/exchange/test/utils/exchange_data_encoder.ts @@ -1,44 +1,56 @@ -import { IExchangeContract } from '@0x/contracts-exchange'; -import { constants as devConstants, provider } from '@0x/contracts-test-utils'; +import { constants, provider } from '@0x/contracts-test-utils'; +import { orderHashUtils } from '@0x/order-utils'; import { SignedOrder } from '@0x/types'; -import { constants, provider } from './index'; +import { constants as exchangeConstants, ExchangeFunctionName, IExchangeContract } from '../../src'; export const exchangeDataEncoder = { encodeOrdersToExchangeData(fnName: string, orders: SignedOrder[] = []): string { - const exchangeInstance = new IExchangeContract(devConstants.NULL_ADDRESS, provider); + const exchangeInstance = new IExchangeContract(constants.NULL_ADDRESS, provider); let data; - if (constants.SINGLE_FILL_FN_NAMES.indexOf(fnName) !== -1) { + if (exchangeConstants.SINGLE_FILL_FN_NAMES.indexOf(fnName) !== -1) { data = (exchangeInstance as any)[fnName].getABIEncodedTransactionData( orders[0], orders[0].takerAssetAmount, orders[0].signature, ); - } else if (constants.BATCH_FILL_FN_NAMES.indexOf(fnName) !== -1) { + } else if (exchangeConstants.BATCH_FILL_FN_NAMES.indexOf(fnName) !== -1) { data = (exchangeInstance as any)[fnName].getABIEncodedTransactionData( orders, orders.map(order => order.takerAssetAmount), orders.map(order => order.signature), ); - } else if (constants.MARKET_FILL_FN_NAMES.indexOf(fnName) !== -1) { + } else if (exchangeConstants.MARKET_FILL_FN_NAMES.indexOf(fnName) !== -1) { data = (exchangeInstance as any)[fnName].getABIEncodedTransactionData( orders, orders.map(order => order.takerAssetAmount).reduce((prev, curr) => prev.plus(curr)), orders.map(order => order.signature), ); - } else if (fnName === constants.MATCH_ORDERS) { + } else if (fnName === ExchangeFunctionName.MatchOrders) { data = exchangeInstance.matchOrders.getABIEncodedTransactionData( orders[0], orders[1], orders[0].signature, orders[1].signature, ); - } else if (fnName === constants.CANCEL_ORDER) { + } else if (fnName === ExchangeFunctionName.CancelOrder) { data = exchangeInstance.cancelOrder.getABIEncodedTransactionData(orders[0]); - } else if (fnName === constants.BATCH_CANCEL_ORDERS) { + } else if (fnName === ExchangeFunctionName.BatchCancelOrders) { data = exchangeInstance.batchCancelOrders.getABIEncodedTransactionData(orders); - } else if (fnName === constants.CANCEL_ORDERS_UP_TO) { + } else if (fnName === ExchangeFunctionName.CancelOrdersUpTo) { data = exchangeInstance.cancelOrdersUpTo.getABIEncodedTransactionData(constants.ZERO_AMOUNT); + } else if (fnName === ExchangeFunctionName.PreSign) { + data = exchangeInstance.preSign.getABIEncodedTransactionData(orderHashUtils.getOrderHashHex(orders[0])); + } else if (fnName === ExchangeFunctionName.SetSignatureValidatorApproval) { + data = exchangeInstance.setSignatureValidatorApproval.getABIEncodedTransactionData( + constants.NULL_ADDRESS, + true, + ); + } else if (fnName === ExchangeFunctionName.SetOrderValidatorApproval) { + // data = exchangeInstance.setOrderValidatorApproval.getABIEncodedTransactionData( + // constants.NULL_ADDRESS, + // true, + // ); } else { throw new Error(`Error: ${fnName} not a supported function`); } diff --git a/contracts/exchange/test/utils/index.ts b/contracts/exchange/test/utils/index.ts index d88a382668..d481d4b669 100644 --- a/contracts/exchange/test/utils/index.ts +++ b/contracts/exchange/test/utils/index.ts @@ -1,3 +1,6 @@ export * from './exchange_wrapper'; export * from './fill_order_combinatorial_utils'; export * from './match_order_tester'; +export * from './exchange_data_encoder'; +export * from './types'; +export * from './constants'; diff --git a/contracts/exchange/test/utils/types.ts b/contracts/exchange/test/utils/types.ts index 5f12635a71..d1dc3d6b15 100644 --- a/contracts/exchange/test/utils/types.ts +++ b/contracts/exchange/test/utils/types.ts @@ -6,3 +6,23 @@ export interface AbiDecodedFillOrderData { takerAssetFillAmount: BigNumber; signature: string; } + +export enum ExchangeFunctionName { + FillOrder = 'fillOrder', + FillOrKillOrder = 'fillOrKillOrder', + FillOrderNoThrow = 'fillOrderNoThrow', + BatchFillOrders = 'batchFillOrders', + BatchFillOrKillOrders = 'batchFillOrKillOrders', + BatchFillOrdersNoThrow = 'batchFillOrdersNoThrow', + MarketBuyOrders = 'marketBuyOrders', + MarketBuyOrdersNoThrow = 'marketBuyOrdersNoThrow', + MarketSellOrders = 'marketSellOrders', + MarketSellOrdersNoThrow = 'marketSellOrdersNoThrow', + MatchOrders = 'matchOrders', + CancelOrder = 'cancelOrder', + BatchCancelOrders = 'batchCancelOrders', + CancelOrdersUpTo = 'cancelOrdersUpTo', + PreSign = 'preSign', + SetSignatureValidatorApproval = 'setSignatureValidatorApproval', + SetOrderValidatorApproval = 'setOrderValidatorApproval', +} diff --git a/contracts/test-utils/src/constants.ts b/contracts/test-utils/src/constants.ts index f003583623..0c5d590a5e 100644 --- a/contracts/test-utils/src/constants.ts +++ b/contracts/test-utils/src/constants.ts @@ -57,26 +57,5 @@ export const constants = { WORD_LENGTH: 32, ZERO_AMOUNT: new BigNumber(0), PERCENTAGE_DENOMINATOR: new BigNumber(10).pow(18), - FUNCTIONS_WITH_MUTEX: [ - 'FILL_ORDER', - 'FILL_OR_KILL_ORDER', - 'BATCH_FILL_ORDERS', - 'BATCH_FILL_OR_KILL_ORDERS', - 'MARKET_BUY_ORDERS', - 'MARKET_SELL_ORDERS', - 'MATCH_ORDERS', - 'CANCEL_ORDER', - 'BATCH_CANCEL_ORDERS', - 'CANCEL_ORDERS_UP_TO', - 'SET_SIGNATURE_VALIDATOR_APPROVAL', - ], - KECCAK256_NULL: ethUtil.addHexPrefix(ethUtil.bufferToHex(ethUtil.SHA3_NULL)), - SINGLE_FILL_FN_NAMES: ['fillOrder', 'fillOrKillOrder', 'fillOrderNoThrow'], - BATCH_FILL_FN_NAMES: ['batchFillOrders', 'batchFillOrKillOrders', 'batchFillOrdersNoThrow'], - MARKET_FILL_FN_NAMES: ['marketBuyOrders', 'marketBuyOrdersNoThrow', 'marketSellOrders', 'marketSellOrdersNoThrow'], - MATCH_ORDERS: 'matchOrders', - CANCEL_ORDER: 'cancelOrder', - BATCH_CANCEL_ORDERS: 'batchCancelOrders', - CANCEL_ORDERS_UP_TO: 'cancelOrdersUpTo', TIME_BUFFER: new BigNumber(1000), }; diff --git a/contracts/test-utils/src/index.ts b/contracts/test-utils/src/index.ts index 0087cfb6b3..c12a71bfda 100644 --- a/contracts/test-utils/src/index.ts +++ b/contracts/test-utils/src/index.ts @@ -28,7 +28,6 @@ export { OrderFactory } from './order_factory'; export { bytes32Values, testCombinatoriallyWithReferenceFuncAsync, uint256Values } from './combinatorial_utils'; export { TransactionFactory } from './transaction_factory'; export { testWithReferenceFuncAsync } from './test_with_reference'; -export { exchangeDataEncoder } from './exchange_data_encoder'; export { MarketBuyOrders, MarketSellOrders,