diff options
author | Fabio Berger <me@fabioberger.com> | 2017-06-01 22:21:09 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-06-01 22:21:09 +0800 |
commit | abd113f61f67b08b9a232a89832b1db4318dac9e (patch) | |
tree | 757df0cc0298508a94b4105fde323cf01ef9d0ea | |
parent | 44f11442424c88d1130ee398d0714636c5ade045 (diff) | |
parent | 52bdc0d3432ef917cca15522cea78255d03d82f6 (diff) | |
download | dexon-sol-tools-abd113f61f67b08b9a232a89832b1db4318dac9e.tar dexon-sol-tools-abd113f61f67b08b9a232a89832b1db4318dac9e.tar.gz dexon-sol-tools-abd113f61f67b08b9a232a89832b1db4318dac9e.tar.bz2 dexon-sol-tools-abd113f61f67b08b9a232a89832b1db4318dac9e.tar.lz dexon-sol-tools-abd113f61f67b08b9a232a89832b1db4318dac9e.tar.xz dexon-sol-tools-abd113f61f67b08b9a232a89832b1db4318dac9e.tar.zst dexon-sol-tools-abd113f61f67b08b9a232a89832b1db4318dac9e.zip |
Merge branch 'fillOrderAsync' of github.com:0xProject/0x.js into fillOrderAsync
-rw-r--r-- | package.json | 2 | ||||
-rw-r--r-- | src/contract_wrappers/exchange_wrapper.ts | 3 | ||||
-rw-r--r-- | src/types.ts | 1 | ||||
-rw-r--r-- | test/utils/order_factory.ts | 10 |
4 files changed, 12 insertions, 4 deletions
diff --git a/package.json b/package.json index 8cef48c95..8b472f2a9 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "pretest:umd": "run-s clean build:*:dev", "substitute_umd_bundle": "npm run remove_src_files_not_used_by_tests; shx mv _bundles/* lib/src", "remove_src_files_not_used_by_tests": "find ./lib/src \\( -path ./lib/src/utils -o -path ./lib/src/schemas -o -path \"./lib/src/types.*\" \\) -prune -o -type f -print | xargs rm", - "run_mocha": "mocha lib/test/**/*_test.js" + "run_mocha": "mocha lib/test/**/*_test.js --timeout 3000" }, "config": { "artifacts": "Proxy Exchange TokenRegistry Token Mintable EtherToken", diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 40f22bd28..ded0d3519 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -125,6 +125,9 @@ export class ExchangeWrapper extends ContractWrapper { if (signedOrder.taker !== constants.NULL_ADDRESS && signedOrder.taker !== senderAddress) { throw new Error(FillOrderValidationErrs.NOT_A_TAKER); } + if (signedOrder.expirationUnixTimestampSec.lessThan(Date.now() / 1000)) { + throw new Error(FillOrderValidationErrs.EXPIRED); + } } private async getExchangeInstanceOrThrowAsync(): Promise<ExchangeContract> { const contractInstance = await this.instantiateContractIfExistsAsync((ExchangeArtifacts as any)); diff --git a/src/types.ts b/src/types.ts index 216026b3d..7c5e1825d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -88,6 +88,7 @@ export type ExchangeContractErrs = keyof typeof ExchangeContractErrs; export const FillOrderValidationErrs = strEnum([ 'FILL_AMOUNT_IS_ZERO', 'NOT_A_TAKER', + 'EXPIRED', ]); export type FillOrderValidationErrs = keyof typeof FillOrderValidationErrs; diff --git a/test/utils/order_factory.ts b/test/utils/order_factory.ts index e41e973ee..c6c6ed927 100644 --- a/test/utils/order_factory.ts +++ b/test/utils/order_factory.ts @@ -14,10 +14,14 @@ export const orderFactory = { makerTokenAmount: BigNumber.BigNumber|number, makerTokenAddress: string, takerTokenAmount: BigNumber.BigNumber|number, - takerTokenAddress: string): Promise<SignedOrder> { + takerTokenAddress: string, + expirationUnixTimestampSec?: BigNumber.BigNumber): Promise<SignedOrder> { // TODO refactor and check const exchangeAddress: string = (ExchangeArtifacts as any).networks[networkId].address; - const INF_TIMESTAMP = 2524604400; + const INF_TIMESTAMP = new BigNumber(2524604400); + expirationUnixTimestampSec = _.isUndefined(expirationUnixTimestampSec) ? + INF_TIMESTAMP : + expirationUnixTimestampSec; const order = { maker, taker, @@ -29,7 +33,7 @@ export const orderFactory = { takerTokenAddress, salt: ZeroEx.generatePseudoRandomSalt(), feeRecipient: constants.NULL_ADDRESS, - expirationUnixTimestampSec: new BigNumber(INF_TIMESTAMP), + expirationUnixTimestampSec, }; const orderHash = ZeroEx.getOrderHashHex(exchangeAddress, order); const ecSignature = await zeroEx.signOrderHashAsync(orderHash); |