aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/contract_wrappers/exchange_wrapper.ts9
-rw-r--r--src/types.ts5
-rw-r--r--test/exchange_wrapper_test.ts4
3 files changed, 16 insertions, 2 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts
index d1763e307..7a5b6ac8c 100644
--- a/src/contract_wrappers/exchange_wrapper.ts
+++ b/src/contract_wrappers/exchange_wrapper.ts
@@ -4,6 +4,7 @@ import {
ECSignature,
ExchangeContract,
ExchangeContractErrs,
+ FillOrderValidationErrs,
OrderValues,
OrderAddresses,
SignedOrder,
@@ -66,6 +67,8 @@ export class ExchangeWrapper extends ContractWrapper {
const senderAddress = await this.web3Wrapper.getSenderAddressOrThrowAsync();
const exchangeInstance = await this.getExchangeInstanceOrThrowAsync();
+ this.validateFillOrder(signedOrder, fillAmount, senderAddress, shouldCheckTransfer);
+
const orderAddresses: OrderAddresses = [
signedOrder.maker,
signedOrder.taker,
@@ -108,6 +111,12 @@ export class ExchangeWrapper extends ContractWrapper {
);
this.throwErrorLogsAsErrors(response.logs);
}
+ private validateFillOrder(signedOrder: SignedOrder, fillAmount: BigNumber.BigNumber, senderAddress: string,
+ shouldCheckTransfer: boolean = true) {
+ if (fillAmount.eq(0)) {
+ throw new Error(FillOrderValidationErrs.FILL_AMOUNT_IS_ZERO);
+ }
+ }
private async getExchangeInstanceOrThrowAsync(): Promise<ExchangeContract> {
const contractInstance = await this.instantiateContractIfExistsAsync((ExchangeArtifacts as any));
return contractInstance as ExchangeContract;
diff --git a/src/types.ts b/src/types.ts
index 7d668e78a..d9ed0b6bf 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -79,6 +79,11 @@ export enum ExchangeContractErrs {
ERROR_CANCEL_NO_VALUE, // Order has already been fully filled or cancelled
}
+export const FillOrderValidationErrs = strEnum([
+ 'FILL_AMOUNT_IS_ZERO',
+]);
+export type FillOrderValidationErrs = keyof typeof FillOrderValidationErrs;
+
export interface ContractResponse {
logs: ContractEvent[];
}
diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts
index b2fb1894b..4867427ae 100644
--- a/test/exchange_wrapper_test.ts
+++ b/test/exchange_wrapper_test.ts
@@ -7,7 +7,7 @@ import * as _ from 'lodash';
import {BlockchainLifecycle} from './utils/blockchain_lifecycle';
import * as BigNumber from 'bignumber.js';
import {orderFactory} from './utils/order_factory';
-import {Token} from '../src/types';
+import {FillOrderValidationErrs, Token} from '../src/types';
import * as Web3 from 'web3';
import * as dirtyChai from 'dirty-chai';
import ChaiBigNumber = require('chai-bignumber');
@@ -134,7 +134,7 @@ describe('ExchangeWrapper', () => {
5, addressBySymbol.MLN, 5, addressBySymbol.GNT);
const fillAmount = new BigNumber(0);
expect(zeroEx.exchange.fillOrderAsync(signedOrder, fillAmount))
- .to.be.rejectedWith('This order has already been filled or cancelled');
+ .to.be.rejectedWith(FillOrderValidationErrs.FILL_AMOUNT_IS_ZERO);
});
});
describe('successful fills', () => {