diff options
author | Leonid <logvinov.leon@gmail.com> | 2017-07-08 05:08:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-08 05:08:34 +0800 |
commit | 0876fc6cabb914c6db5206182c8bd8d747b40674 (patch) | |
tree | be3ffb112ade307d4e93fc4d7bafa5c86244a53c | |
parent | 90ddfe58a99eb241a86dff64f31263994c00ce2c (diff) | |
parent | 6593ddf35cdcd7f474ea0cd108c19f673bdc441c (diff) | |
download | dexon-sol-tools-0876fc6cabb914c6db5206182c8bd8d747b40674.tar dexon-sol-tools-0876fc6cabb914c6db5206182c8bd8d747b40674.tar.gz dexon-sol-tools-0876fc6cabb914c6db5206182c8bd8d747b40674.tar.bz2 dexon-sol-tools-0876fc6cabb914c6db5206182c8bd8d747b40674.tar.lz dexon-sol-tools-0876fc6cabb914c6db5206182c8bd8d747b40674.tar.xz dexon-sol-tools-0876fc6cabb914c6db5206182c8bd8d747b40674.tar.zst dexon-sol-tools-0876fc6cabb914c6db5206182c8bd8d747b40674.zip |
Merge branch 'master' into cache_net_version
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | package.json | 4 | ||||
-rw-r--r-- | src/contract_wrappers/exchange_wrapper.ts | 6 | ||||
-rw-r--r-- | test/0x.js_test.ts | 6 | ||||
-rw-r--r-- | test/exchange_wrapper_test.ts | 32 | ||||
-rw-r--r-- | test/utils/fill_scenarios.ts | 60 |
6 files changed, 56 insertions, 54 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bbd61114..413203e4c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ v0.9.0 - TBD * Move `zeroEx.exchange.getAvailableContractAddressesAsync` to `zeroEx.getAvailableExchangeContractAddressesAsync` (#94) * Move `zeroEx.exchange.getProxyAuthorizedContractAddressesAsync` to `zeroEx.getProxyAuthorizedExchangeContractAddressesAsync` (#94) * Cache `net_version` requests and invalidate the cache on calls to `setProvider` (#95) + * Rename `zeroEx.exchange.batchCancelOrderAsync` to `zeroEx.exchange.batchCancelOrdersAsync` + * Rename `zeroEx.exchange.batchFillOrderAsync` to `zeroEx.exchange.batchFillOrdersAsync` v0.8.0 - _Jul. 4, 2017_ ------------------------ diff --git a/package.json b/package.json index ced8071a3..0ac014e76 100644 --- a/package.json +++ b/package.json @@ -85,8 +85,8 @@ "typedoc": "^0.7.1", "typescript": "^2.3.3", "web3-provider-engine": "^13.0.1", - "web3-typescript-typings": "^0.0.10", - "webpack": "^2.6.0" + "web3-typescript-typings": "^0.0.11", + "webpack": "^3.1.0" }, "dependencies": { "bignumber.js": "^4.0.2", diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 2353c826a..fa4b5904b 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -297,8 +297,8 @@ export class ExchangeWrapper extends ContractWrapper { * Must be available via the supplied Web3.Provider passed to 0x.js. */ @decorators.contractCallErrorHandler - public async batchFillOrderAsync(orderFillRequests: OrderFillRequest[], - shouldCheckTransfer: boolean, takerAddress: string): Promise<void> { + public async batchFillOrdersAsync(orderFillRequests: OrderFillRequest[], + shouldCheckTransfer: boolean, takerAddress: string): Promise<void> { assert.doesConformToSchema('orderFillRequests', orderFillRequests, orderFillRequestsSchema); const exchangeContractAddresses = _.map( orderFillRequests, @@ -520,7 +520,7 @@ export class ExchangeWrapper extends ContractWrapper { * interface. */ @decorators.contractCallErrorHandler - public async batchCancelOrderAsync(orderCancellationRequests: OrderCancellationRequest[]): Promise<void> { + public async batchCancelOrdersAsync(orderCancellationRequests: OrderCancellationRequest[]): Promise<void> { assert.doesConformToSchema('orderCancellationRequests', orderCancellationRequests, orderCancellationRequestsSchema); const exchangeContractAddresses = _.map( diff --git a/test/0x.js_test.ts b/test/0x.js_test.ts index 0d8d63985..f25f104bd 100644 --- a/test/0x.js_test.ts +++ b/test/0x.js_test.ts @@ -163,7 +163,7 @@ describe('ZeroEx library', () => { _.each(stubs, s => s.restore()); stubs = []; }); - it ('Should return the correct ECSignature on TestPRC nodeVersion', async () => { + it('Should return the correct ECSignature on TestPRC nodeVersion', async () => { const orderHash = '0x6927e990021d23b1eb7b8789f6a6feaf98fe104bb0cf8259421b79f9a34222b0'; const expectedECSignature = { v: 27, @@ -173,7 +173,7 @@ describe('ZeroEx library', () => { const ecSignature = await zeroEx.signOrderHashAsync(orderHash, makerAddress); expect(ecSignature).to.deep.equal(expectedECSignature); }); - it ('should return the correct ECSignature on Parity > V1.6.6', async () => { + it('should return the correct ECSignature on Parity > V1.6.6', async () => { const newParityNodeVersion = 'Parity//v1.6.7-beta-e128418-20170518/x86_64-macos/rustc1.17.0'; const orderHash = '0x34decbedc118904df65f379a175bb39ca18209d6ce41d5ed549d54e6e0a95004'; // tslint:disable-next-line: max-line-length @@ -194,7 +194,7 @@ describe('ZeroEx library', () => { const ecSignature = await zeroEx.signOrderHashAsync(orderHash, makerAddress); expect(ecSignature).to.deep.equal(expectedECSignature); }); - it ('should return the correct ECSignature on Parity < V1.6.6', async () => { + it('should return the correct ECSignature on Parity < V1.6.6', async () => { const newParityNodeVersion = 'Parity//v1.6.6-beta-8c6e3f3-20170411/x86_64-macos/rustc1.16.0'; const orderHash = '0xc793e33ffded933b76f2f48d9aa3339fc090399d5e7f5dec8d3660f5480793f7'; // tslint:disable-next-line: max-line-length diff --git a/test/exchange_wrapper_test.ts b/test/exchange_wrapper_test.ts index 45da44f54..53032efd6 100644 --- a/test/exchange_wrapper_test.ts +++ b/test/exchange_wrapper_test.ts @@ -386,7 +386,7 @@ describe('ExchangeWrapper', () => { }); }); }); - describe('#batchFillOrderAsync', () => { + describe('#batchFillOrdersAsync', () => { let signedOrder: SignedOrder; let signedOrderHashHex: string; let anotherSignedOrder: SignedOrder; @@ -414,10 +414,10 @@ describe('ExchangeWrapper', () => { }); describe('successful batch fills', () => { it('should no-op for an empty batch', async () => { - await zeroEx.exchange.batchFillOrderAsync([], shouldCheckTransfer, takerAddress); + await zeroEx.exchange.batchFillOrdersAsync([], shouldCheckTransfer, takerAddress); }); it('should successfully fill multiple orders', async () => { - await zeroEx.exchange.batchFillOrderAsync(orderFillBatch, shouldCheckTransfer, takerAddress); + await zeroEx.exchange.batchFillOrdersAsync(orderFillBatch, shouldCheckTransfer, takerAddress); const filledAmount = await zeroEx.exchange.getFilledTakerAmountAsync( signedOrderHashHex, exchangeContractAddress, ); @@ -531,7 +531,7 @@ describe('ExchangeWrapper', () => { }); }); }); - describe('#batchCancelOrderAsync', () => { + describe('#batchCancelOrdersAsync', () => { let anotherSignedOrder: SignedOrder; let anotherOrderHashHex: string; let cancelBatch: OrderCancellationRequest[]; @@ -556,7 +556,7 @@ describe('ExchangeWrapper', () => { const signedOrderWithDifferentMaker = await fillScenarios.createFillableSignedOrderAsync( makerTokenAddress, takerTokenAddress, takerAddress, takerAddress, fillableAmount, ); - return expect(zeroEx.exchange.batchCancelOrderAsync([ + return expect(zeroEx.exchange.batchCancelOrdersAsync([ cancelBatch[0], { order: signedOrderWithDifferentMaker, @@ -567,7 +567,7 @@ describe('ExchangeWrapper', () => { }); describe('successful batch cancels', () => { it('should cancel a batch of orders', async () => { - await zeroEx.exchange.batchCancelOrderAsync(cancelBatch); + await zeroEx.exchange.batchCancelOrdersAsync(cancelBatch); const cancelledAmount = await zeroEx.exchange.getCanceledTakerAmountAsync( orderHashHex, exchangeContractAddress, ); @@ -603,19 +603,19 @@ describe('ExchangeWrapper', () => { orderHash = zeroEx.getOrderHashHex(signedOrder); }); describe('#getUnavailableTakerAmountAsync', () => { - it ('should throw if passed an invalid orderHash', async () => { + it('should throw if passed an invalid orderHash', async () => { const invalidOrderHashHex = '0x123'; return expect(zeroEx.exchange.getUnavailableTakerAmountAsync( invalidOrderHashHex, exchangeContractAddress, )).to.be.rejected(); }); - it ('should return zero if passed a valid but non-existent orderHash', async () => { + it('should return zero if passed a valid but non-existent orderHash', async () => { const unavailableValueT = await zeroEx.exchange.getUnavailableTakerAmountAsync( NON_EXISTENT_ORDER_HASH, exchangeContractAddress, ); expect(unavailableValueT).to.be.bignumber.equal(0); }); - it ('should return the unavailableValueT for a valid and partially filled orderHash', async () => { + it('should return the unavailableValueT for a valid and partially filled orderHash', async () => { const unavailableValueT = await zeroEx.exchange.getUnavailableTakerAmountAsync( orderHash, exchangeContractAddress, ); @@ -623,19 +623,19 @@ describe('ExchangeWrapper', () => { }); }); describe('#getFilledTakerAmountAsync', () => { - it ('should throw if passed an invalid orderHash', async () => { + it('should throw if passed an invalid orderHash', async () => { const invalidOrderHashHex = '0x123'; return expect(zeroEx.exchange.getFilledTakerAmountAsync( invalidOrderHashHex, exchangeContractAddress, )).to.be.rejected(); }); - it ('should return zero if passed a valid but non-existent orderHash', async () => { + it('should return zero if passed a valid but non-existent orderHash', async () => { const filledValueT = await zeroEx.exchange.getFilledTakerAmountAsync( NON_EXISTENT_ORDER_HASH, exchangeContractAddress, ); expect(filledValueT).to.be.bignumber.equal(0); }); - it ('should return the filledValueT for a valid and partially filled orderHash', async () => { + it('should return the filledValueT for a valid and partially filled orderHash', async () => { const filledValueT = await zeroEx.exchange.getFilledTakerAmountAsync( orderHash, exchangeContractAddress, ); @@ -643,25 +643,25 @@ describe('ExchangeWrapper', () => { }); }); describe('#getCanceledTakerAmountAsync', () => { - it ('should throw if passed an invalid orderHash', async () => { + it('should throw if passed an invalid orderHash', async () => { const invalidOrderHashHex = '0x123'; return expect(zeroEx.exchange.getCanceledTakerAmountAsync( invalidOrderHashHex, exchangeContractAddress, )).to.be.rejected(); }); - it ('should return zero if passed a valid but non-existent orderHash', async () => { + it('should return zero if passed a valid but non-existent orderHash', async () => { const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync( NON_EXISTENT_ORDER_HASH, exchangeContractAddress, ); expect(cancelledValueT).to.be.bignumber.equal(0); }); - it ('should return the cancelledValueT for a valid and partially filled orderHash', async () => { + it('should return the cancelledValueT for a valid and partially filled orderHash', async () => { const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync( orderHash, exchangeContractAddress, ); expect(cancelledValueT).to.be.bignumber.equal(0); }); - it ('should return the cancelledValueT for a valid and cancelled orderHash', async () => { + it('should return the cancelledValueT for a valid and cancelled orderHash', async () => { const cancelAmount = fillableAmount.minus(partialFillAmount); await zeroEx.exchange.cancelOrderAsync(signedOrder, cancelAmount); const cancelledValueT = await zeroEx.exchange.getCanceledTakerAmountAsync( diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts index 65a912955..bebf82fd8 100644 --- a/test/utils/fill_scenarios.ts +++ b/test/utils/fill_scenarios.ts @@ -71,37 +71,15 @@ export class FillScenarios { makerAddress: string, takerAddress: string, makerFillableAmount: BigNumber.BigNumber, takerFillableAmount: BigNumber.BigNumber, feeRecepient: string, expirationUnixTimestampSec?: BigNumber.BigNumber): Promise<SignedOrder> { - await this.zeroEx.token.transferAsync(makerTokenAddress, this.coinbase, makerAddress, makerFillableAmount); - const oldMakerAllowance = await this.zeroEx.token.getProxyAllowanceAsync(makerTokenAddress, makerAddress); - const newMakerAllowance = oldMakerAllowance.plus(makerFillableAmount); - await this.zeroEx.token.setProxyAllowanceAsync( - makerTokenAddress, makerAddress, newMakerAllowance, - ); - await this.zeroEx.token.transferAsync(takerTokenAddress, this.coinbase, takerAddress, takerFillableAmount); - const oldTakerAllowance = await this.zeroEx.token.getProxyAllowanceAsync(takerTokenAddress, takerAddress); - const newTakerAllowance = oldTakerAllowance.plus(takerFillableAmount); - await this.zeroEx.token.setProxyAllowanceAsync( - takerTokenAddress, takerAddress, newTakerAllowance, - ); - if (!makerFee.isZero()) { - await this.zeroEx.token.transferAsync(this.zrxTokenAddress, this.coinbase, makerAddress, makerFee); - const oldMakerFeeAllowance = - await this.zeroEx.token.getProxyAllowanceAsync(this.zrxTokenAddress, makerAddress); - const newMakerFeeAllowance = oldMakerFeeAllowance.plus(makerFee); - await this.zeroEx.token.setProxyAllowanceAsync( - this.zrxTokenAddress, makerAddress, newMakerFeeAllowance, - ); - } - if (!takerFee.isZero()) { - await this.zeroEx.token.transferAsync(this.zrxTokenAddress, this.coinbase, takerAddress, takerFee); - const oldTakerFeeAllowance = - await this.zeroEx.token.getProxyAllowanceAsync(this.zrxTokenAddress, takerAddress); - const newTakerFeeAllowance = oldTakerFeeAllowance.plus(takerFee); - await this.zeroEx.token.setProxyAllowanceAsync( - this.zrxTokenAddress, takerAddress, newTakerFeeAllowance, - ); - } + await Promise.all([ + this.increaseBalanceAndAllowanceAsync(makerTokenAddress, makerAddress, makerFillableAmount), + this.increaseBalanceAndAllowanceAsync(takerTokenAddress, takerAddress, takerFillableAmount), + ]); + await Promise.all([ + this.increaseBalanceAndAllowanceAsync(this.zrxTokenAddress, makerAddress, makerFee), + this.increaseBalanceAndAllowanceAsync(this.zrxTokenAddress, takerAddress, takerFee), + ]); const signedOrder = await orderFactory.createSignedOrderAsync(this.zeroEx, makerAddress, takerAddress, makerFee, takerFee, @@ -109,4 +87,26 @@ export class FillScenarios { this.exchangeContractAddress, feeRecepient, expirationUnixTimestampSec); return signedOrder; } + private async increaseBalanceAndAllowanceAsync( + tokenAddress: string, address: string, amount: BigNumber.BigNumber): Promise<void> { + if (amount.isZero()) { + return; // noop + } + await Promise.all([ + this.increaseBalanceAsync(tokenAddress, address, amount), + this.increaseAllowanceAsync(tokenAddress, address, amount), + ]); + } + private async increaseBalanceAsync( + tokenAddress: string, address: string, amount: BigNumber.BigNumber): Promise<void> { + await this.zeroEx.token.transferAsync(tokenAddress, this.coinbase, address, amount); + } + private async increaseAllowanceAsync( + tokenAddress: string, address: string, amount: BigNumber.BigNumber): Promise<void> { + const oldMakerAllowance = await this.zeroEx.token.getProxyAllowanceAsync(tokenAddress, address); + const newMakerAllowance = oldMakerAllowance.plus(amount); + await this.zeroEx.token.setProxyAllowanceAsync( + tokenAddress, address, newMakerAllowance, + ); + } } |