aboutsummaryrefslogtreecommitdiffstats
path: root/src/contract_wrappers
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-06-02 22:29:12 +0800
committerFabio Berger <me@fabioberger.com>2017-06-02 22:29:12 +0800
commit21292ad15ec9490acb8d3089286f3d81e83967b7 (patch)
tree1f08ab21da3f38b4573c623a87cb44c21c3fcbfc /src/contract_wrappers
parentaed96d593d2658f022a257d00124c244bb73bf92 (diff)
downloaddexon-sol-tools-21292ad15ec9490acb8d3089286f3d81e83967b7.tar
dexon-sol-tools-21292ad15ec9490acb8d3089286f3d81e83967b7.tar.gz
dexon-sol-tools-21292ad15ec9490acb8d3089286f3d81e83967b7.tar.bz2
dexon-sol-tools-21292ad15ec9490acb8d3089286f3d81e83967b7.tar.lz
dexon-sol-tools-21292ad15ec9490acb8d3089286f3d81e83967b7.tar.xz
dexon-sol-tools-21292ad15ec9490acb8d3089286f3d81e83967b7.tar.zst
dexon-sol-tools-21292ad15ec9490acb8d3089286f3d81e83967b7.zip
Add balance check to `transferAsync` and related test
Diffstat (limited to 'src/contract_wrappers')
-rw-r--r--src/contract_wrappers/token_wrapper.ts6
1 files changed, 6 insertions, 0 deletions
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,
});