From badbaa39fc000e6febced9d8d0118565af7648dc Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 7 Jun 2017 17:46:55 +0200 Subject: Address feedback --- src/contract_wrappers/exchange_wrapper.ts | 19 +++++++++++-------- src/types.ts | 1 + test/exchange_wrapper_test.ts | 12 ++++-------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index e4d360690..af8b8db24 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -18,7 +18,8 @@ import { CreateContractEvent, ContractEventObj, EventCallback, - ContractResponse, OrderCancellationRequest, + ContractResponse, + OrderCancellationRequest, } from '../types'; import {assert} from '../utils/assert'; import {utils} from '../utils/utils'; @@ -187,16 +188,18 @@ export class ExchangeWrapper extends ContractWrapper { */ public async batchCancelOrderAsync(cancellationRequestsBatch: OrderCancellationRequest[]): Promise { const makers = _.map(cancellationRequestsBatch, cancellationRequest => cancellationRequest.order.maker); - assert.assert(!_.isEmpty(cancellationRequestsBatch), 'Can not cancel an empty batch'); - assert.assert(_.uniq(makers).length === 1, 'Can not cancel orders from multiple makers in a single batch'); + if (_.isEmpty(cancellationRequestsBatch)) { + return; + } + assert.assert(_.uniq(makers).length === 1, ExchangeContractErrs.MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH); const maker = makers[0]; + await assert.isSenderAddressAvailableAsync(this.web3Wrapper, 'maker', maker); _.forEach(cancellationRequestsBatch, - async (cancellationRequest: OrderCancellationRequest) => { - assert.doesConformToSchema('order', + async (cancellationRequest: OrderCancellationRequest, i: number) => { + assert.doesConformToSchema(`orderCancellationRequests[${i}].order`, SchemaValidator.convertToJSONSchemaCompatibleObject(cancellationRequest.order as object), orderSchema); - assert.isBigNumber('takerTokenCancelAmount', cancellationRequest.takerTokenCancelAmount); - await assert.isSenderAddressAvailableAsync(this.web3Wrapper, 'order.maker', - cancellationRequest.order.maker); + assert.isBigNumber(`orderCancellationRequests[${i}].takerTokenCancelAmount`, + cancellationRequest.takerTokenCancelAmount); await this.validateCancelOrderAndThrowIfInvalidAsync( cancellationRequest.order, cancellationRequest.takerTokenCancelAmount); }); diff --git a/src/types.ts b/src/types.ts index 1034893a4..c58e5fd02 100644 --- a/src/types.ts +++ b/src/types.ts @@ -145,6 +145,7 @@ export const ExchangeContractErrs = strEnum([ 'INSUFFICIENT_MAKER_FEE_BALANCE', 'INSUFFICIENT_MAKER_FEE_ALLOWANCE', 'TRANSACTION_SENDER_IS_NOT_FILL_ORDER_TAKER', + 'MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH' ]); export type ExchangeContractErrs = keyof typeof ExchangeContractErrs; diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 68224a68c..88a2e2277 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -395,21 +395,17 @@ describe('ExchangeWrapper', () => { ]; }); describe('failed batch cancels', () => { - it('should throw when orders are empty', async () => { - return expect(zeroEx.exchange.batchCancelOrderAsync([])) - .to.be.rejectedWith('Can not cancel an empty batch'); - }); - it.only('should throw when orders have different makers', async () => { - const signedOrderWithADifferentMaker = await fillScenarios.createFillableSignedOrderAsync( + it('should throw when orders have different makers', async () => { + const signedOrderWithDifferentMaker = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, takerAddress, takerAddress, fillableAmount, ); return expect(zeroEx.exchange.batchCancelOrderAsync([ cancelBatch[0], { - order: signedOrderWithADifferentMaker, + order: signedOrderWithDifferentMaker, takerTokenCancelAmount: cancelAmount, }, - ])).to.be.rejectedWith('Can not cancel orders from multiple makers in a single batch'); + ])).to.be.rejectedWith(ExchangeContractErrs.MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH); }); }); describe('successful batch cancels', () => { -- cgit v1.2.3