From 198cd364db9b87a5011622411b8decebadc6bdd0 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 4 Jul 2017 23:25:47 -0700 Subject: Paralellize fill scenarios --- test/utils/fill_scenarios.ts | 60 ++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'test/utils') diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts index 65a912955..439f22f9f 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 { - 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 { + if (amount.isZero()) { + return; + } + await Promise.all([ + this.increaseBalanceAsync(tokenAddress, address, amount), + this.increaseAllowanceAsync(tokenAddress, address, amount), + ]); + } + private async increaseBalanceAsync( + tokenAddress: string, address: string, amount: BigNumber.BigNumber): Promise { + await this.zeroEx.token.transferAsync(tokenAddress, this.coinbase, address, amount); + } + private async increaseAllowanceAsync( + tokenAddress: string, address: string, amount: BigNumber.BigNumber): Promise { + const oldMakerAllowance = await this.zeroEx.token.getProxyAllowanceAsync(tokenAddress, address); + const newMakerAllowance = oldMakerAllowance.plus(amount); + await this.zeroEx.token.setProxyAllowanceAsync( + tokenAddress, address, newMakerAllowance, + ); + } } -- cgit v1.2.3 From 23f32b6bbafdf4adc75d32f2438ef8917e792cfb Mon Sep 17 00:00:00 2001 From: Leonid Date: Fri, 7 Jul 2017 14:07:26 -0700 Subject: Add noop comment --- test/utils/fill_scenarios.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/utils') diff --git a/test/utils/fill_scenarios.ts b/test/utils/fill_scenarios.ts index 439f22f9f..bebf82fd8 100644 --- a/test/utils/fill_scenarios.ts +++ b/test/utils/fill_scenarios.ts @@ -90,7 +90,7 @@ export class FillScenarios { private async increaseBalanceAndAllowanceAsync( tokenAddress: string, address: string, amount: BigNumber.BigNumber): Promise { if (amount.isZero()) { - return; + return; // noop } await Promise.all([ this.increaseBalanceAsync(tokenAddress, address, amount), -- cgit v1.2.3