aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-08-24 00:50:51 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-08-24 15:55:02 +0800
commit8d6045c1d5737ff2e62f6f3b906cf639da1aa2ba (patch)
treeb6fc54d6a328cc4c307bcf95deea36a609c88b94
parentdc3756bc992b2db4eb26935f8861123ed76189e6 (diff)
downloaddexon-sol-tools-8d6045c1d5737ff2e62f6f3b906cf639da1aa2ba.tar
dexon-sol-tools-8d6045c1d5737ff2e62f6f3b906cf639da1aa2ba.tar.gz
dexon-sol-tools-8d6045c1d5737ff2e62f6f3b906cf639da1aa2ba.tar.bz2
dexon-sol-tools-8d6045c1d5737ff2e62f6f3b906cf639da1aa2ba.tar.lz
dexon-sol-tools-8d6045c1d5737ff2e62f6f3b906cf639da1aa2ba.tar.xz
dexon-sol-tools-8d6045c1d5737ff2e62f6f3b906cf639da1aa2ba.tar.zst
dexon-sol-tools-8d6045c1d5737ff2e62f6f3b906cf639da1aa2ba.zip
Add validation for the case where the order is fully filled or canceled and a test
-rw-r--r--src/types.ts1
-rw-r--r--src/utils/order_validation_utils.ts5
-rw-r--r--test/order_validation_test.ts9
3 files changed, 15 insertions, 0 deletions
diff --git a/src/types.ts b/src/types.ts
index 0de87ca71..5ba85a7d5 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -180,6 +180,7 @@ export enum ExchangeContractErrs {
OrderCancelExpired = 'ORDER_CANCEL_EXPIRED',
OrderCancelAmountZero = 'ORDER_CANCEL_AMOUNT_ZERO',
OrderAlreadyCancelledOrFilled = 'ORDER_ALREADY_CANCELLED_OR_FILLED',
+ OrderFillAmountZero = 'ORDER_FILL_AMOUNT_ZERO',
OrderRemainingFillAmountZero = 'ORDER_REMAINING_FILL_AMOUNT_ZERO',
OrderFillRoundingError = 'ORDER_FILL_ROUNDING_ERROR',
FillBalanceAllowanceError = 'FILL_BALANCE_ALLOWANCE_ERROR',
diff --git a/src/utils/order_validation_utils.ts b/src/utils/order_validation_utils.ts
index 6f9cd7b1a..445ad43f9 100644
--- a/src/utils/order_validation_utils.ts
+++ b/src/utils/order_validation_utils.ts
@@ -16,6 +16,11 @@ export class OrderValidationUtils {
takerAddress: string,
zrxTokenAddress: string): Promise<void> {
if (fillTakerTokenAmount.eq(0)) {
+ throw new Error(ExchangeContractErrs.OrderFillAmountZero);
+ }
+ const orderHash = utils.getOrderHashHex(signedOrder);
+ const unavailableTakerTokenAmount = await this.exchangeWrapper.getUnavailableTakerAmountAsync(orderHash);
+ if (signedOrder.makerTokenAmount.eq(unavailableTakerTokenAmount)) {
throw new Error(ExchangeContractErrs.OrderRemainingFillAmountZero);
}
if (signedOrder.taker !== constants.NULL_ADDRESS && signedOrder.taker !== takerAddress) {
diff --git a/test/order_validation_test.ts b/test/order_validation_test.ts
index 8982a9304..8a6303f3a 100644
--- a/test/order_validation_test.ts
+++ b/test/order_validation_test.ts
@@ -62,6 +62,15 @@ describe('OrderValidation', () => {
const zeroFillAmount = new BigNumber(0);
return expect(zeroEx.exchange.validateFillOrderThrowIfInvalidAsync(
signedOrder, zeroFillAmount, takerAddress,
+ )).to.be.rejectedWith(ExchangeContractErrs.OrderFillAmountZero);
+ });
+ it('should throw when the order is fully filled or cancelled', async () => {
+ const signedOrder = await fillScenarios.createFillableSignedOrderAsync(
+ makerTokenAddress, takerTokenAddress, makerAddress, takerAddress, fillableAmount,
+ );
+ await zeroEx.exchange.cancelOrderAsync(signedOrder, fillableAmount);
+ return expect(zeroEx.exchange.validateFillOrderThrowIfInvalidAsync(
+ signedOrder, fillableAmount, takerAddress,
)).to.be.rejectedWith(ExchangeContractErrs.OrderRemainingFillAmountZero);
});
it('should throw when sender is not a taker', async () => {