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 /test/utils | |
parent | 90ddfe58a99eb241a86dff64f31263994c00ce2c (diff) | |
parent | 6593ddf35cdcd7f474ea0cd108c19f673bdc441c (diff) | |
download | dexon-0x-contracts-0876fc6cabb914c6db5206182c8bd8d747b40674.tar.gz dexon-0x-contracts-0876fc6cabb914c6db5206182c8bd8d747b40674.tar.zst dexon-0x-contracts-0876fc6cabb914c6db5206182c8bd8d747b40674.zip |
Merge branch 'master' into cache_net_version
Diffstat (limited to 'test/utils')
-rw-r--r-- | test/utils/fill_scenarios.ts | 60 |
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, + ); + } } |