diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-10-04 19:21:39 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-10-04 19:31:09 +0800 |
commit | 8b7caef0db337a5f1b9bf41ee5f8a9157eda4d1d (patch) | |
tree | 898990b27b3b50797ebac7b439e0edf353fd26e2 | |
parent | 836d9be7fee9986c8ffa380633d873ba557511f4 (diff) | |
download | dexon-0x-contracts-8b7caef0db337a5f1b9bf41ee5f8a9157eda4d1d.tar.gz dexon-0x-contracts-8b7caef0db337a5f1b9bf41ee5f8a9157eda4d1d.tar.zst dexon-0x-contracts-8b7caef0db337a5f1b9bf41ee5f8a9157eda4d1d.zip |
Fix an issue when validation failed, but contract call will succeed
-rw-r--r-- | src/utils/order_validation_utils.ts | 6 | ||||
-rw-r--r-- | test/order_validation_test.ts | 32 |
2 files changed, 37 insertions, 1 deletions
diff --git a/src/utils/order_validation_utils.ts b/src/utils/order_validation_utils.ts index 6f7522c41..de20cf06d 100644 --- a/src/utils/order_validation_utils.ts +++ b/src/utils/order_validation_utils.ts @@ -121,7 +121,11 @@ export class OrderValidationUtils { } if (!isMakerTokenZRX) { - const makerZRXBalance = await this.tokenWrapper.getBalanceAsync(zrxTokenAddress, signedOrder.maker); + const isTakerTokenZRX = signedOrder.takerTokenAddress === zrxTokenAddress; + let makerZRXBalance = await this.tokenWrapper.getBalanceAsync(zrxTokenAddress, signedOrder.maker); + if (isTakerTokenZRX) { + makerZRXBalance = makerZRXBalance.plus(fillTakerAmount); + } const makerZRXAllowance = await this.tokenWrapper.getProxyAllowanceAsync( zrxTokenAddress, signedOrder.maker); diff --git a/test/order_validation_test.ts b/test/order_validation_test.ts index f625433eb..9e6817c8b 100644 --- a/test/order_validation_test.ts +++ b/test/order_validation_test.ts @@ -356,5 +356,37 @@ describe('OrderValidation', () => { )).to.be.rejectedWith(ExchangeContractErrs.InsufficientTakerAllowance); }); }); + describe('should not throw if user doesn\'t have sufficient ZRX to pay the fees, but will after a transfer', + () => { + let signedOrder: SignedOrder; + let txHash: string; + it('should not throw if maker will have enough ZRX to pay fees after the transfer', async () => { + const makerFee = new BigNumber(2); + const takerFee = new BigNumber(2); + signedOrder = await fillScenarios.createFillableSignedOrderWithFeesAsync( + makerTokenAddress, zrxTokenAddress, makerFee, takerFee, + makerAddress, takerAddress, fillableAmount, feeRecipient, + ); + txHash = await zeroEx.token.transferAsync(zrxTokenAddress, makerAddress, coinbase, makerFee); + await zeroEx.awaitTransactionMinedAsync(txHash); + await (orderValidationUtils as any).validateFillOrderMakerBalancesAllowancesThrowIfInvalidAsync( + signedOrder, fillTakerAmount, zrxTokenAddress, + ); + }); + it('should throw if maker will not have enough ZRX to pay fees even after the transfer', async () => { + const makerFee = fillableAmount.plus(1); + const takerFee = fillableAmount.plus(1); + signedOrder = await fillScenarios.createFillableSignedOrderWithFeesAsync( + makerTokenAddress, zrxTokenAddress, makerFee, takerFee, + makerAddress, takerAddress, fillableAmount, feeRecipient, + ); + txHash = await zeroEx.token.transferAsync(zrxTokenAddress, makerAddress, coinbase, makerFee); + await zeroEx.awaitTransactionMinedAsync(txHash); + return expect( + (orderValidationUtils as any).validateFillOrderMakerBalancesAllowancesThrowIfInvalidAsync( + signedOrder, fillTakerAmount, zrxTokenAddress, + )).to.be.rejectedWith(ExchangeContractErrs.InsufficientMakerFeeBalance); + }); + }); }); }); |