From 41098c6a35cc483b30ddc0566ca18c98b1548364 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 26 Jun 2017 11:20:16 -0700 Subject: refactor getBalanceInEthAsync to getBalanceInWeiAsync and change the test assertions to check if the discrepancy between the existing ETH balance and expected balance is small enough to simply be the gas cost used by the transaction. --- src/contract_wrappers/ether_token_wrapper.ts | 3 +-- src/web3_wrapper.ts | 9 ++++----- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/contract_wrappers/ether_token_wrapper.ts b/src/contract_wrappers/ether_token_wrapper.ts index e8efbc9a6..76e7289b7 100644 --- a/src/contract_wrappers/ether_token_wrapper.ts +++ b/src/contract_wrappers/ether_token_wrapper.ts @@ -28,8 +28,7 @@ export class EtherTokenWrapper extends ContractWrapper { assert.isBigNumber('amountInWei', amountInWei); await assert.isSenderAddressAsync('depositor', depositor, this._web3Wrapper); - const ethBalance = await this._web3Wrapper.getBalanceInEthAsync(depositor); - const ethBalanceInWei = this._web3Wrapper.toWei(ethBalance); + const ethBalanceInWei = await this._web3Wrapper.getBalanceInWeiAsync(depositor); assert.assert(ethBalanceInWei.gte(amountInWei), ZeroExError.INSUFFICIENT_ETH_BALANCE_FOR_DEPOSIT); const wethContract = await this._getEtherTokenContractAsync(); diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index 0a310aeee..630f0bef3 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -38,11 +38,10 @@ export class Web3Wrapper { const balanceWei = this.web3.toWei(ethAmount, 'ether'); return balanceWei; } - public async getBalanceInEthAsync(owner: string): Promise { - const balanceInWei = await promisify(this.web3.eth.getBalance)(owner); - let balanceEth = this.web3.fromWei(balanceInWei, 'ether'); - balanceEth = new BigNumber(balanceEth); - return balanceEth; + public async getBalanceInWeiAsync(owner: string): Promise { + let balanceInWei = await promisify(this.web3.eth.getBalance)(owner); + balanceInWei = new BigNumber(balanceInWei); + return balanceInWei; } public async doesContractExistAtAddressAsync(address: string): Promise { const code = await promisify(this.web3.eth.getCode)(address); -- cgit v1.2.3