aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-01-19 20:56:36 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-01-30 23:01:36 +0800
commit091ba473ff83ebd3239273b8e40671b9ccab5f47 (patch)
treeb4629fd2ddc664934a7fe8f9772fb0ae8a823499
parentfca051c5656c29164d9ef05fe5124b98972b79cc (diff)
downloaddexon-sol-tools-091ba473ff83ebd3239273b8e40671b9ccab5f47.tar
dexon-sol-tools-091ba473ff83ebd3239273b8e40671b9ccab5f47.tar.gz
dexon-sol-tools-091ba473ff83ebd3239273b8e40671b9ccab5f47.tar.bz2
dexon-sol-tools-091ba473ff83ebd3239273b8e40671b9ccab5f47.tar.lz
dexon-sol-tools-091ba473ff83ebd3239273b8e40671b9ccab5f47.tar.xz
dexon-sol-tools-091ba473ff83ebd3239273b8e40671b9ccab5f47.tar.zst
dexon-sol-tools-091ba473ff83ebd3239273b8e40671b9ccab5f47.zip
Remove truffle from Ether Token tests
-rw-r--r--packages/contracts/test/ether_token.ts36
1 files 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<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 () => {
+ accounts = await web3Wrapper.getAvailableAddressesAsync();
+ account = accounts[0];
etherTokenAddress = EtherToken.address;
zeroEx = new ZeroEx(web3.currentProvider, {
gasPrice,
networkId: constants.TESTRPC_NETWORK_ID,
});
});
-
- 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;
- };
-
+ 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;