diff options
author | Amir Bandeali <abandeali1@gmail.com> | 2017-11-30 14:26:51 +0800 |
---|---|---|
committer | Amir Bandeali <abandeali1@gmail.com> | 2017-11-30 23:10:18 +0800 |
commit | e85a69655c29a04b7f1a3506c5ecb55433425f7f (patch) | |
tree | d085c0f6fd46980c85f92f60adf95a6b8f272c49 /packages/contracts/test/ts/ether_token.ts | |
parent | 4b3e0383235ca4ca0127f24c2e05543bb45a56bb (diff) | |
download | dexon-0x-contracts-e85a69655c29a04b7f1a3506c5ecb55433425f7f.tar dexon-0x-contracts-e85a69655c29a04b7f1a3506c5ecb55433425f7f.tar.gz dexon-0x-contracts-e85a69655c29a04b7f1a3506c5ecb55433425f7f.tar.bz2 dexon-0x-contracts-e85a69655c29a04b7f1a3506c5ecb55433425f7f.tar.lz dexon-0x-contracts-e85a69655c29a04b7f1a3506c5ecb55433425f7f.tar.xz dexon-0x-contracts-e85a69655c29a04b7f1a3506c5ecb55433425f7f.tar.zst dexon-0x-contracts-e85a69655c29a04b7f1a3506c5ecb55433425f7f.zip |
Fix indentations
Diffstat (limited to 'packages/contracts/test/ts/ether_token.ts')
-rw-r--r-- | packages/contracts/test/ts/ether_token.ts | 157 |
1 files changed, 79 insertions, 78 deletions
diff --git a/packages/contracts/test/ts/ether_token.ts b/packages/contracts/test/ts/ether_token.ts index 7e98e9bef..857371578 100644 --- a/packages/contracts/test/ts/ether_token.ts +++ b/packages/contracts/test/ts/ether_token.ts @@ -18,100 +18,101 @@ const expect = chai.expect; const web3: Web3 = (global as any).web3; contract('EtherToken', (accounts: string[]) => { - const account = accounts[0]; - const gasPrice = ZeroEx.toBaseUnitAmount(new BigNumber(20), 9); - let zeroEx: ZeroEx; - let etherTokenAddress: string; - before(async () => { - etherTokenAddress = EtherToken.address; - zeroEx = new ZeroEx(web3.currentProvider, { - gasPrice, - etherTokenContractAddress: etherTokenAddress, - }); - }); - - const sendTransactionAsync = promisify(web3.eth.sendTransaction); - const getEthBalanceAsync = async (owner: string) => { - const balanceStr = await promisify(web3.eth.getBalance)(owner); - const balance = new BigNumber(balanceStr); - return balance; - }; - - describe('deposit', () => { - it('should throw if caller attempts to deposit more Ether than caller balance', async () => { - const initEthBalance = await getEthBalanceAsync(account); - const ethToDeposit = initEthBalance.plus(1); - - return expect(zeroEx.etherToken.depositAsync(ethToDeposit, account)) - .to.be.rejectedWith(ZeroExError.InsufficientEthBalanceForDeposit); + const account = accounts[0]; + const gasPrice = ZeroEx.toBaseUnitAmount(new BigNumber(20), 9); + let zeroEx: ZeroEx; + let etherTokenAddress: string; + before(async () => { + etherTokenAddress = EtherToken.address; + zeroEx = new ZeroEx(web3.currentProvider, { + gasPrice, + etherTokenContractAddress: etherTokenAddress, + }); }); - it('should convert deposited Ether to wrapped Ether tokens', async () => { - const initEthBalance = await getEthBalanceAsync(account); - const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); + const sendTransactionAsync = promisify(web3.eth.sendTransaction); + const getEthBalanceAsync = async (owner: string) => { + const balanceStr = await promisify(web3.eth.getBalance)(owner); + const balance = new BigNumber(balanceStr); + return balance; + }; - const ethToDeposit = new BigNumber(web3.toWei(1, 'ether')); + describe('deposit', () => { + it('should throw if caller attempts to deposit more Ether than caller balance', async () => { + const initEthBalance = await getEthBalanceAsync(account); + const ethToDeposit = initEthBalance.plus(1); - const txHash = await zeroEx.etherToken.depositAsync(ethToDeposit, account); - const receipt = await zeroEx.awaitTransactionMinedAsync(txHash); + return expect(zeroEx.etherToken.depositAsync(ethToDeposit, account)) + .to.be.rejectedWith(ZeroExError.InsufficientEthBalanceForDeposit); + }); - const ethSpentOnGas = gasPrice.times(receipt.gasUsed); - const finalEthBalance = await getEthBalanceAsync(account); - const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); + it('should convert deposited Ether to wrapped Ether tokens', async () => { + const initEthBalance = await getEthBalanceAsync(account); + const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); - expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas))); - expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit)); - }); - }); + const ethToDeposit = new BigNumber(web3.toWei(1, 'ether')); - describe('withdraw', () => { - it('should throw if caller attempts to withdraw greater than caller balance', async () => { - const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); - const ethTokensToWithdraw = initEthTokenBalance.plus(1); + const txHash = await zeroEx.etherToken.depositAsync(ethToDeposit, account); + const receipt = await zeroEx.awaitTransactionMinedAsync(txHash); - return expect(zeroEx.etherToken.withdrawAsync(ethTokensToWithdraw, account)) - .to.be.rejectedWith(ZeroExError.InsufficientWEthBalanceForWithdrawal); - }); + const ethSpentOnGas = gasPrice.times(receipt.gasUsed); + const finalEthBalance = await getEthBalanceAsync(account); + const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); - it('should convert ether tokens to ether with sufficient balance', async () => { - const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); - const initEthBalance = await getEthBalanceAsync(account); - const ethTokensToWithdraw = initEthTokenBalance; - expect(ethTokensToWithdraw).to.not.be.bignumber.equal(0); - const txHash = await zeroEx.etherToken.withdrawAsync(ethTokensToWithdraw, account); - const receipt = await zeroEx.awaitTransactionMinedAsync(txHash); - - const ethSpentOnGas = gasPrice.times(receipt.gasUsed); - const finalEthBalance = await getEthBalanceAsync(account); - const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); + expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas))); + expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit)); + }); + }); - expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.plus(ethTokensToWithdraw.minus(ethSpentOnGas))); - expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.minus(ethTokensToWithdraw)); + describe('withdraw', () => { + it('should throw if caller attempts to withdraw greater than caller balance', async () => { + const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); + const ethTokensToWithdraw = initEthTokenBalance.plus(1); + + return expect(zeroEx.etherToken.withdrawAsync(ethTokensToWithdraw, account)) + .to.be.rejectedWith(ZeroExError.InsufficientWEthBalanceForWithdrawal); + }); + + it('should convert ether tokens to ether with sufficient balance', async () => { + const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); + const initEthBalance = await getEthBalanceAsync(account); + const ethTokensToWithdraw = initEthTokenBalance; + expect(ethTokensToWithdraw).to.not.be.bignumber.equal(0); + const txHash = await zeroEx.etherToken.withdrawAsync(ethTokensToWithdraw, account); + const receipt = await zeroEx.awaitTransactionMinedAsync(txHash); + + const ethSpentOnGas = gasPrice.times(receipt.gasUsed); + const finalEthBalance = await getEthBalanceAsync(account); + const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); + + expect(finalEthBalance).to.be.bignumber + .equal(initEthBalance.plus(ethTokensToWithdraw.minus(ethSpentOnGas))); + expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.minus(ethTokensToWithdraw)); + }); }); - }); - describe('fallback', () => { - it('should convert sent ether to ether tokens', async () => { - const initEthBalance = await getEthBalanceAsync(account); - const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); + describe('fallback', () => { + it('should convert sent ether to ether tokens', async () => { + const initEthBalance = await getEthBalanceAsync(account); + const initEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); - const ethToDeposit = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18); + const ethToDeposit = ZeroEx.toBaseUnitAmount(new BigNumber(1), 18); - const txHash = await sendTransactionAsync({ - from: account, - to: etherTokenAddress, - value: ethToDeposit, - gasPrice, - }); + const txHash = await sendTransactionAsync({ + from: account, + to: etherTokenAddress, + value: ethToDeposit, + gasPrice, + }); - const receipt = await zeroEx.awaitTransactionMinedAsync(txHash); + const receipt = await zeroEx.awaitTransactionMinedAsync(txHash); - const ethSpentOnGas = gasPrice.times(receipt.gasUsed); - const finalEthBalance = await getEthBalanceAsync(account); - const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); + const ethSpentOnGas = gasPrice.times(receipt.gasUsed); + const finalEthBalance = await getEthBalanceAsync(account); + const finalEthTokenBalance = await zeroEx.token.getBalanceAsync(etherTokenAddress, account); - expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas))); - expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit)); + expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas))); + expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit)); + }); }); - }); }); |