From 857a35d4f71c1c954033c3b0505250e18be21cfb Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 9 Nov 2018 00:45:48 +0100 Subject: Fix validateOrderFillableOrThrowAsync method so it also checks order signature, cancelled, cancelledUpTo, and throws helpful error messages --- packages/contracts/test/utils/exchange_wrapper.ts | 4 ++++ .../test/utils/simple_order_filled_cancelled_fetcher.ts | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/test/utils/exchange_wrapper.ts b/packages/contracts/test/utils/exchange_wrapper.ts index 29dba690a..cfff682e1 100644 --- a/packages/contracts/test/utils/exchange_wrapper.ts +++ b/packages/contracts/test/utils/exchange_wrapper.ts @@ -219,6 +219,10 @@ export class ExchangeWrapper { const isCancelled = await this._exchange.cancelled.callAsync(orderHashHex); return isCancelled; } + public async getOrderEpochAsync(makerAddress: string, takerAddress: string): Promise { + const orderEpoch = new BigNumber(await this._exchange.orderEpoch.callAsync(makerAddress, takerAddress)); + return orderEpoch; + } public async getOrderInfoAsync(signedOrder: SignedOrder): Promise { const orderInfo = (await this._exchange.getOrderInfo.callAsync(signedOrder)) as OrderInfo; return orderInfo; diff --git a/packages/contracts/test/utils/simple_order_filled_cancelled_fetcher.ts b/packages/contracts/test/utils/simple_order_filled_cancelled_fetcher.ts index 5f5575c7b..af959e00e 100644 --- a/packages/contracts/test/utils/simple_order_filled_cancelled_fetcher.ts +++ b/packages/contracts/test/utils/simple_order_filled_cancelled_fetcher.ts @@ -1,4 +1,5 @@ -import { AbstractOrderFilledCancelledFetcher } from '@0x/order-utils'; +import { AbstractOrderFilledCancelledFetcher, orderHashUtils } from '@0x/order-utils'; +import { SignedOrder } from '@0x/types'; import { BigNumber } from '@0x/utils'; import { ExchangeWrapper } from './exchange_wrapper'; @@ -14,9 +15,15 @@ export class SimpleOrderFilledCancelledFetcher implements AbstractOrderFilledCan const filledTakerAmount = new BigNumber(await this._exchangeWrapper.getTakerAssetFilledAmountAsync(orderHash)); return filledTakerAmount; } - public async isOrderCancelledAsync(orderHash: string): Promise { + public async isOrderCancelledAsync(signedOrder: SignedOrder): Promise { + const orderHash = orderHashUtils.getOrderHashHex(signedOrder); const isCancelled = await this._exchangeWrapper.isCancelledAsync(orderHash); - return isCancelled; + const orderEpoch = await this._exchangeWrapper.getOrderEpochAsync( + signedOrder.makerAddress, + signedOrder.senderAddress, + ); + const isCancelledByOrderEpoch = orderEpoch > signedOrder.salt; + return isCancelled || isCancelledByOrderEpoch; } public getZRXAssetData(): string { return this._zrxAssetData; -- cgit v1.2.3 From 1f0ac47bd97b88071a6380a728cfdb1457c2590c Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Sat, 10 Nov 2018 00:14:48 +0100 Subject: Move signature validation into OrderValidationUtils.validateOrderFillableOrThrowAsync --- packages/contracts/test/utils/fill_order_combinatorial_utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages/contracts') diff --git a/packages/contracts/test/utils/fill_order_combinatorial_utils.ts b/packages/contracts/test/utils/fill_order_combinatorial_utils.ts index 81bb33318..8046771f9 100644 --- a/packages/contracts/test/utils/fill_order_combinatorial_utils.ts +++ b/packages/contracts/test/utils/fill_order_combinatorial_utils.ts @@ -392,7 +392,7 @@ export class FillOrderCombinatorialUtils { ); // 5. If I fill it by X, what are the resulting balances/allowances/filled amounts expected? - const orderValidationUtils = new OrderValidationUtils(orderFilledCancelledFetcher); + const orderValidationUtils = new OrderValidationUtils(orderFilledCancelledFetcher, provider); const lazyStore = new BalanceAndProxyAllowanceLazyStore(balanceAndProxyAllowanceFetcher); const exchangeTransferSimulator = new ExchangeTransferSimulator(lazyStore); -- cgit v1.2.3 From 8aeb18bcc3d10dbc7610d597d98a4ad26131cf78 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 12 Nov 2018 10:22:03 +0100 Subject: rename param --- packages/contracts/test/utils/exchange_wrapper.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/test/utils/exchange_wrapper.ts b/packages/contracts/test/utils/exchange_wrapper.ts index cfff682e1..52322d5c4 100644 --- a/packages/contracts/test/utils/exchange_wrapper.ts +++ b/packages/contracts/test/utils/exchange_wrapper.ts @@ -219,8 +219,8 @@ export class ExchangeWrapper { const isCancelled = await this._exchange.cancelled.callAsync(orderHashHex); return isCancelled; } - public async getOrderEpochAsync(makerAddress: string, takerAddress: string): Promise { - const orderEpoch = new BigNumber(await this._exchange.orderEpoch.callAsync(makerAddress, takerAddress)); + public async getOrderEpochAsync(makerAddress: string, senderAddress: string): Promise { + const orderEpoch = new BigNumber(await this._exchange.orderEpoch.callAsync(makerAddress, senderAddress)); return orderEpoch; } public async getOrderInfoAsync(signedOrder: SignedOrder): Promise { -- cgit v1.2.3 From 8efc6c211246ec59a70d25754ccf1986944a5976 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 12 Nov 2018 10:25:33 +0100 Subject: Remove unnecessary conversion to BigNumber --- packages/contracts/test/utils/exchange_wrapper.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'packages/contracts') diff --git a/packages/contracts/test/utils/exchange_wrapper.ts b/packages/contracts/test/utils/exchange_wrapper.ts index 52322d5c4..c28989d3f 100644 --- a/packages/contracts/test/utils/exchange_wrapper.ts +++ b/packages/contracts/test/utils/exchange_wrapper.ts @@ -212,7 +212,7 @@ export class ExchangeWrapper { return tx; } public async getTakerAssetFilledAmountAsync(orderHashHex: string): Promise { - const filledAmount = new BigNumber(await this._exchange.filled.callAsync(orderHashHex)); + const filledAmount = await this._exchange.filled.callAsync(orderHashHex); return filledAmount; } public async isCancelledAsync(orderHashHex: string): Promise { @@ -220,7 +220,7 @@ export class ExchangeWrapper { return isCancelled; } public async getOrderEpochAsync(makerAddress: string, senderAddress: string): Promise { - const orderEpoch = new BigNumber(await this._exchange.orderEpoch.callAsync(makerAddress, senderAddress)); + const orderEpoch = await this._exchange.orderEpoch.callAsync(makerAddress, senderAddress); return orderEpoch; } public async getOrderInfoAsync(signedOrder: SignedOrder): Promise { -- cgit v1.2.3