diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-01-26 18:21:06 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-01-30 23:01:37 +0800 |
commit | 6f13d107c4ca90049249e44a90b45cac2b490762 (patch) | |
tree | 905b7b408ca8d9fcc794ff9cb78b229134bd4dae /packages | |
parent | e56b2ceebb5e18aff0daf8951f3bd854c84bc433 (diff) | |
download | dexon-0x-contracts-6f13d107c4ca90049249e44a90b45cac2b490762.tar dexon-0x-contracts-6f13d107c4ca90049249e44a90b45cac2b490762.tar.gz dexon-0x-contracts-6f13d107c4ca90049249e44a90b45cac2b490762.tar.bz2 dexon-0x-contracts-6f13d107c4ca90049249e44a90b45cac2b490762.tar.lz dexon-0x-contracts-6f13d107c4ca90049249e44a90b45cac2b490762.tar.xz dexon-0x-contracts-6f13d107c4ca90049249e44a90b45cac2b490762.tar.zst dexon-0x-contracts-6f13d107c4ca90049249e44a90b45cac2b490762.zip |
Remove promisified web3 functions from tests
Diffstat (limited to 'packages')
-rw-r--r-- | packages/contracts/test/ether_token.ts | 22 | ||||
-rw-r--r-- | packages/web3-wrapper/src/index.ts | 4 |
2 files changed, 12 insertions, 14 deletions
diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts index d4e478099..fd7321280 100644 --- a/packages/contracts/test/ether_token.ts +++ b/packages/contracts/test/ether_token.ts @@ -20,12 +20,6 @@ describe('EtherToken', () => { const gasPrice = ZeroEx.toBaseUnitAmount(new BigNumber(20), 9); let zeroEx: ZeroEx; let etherTokenAddress: string; - const sendTransactionAsync = promisify<string>(web3.eth.sendTransaction); - const getEthBalanceAsync = async (owner: string) => { - const balanceStr = await promisify<string>(web3.eth.getBalance)(owner); - const balance = new BigNumber(balanceStr); - return balance; - }; before(async () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); account = accounts[0]; @@ -45,7 +39,7 @@ describe('EtherToken', () => { }); describe('deposit', () => { it('should throw if caller attempts to deposit more Ether than caller balance', async () => { - const initEthBalance = await getEthBalanceAsync(account); + const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); const ethToDeposit = initEthBalance.plus(1); return expect(zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account)).to.be.rejectedWith( @@ -54,7 +48,7 @@ describe('EtherToken', () => { }); it('should convert deposited Ether to wrapped Ether tokens', async () => { - const initEthBalance = await getEthBalanceAsync(account); + const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); const ethToDeposit = new BigNumber(web3.toWei(1, 'ether')); @@ -63,7 +57,7 @@ describe('EtherToken', () => { const receipt = await zeroEx.awaitTransactionMinedAsync(txHash); const ethSpentOnGas = gasPrice.times(receipt.gasUsed); - const finalEthBalance = await getEthBalanceAsync(account); + const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas))); @@ -85,7 +79,7 @@ describe('EtherToken', () => { const ethToDeposit = new BigNumber(web3.toWei(1, 'ether')); await zeroEx.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account); const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); - const initEthBalance = await getEthBalanceAsync(account); + const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); const ethTokensToWithdraw = initEthTokenBalance; expect(ethTokensToWithdraw).to.not.be.bignumber.equal(0); const txHash = await zeroEx.etherToken.withdrawAsync(etherTokenAddress, ethTokensToWithdraw, account, { @@ -94,7 +88,7 @@ describe('EtherToken', () => { const receipt = await zeroEx.awaitTransactionMinedAsync(txHash); const ethSpentOnGas = gasPrice.times(receipt.gasUsed); - const finalEthBalance = await getEthBalanceAsync(account); + const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); expect(finalEthBalance).to.be.bignumber.equal( @@ -106,12 +100,12 @@ describe('EtherToken', () => { describe('fallback', () => { it('should convert sent ether to ether tokens', async () => { - const initEthBalance = await getEthBalanceAsync(account); + const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); const ethToDeposit = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18); - const txHash = await sendTransactionAsync({ + const txHash = await web3Wrapper.sendTransactionAsync({ from: account, to: etherTokenAddress, value: ethToDeposit, @@ -121,7 +115,7 @@ describe('EtherToken', () => { const receipt = await zeroEx.awaitTransactionMinedAsync(txHash); const ethSpentOnGas = gasPrice.times(receipt.gasUsed); - const finalEthBalance = await getEthBalanceAsync(account); + const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas))); diff --git a/packages/web3-wrapper/src/index.ts b/packages/web3-wrapper/src/index.ts index c4826f2be..a2878fc2a 100644 --- a/packages/web3-wrapper/src/index.ts +++ b/packages/web3-wrapper/src/index.ts @@ -134,6 +134,10 @@ export class Web3Wrapper { const gas = await promisify<number>(this._web3.eth.estimateGas)({ data }); return gas; } + public async sendTransactionAsync(txData: Web3.TxData): Promise<string> { + const txHash = await promisify<string>(this._web3.eth.sendTransaction)(txData); + return txHash; + } private async _sendRawPayloadAsync<A>(payload: Web3.JSONRPCRequestPayload): Promise<A> { const sendAsync = this._web3.currentProvider.sendAsync.bind(this._web3.currentProvider); const response = await promisify<Web3.JSONRPCResponsePayload>(sendAsync)(payload); |