From a2c495a9830170173e5024b2e8e44e99cc319d06 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Sun, 25 Jun 2017 14:48:48 -0700 Subject: Re-wrap BigNumber returned from web3 in `getBalanceInEthAsync` --- src/web3_wrapper.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/web3_wrapper.ts') diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index 6bdca499f..afecbec7f 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -36,7 +36,8 @@ export class Web3Wrapper { } public async getBalanceInEthAsync(owner: string): Promise { const balanceInWei = await promisify(this.web3.eth.getBalance)(owner); - const balanceEth = this.web3.fromWei(balanceInWei, 'ether'); + let balanceEth = this.web3.fromWei(balanceInWei, 'ether'); + balanceEth = new BigNumber(balanceEth); return balanceEth; } public async doesContractExistAtAddressAsync(address: string): Promise { -- cgit v1.2.3 From 60b3f3e6dd39afe12884a17f9d978dd604a138b5 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Sun, 25 Jun 2017 14:50:11 -0700 Subject: Implement EtherTokenWrapper and tests, with deposit and withdraw methods --- src/web3_wrapper.ts | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/web3_wrapper.ts') diff --git a/src/web3_wrapper.ts b/src/web3_wrapper.ts index afecbec7f..0a310aeee 100644 --- a/src/web3_wrapper.ts +++ b/src/web3_wrapper.ts @@ -34,6 +34,10 @@ export class Web3Wrapper { return undefined; } } + public toWei(ethAmount: BigNumber.BigNumber): BigNumber.BigNumber { + 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'); -- cgit v1.2.3 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/web3_wrapper.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/web3_wrapper.ts') 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