aboutsummaryrefslogtreecommitdiffstats
path: root/test/utils/fill_scenarios.ts
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2017-07-08 05:07:41 +0800
committerGitHub <noreply@github.com>2017-07-08 05:07:41 +0800
commit6593ddf35cdcd7f474ea0cd108c19f673bdc441c (patch)
treeb56b9ddfd4282d620e8e58d5acc80cc6bf1c8b22 /test/utils/fill_scenarios.ts
parentf7515b489d10185e9e075dc9b73baa58a63cf6c4 (diff)
parent23f32b6bbafdf4adc75d32f2438ef8917e792cfb (diff)
downloaddexon-sol-tools-6593ddf35cdcd7f474ea0cd108c19f673bdc441c.tar
dexon-sol-tools-6593ddf35cdcd7f474ea0cd108c19f673bdc441c.tar.gz
dexon-sol-tools-6593ddf35cdcd7f474ea0cd108c19f673bdc441c.tar.bz2
dexon-sol-tools-6593ddf35cdcd7f474ea0cd108c19f673bdc441c.tar.lz
dexon-sol-tools-6593ddf35cdcd7f474ea0cd108c19f673bdc441c.tar.xz
dexon-sol-tools-6593ddf35cdcd7f474ea0cd108c19f673bdc441c.tar.zst
dexon-sol-tools-6593ddf35cdcd7f474ea0cd108c19f673bdc441c.zip
Merge pull request #97 from 0xProject/speedup-tests
Paralellize fill scenarios
Diffstat (limited to 'test/utils/fill_scenarios.ts')
-rw-r--r--test/utils/fill_scenarios.ts60
1 files changed, 30 insertions, 30 deletions
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,
+ );
+ }
}