From 1d68692bb6ae6be25b989cca8e5d3040bd6d1502 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 25 May 2018 15:51:43 -0700 Subject: Remove contracts -> @0xproject/order-utils dependency --- packages/contracts/test/ether_token.ts | 53 ++++++++++++++-------------------- 1 file changed, 22 insertions(+), 31 deletions(-) (limited to 'packages/contracts/test/ether_token.ts') diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts index 5c8a5e199..10dd635fe 100644 --- a/packages/contracts/test/ether_token.ts +++ b/packages/contracts/test/ether_token.ts @@ -1,4 +1,3 @@ -import { ContractWrappers, ContractWrappersError } from '@0xproject/contract-wrappers'; import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils'; import { BigNumber, promisify } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; @@ -18,8 +17,7 @@ const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); describe('EtherToken', () => { let account: string; const gasPrice = Web3Wrapper.toBaseUnitAmount(new BigNumber(20), 9); - let contractWrappers: ContractWrappers; - let etherTokenAddress: string; + let etherToken: WETH9Contract; before(async () => { await blockchainLifecycle.startAsync(); @@ -31,11 +29,9 @@ describe('EtherToken', () => { const accounts = await web3Wrapper.getAvailableAddressesAsync(); account = accounts[0]; - const etherToken = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.EtherToken, provider, txDefaults); - etherTokenAddress = etherToken.address; - contractWrappers = new ContractWrappers(provider, { + etherToken = await WETH9Contract.deployFrom0xArtifactAsync(artifacts.EtherToken, provider, { gasPrice, - networkId: constants.TESTRPC_NETWORK_ID, + ...txDefaults, }); }); beforeEach(async () => { @@ -49,18 +45,18 @@ describe('EtherToken', () => { const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); const ethToDeposit = initEthBalance.plus(1); - return expect( - contractWrappers.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account), - ).to.be.rejectedWith(ContractWrappersError.InsufficientEthBalanceForDeposit); + return expect(etherToken.deposit.sendTransactionAsync({ value: ethToDeposit })).to.be.rejectedWith( + "ender doesn't have enough funds to send tx.", + ); }); it('should convert deposited Ether to wrapped Ether tokens', async () => { const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); - const initEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account); + const initEthTokenBalance = await etherToken.balanceOf.callAsync(account); const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1))); - const txHash = await contractWrappers.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account); + const txHash = await etherToken.deposit.sendTransactionAsync({ value: ethToDeposit }); const receipt = await web3Wrapper.awaitTransactionSuccessAsync( txHash, constants.AWAIT_TRANSACTION_MINED_MS, @@ -68,7 +64,7 @@ describe('EtherToken', () => { const ethSpentOnGas = gasPrice.times(receipt.gasUsed); const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); - const finalEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account); + const finalEthTokenBalance = await etherToken.balanceOf.callAsync(account); expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas))); expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit)); @@ -77,29 +73,24 @@ describe('EtherToken', () => { describe('withdraw', () => { it('should throw if caller attempts to withdraw greater than caller balance', async () => { - const initEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account); + const initEthTokenBalance = await etherToken.balanceOf.callAsync(account); const ethTokensToWithdraw = initEthTokenBalance.plus(1); - return expect( - contractWrappers.etherToken.withdrawAsync(etherTokenAddress, ethTokensToWithdraw, account), - ).to.be.rejectedWith(ContractWrappersError.InsufficientWEthBalanceForWithdrawal); + return expect(etherToken.withdraw.sendTransactionAsync(ethTokensToWithdraw)).to.be.rejectedWith( + constants.REVERT, + ); }); it('should convert ether tokens to ether with sufficient balance', async () => { const ethToDeposit = new BigNumber(Web3Wrapper.toWei(new BigNumber(1))); - await contractWrappers.etherToken.depositAsync(etherTokenAddress, ethToDeposit, account); - const initEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account); + await etherToken.deposit.sendTransactionAsync({ value: ethToDeposit }); + const initEthTokenBalance = await etherToken.balanceOf.callAsync(account); const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); const ethTokensToWithdraw = initEthTokenBalance; expect(ethTokensToWithdraw).to.not.be.bignumber.equal(0); - const txHash = await contractWrappers.etherToken.withdrawAsync( - etherTokenAddress, - ethTokensToWithdraw, - account, - { - gasLimit: constants.MAX_ETHERTOKEN_WITHDRAW_GAS, - }, - ); + const txHash = await etherToken.withdraw.sendTransactionAsync(ethTokensToWithdraw, { + gas: constants.MAX_ETHERTOKEN_WITHDRAW_GAS, + }); const receipt = await web3Wrapper.awaitTransactionSuccessAsync( txHash, constants.AWAIT_TRANSACTION_MINED_MS, @@ -107,7 +98,7 @@ describe('EtherToken', () => { const ethSpentOnGas = gasPrice.times(receipt.gasUsed); const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); - const finalEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account); + const finalEthTokenBalance = await etherToken.balanceOf.callAsync(account); expect(finalEthBalance).to.be.bignumber.equal( initEthBalance.plus(ethTokensToWithdraw.minus(ethSpentOnGas)), @@ -119,13 +110,13 @@ describe('EtherToken', () => { describe('fallback', () => { it('should convert sent ether to ether tokens', async () => { const initEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); - const initEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account); + const initEthTokenBalance = await etherToken.balanceOf.callAsync(account); const ethToDeposit = Web3Wrapper.toBaseUnitAmount(new BigNumber(1), 18); const txHash = await web3Wrapper.sendTransactionAsync({ from: account, - to: etherTokenAddress, + to: etherToken.address, value: ethToDeposit, gasPrice, }); @@ -137,7 +128,7 @@ describe('EtherToken', () => { const ethSpentOnGas = gasPrice.times(receipt.gasUsed); const finalEthBalance = await web3Wrapper.getBalanceInWeiAsync(account); - const finalEthTokenBalance = await contractWrappers.token.getBalanceAsync(etherTokenAddress, account); + const finalEthTokenBalance = await etherToken.balanceOf.callAsync(account); expect(finalEthBalance).to.be.bignumber.equal(initEthBalance.minus(ethToDeposit.plus(ethSpentOnGas))); expect(finalEthTokenBalance).to.be.bignumber.equal(initEthTokenBalance.plus(ethToDeposit)); -- cgit v1.2.3