aboutsummaryrefslogtreecommitdiffstats
path: root/test/utils/fill_scenarios.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-07-05 14:25:47 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-07-08 00:58:56 +0800
commit198cd364db9b87a5011622411b8decebadc6bdd0 (patch)
tree3974d068d5026bc1b7badd0af8d7b101e2554f87 /test/utils/fill_scenarios.ts
parent03a6e1dac55d174701493cacdd7db46a9aeed25b (diff)
downloaddexon-0x-contracts-198cd364db9b87a5011622411b8decebadc6bdd0.tar.gz
dexon-0x-contracts-198cd364db9b87a5011622411b8decebadc6bdd0.tar.zst
dexon-0x-contracts-198cd364db9b87a5011622411b8decebadc6bdd0.zip
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..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<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;
+ }
+ 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,
+ );
+ }
}