From 091ba473ff83ebd3239273b8e40671b9ccab5f47 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 19 Jan 2018 13:56:36 +0100 Subject: Remove truffle from Ether Token tests --- packages/contracts/test/ether_token.ts | 36 ++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/contracts/test/ether_token.ts b/packages/contracts/test/ether_token.ts index cce11812b..a5a97a60a 100644 --- a/packages/contracts/test/ether_token.ts +++ b/packages/contracts/test/ether_token.ts @@ -1,7 +1,9 @@ import { ZeroEx, ZeroExError } from '0x.js'; +import { BlockchainLifecycle } from '@0xproject/dev-utils'; import { BigNumber, promisify } from '@0xproject/utils'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as chai from 'chai'; -import Web3 = require('web3'); +import * as Web3 from 'web3'; import { Artifacts } from '../util/artifacts'; import { constants } from '../util/constants'; @@ -16,28 +18,36 @@ const expect = chai.expect; // In order to benefit from type-safety, we re-assign the global web3 instance injected by Truffle // with type `any` to a variable of type `Web3`. const web3: Web3 = (global as any).web3; +const blockchainLifecycle = new BlockchainLifecycle(constants.RPC_URL); -contract('EtherToken', (accounts: string[]) => { - const account = accounts[0]; +describe.only('EtherToken', () => { + const web3Wrapper = new Web3Wrapper(web3.currentProvider); + let accounts: string[]; + let account: string; const gasPrice = ZeroEx.toBaseUnitAmount(new BigNumber(20), 9); let zeroEx: ZeroEx; let etherTokenAddress: string; - + 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; + }; before(async () => { + accounts = await web3Wrapper.getAvailableAddressesAsync(); + account = accounts[0]; etherTokenAddress = EtherToken.address; zeroEx = new ZeroEx(web3.currentProvider, { gasPrice, networkId: constants.TESTRPC_NETWORK_ID, }); }); - - 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; - }; - + beforeEach(async () => { + await blockchainLifecycle.startAsync(); + }); + afterEach(async () => { + await blockchainLifecycle.revertAsync(); + }); describe('deposit', () => { it('should throw if caller attempts to deposit more Ether than caller balance', async () => { const initEthBalance = await getEthBalanceAsync(account); @@ -77,6 +87,8 @@ contract('EtherToken', (accounts: string[]) => { }); it('should convert ether tokens to ether with sufficient balance', async () => { + 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 ethTokensToWithdraw = initEthTokenBalance; -- cgit v1.2.3