diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-06-09 01:21:46 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-06-09 01:22:48 +0800 |
commit | a786776d7cf52ab70d54e0dc421dc645a412b3c7 (patch) | |
tree | 7283487385f2e966f9e3453b176713479061c4d6 /src | |
parent | c94485dfbba388f481ca6c10bd62b863d7429223 (diff) | |
download | dexon-sol-tools-a786776d7cf52ab70d54e0dc421dc645a412b3c7.tar.gz dexon-sol-tools-a786776d7cf52ab70d54e0dc421dc645a412b3c7.tar.zst dexon-sol-tools-a786776d7cf52ab70d54e0dc421dc645a412b3c7.zip |
Add assert.hashAtMostOneUniqueValue
Diffstat (limited to 'src')
-rw-r--r-- | src/contract_wrappers/exchange_wrapper.ts | 12 | ||||
-rw-r--r-- | src/types.ts | 2 | ||||
-rw-r--r-- | src/utils/assert.ts | 3 |
3 files changed, 10 insertions, 7 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index a7d1f52ae..aa79729c3 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -161,15 +161,15 @@ export class ExchangeWrapper extends ContractWrapper { this.throwErrorLogsAsErrors(response.logs); } /** - * Sequentially and atomically fills signedOrders up to takerTokenFillAmount. - * If fill amount is reached - it succeeds and doesn't fill the rest of the orders. - * If fill amount is not reached - it just fills all the orders. + * Sequentially and atomically fills signedOrders up to the specified takerTokenFillAmount. + * If the fill amount is reached - it succeeds and does not fill the rest of the orders. + * If fill amount is not reached - it fills as much of the fill amount as possible and succeeds. */ public async fillOrdersUpToAsync(signedOrders: SignedOrder[], takerTokenFillAmount: BigNumber.BigNumber, shouldCheckTransfer: boolean, takerAddress: string): Promise<void> { const takerTokenAddresses = _.map(signedOrders, signedOrder => signedOrder.takerTokenAddress); - assert.assert(_.uniq(takerTokenAddresses).length <= 1, - ExchangeContractErrs.MULTIPLE_TAKER_TOKENS_IN_FILL_UP_TO); + assert.hashAtMostOneUniqueValue(takerTokenAddresses, + ExchangeContractErrs.MULTIPLE_TAKER_TOKENS_IN_FILL_UP_TO_DISALLOWED); assert.isBigNumber('takerTokenFillAmount', takerTokenFillAmount); assert.isBoolean('shouldCheckTransfer', shouldCheckTransfer); await assert.isSenderAddressAsync('takerAddress', takerAddress, this.web3Wrapper); @@ -433,7 +433,7 @@ export class ExchangeWrapper extends ContractWrapper { */ public async batchCancelOrderAsync(orderCancellationRequests: OrderCancellationRequest[]): Promise<void> { const makers = _.map(orderCancellationRequests, cancellationRequest => cancellationRequest.order.maker); - assert.assert(_.uniq(makers).length <= 1, ExchangeContractErrs.MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH); + assert.hashAtMostOneUniqueValue(makers, ExchangeContractErrs.MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH); const maker = makers[0]; await assert.isSenderAddressAsync('maker', maker, this.web3Wrapper); _.forEach(orderCancellationRequests, diff --git a/src/types.ts b/src/types.ts index 53476ab85..8f538a70d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -171,7 +171,7 @@ export const ExchangeContractErrs = strEnum([ 'TRANSACTION_SENDER_IS_NOT_FILL_ORDER_TAKER', 'MULTIPLE_MAKERS_IN_SINGLE_CANCEL_BATCH', 'INSUFFICIENT_REMAINING_FILL_AMOUNT', - 'MULTIPLE_TAKER_TOKENS_IN_FILL_UP_TO', + 'MULTIPLE_TAKER_TOKENS_IN_FILL_UP_TO_DISALLOWED', ]); export type ExchangeContractErrs = keyof typeof ExchangeContractErrs; diff --git a/src/utils/assert.ts b/src/utils/assert.ts index 4dc6945a2..c7c164ee5 100644 --- a/src/utils/assert.ts +++ b/src/utils/assert.ts @@ -42,6 +42,9 @@ export const assert = { const availableAddresses = await web3Wrapper.getAvailableAddressesAsync(); this.assert(!_.isEmpty(availableAddresses), 'No addresses were available on the provided web3 instance'); }, + hashAtMostOneUniqueValue(value: any[], errMsg: string): void { + this.assert(_.uniq(value).length <= 1, errMsg); + }, isNumber(variableName: string, value: number): void { this.assert(_.isFinite(value), this.typeAssertionMessage(variableName, 'number', value)); }, |