From 21292ad15ec9490acb8d3089286f3d81e83967b7 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 2 Jun 2017 16:29:12 +0200 Subject: Add balance check to `transferAsync` and related test --- src/contract_wrappers/token_wrapper.ts | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/contract_wrappers/token_wrapper.ts') diff --git a/src/contract_wrappers/token_wrapper.ts b/src/contract_wrappers/token_wrapper.ts index 6cb71c7e8..55e1e364b 100644 --- a/src/contract_wrappers/token_wrapper.ts +++ b/src/contract_wrappers/token_wrapper.ts @@ -102,6 +102,12 @@ export class TokenWrapper extends ContractWrapper { assert.isBigNumber('amountInBaseUnits', amountInBaseUnits); const tokenContract = await this.getTokenContractAsync(tokenAddress); + + const fromAddressBalance = await this.getBalanceAsync(tokenAddress, fromAddress); + if (fromAddressBalance.lessThan(amountInBaseUnits)) { + throw new Error(ZeroExError.INSUFFICIENT_BALANCE_FOR_TRANSFER); + } + await tokenContract.transfer(toAddress, amountInBaseUnits, { from: fromAddress, }); -- cgit v1.2.3