Remove truffle from Exchange tests

This commit is contained in:
Leonid Logvinov
2018-01-19 14:54:44 +01:00
parent d0fbea76d8
commit f2b2b86786
3 changed files with 64 additions and 19 deletions

View File

@@ -1,5 +1,7 @@
import { ZeroEx } from '0x.js';
import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import ethUtil = require('ethereumjs-util');
import * as Web3 from 'web3';
@@ -21,13 +23,14 @@ const { Exchange, TokenTransferProxy, DummyToken, TokenRegistry, MaliciousToken
// 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('Exchange', (accounts: string[]) => {
const maker = accounts[0];
const tokenOwner = accounts[0];
const taker = accounts[1] || accounts[accounts.length - 1];
const feeRecipient = accounts[2] || accounts[accounts.length - 1];
describe('Exchange', () => {
const web3Wrapper = new Web3Wrapper(web3.currentProvider);
let maker: string;
let tokenOwner: string;
let taker: string;
let feeRecipient: string;
const INITIAL_BALANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
const INITIAL_ALLOWANCE = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
@@ -46,6 +49,11 @@ contract('Exchange', (accounts: string[]) => {
let zeroEx: ZeroEx;
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
maker = accounts[0];
tokenOwner = accounts[0];
taker = accounts[1] || accounts[accounts.length - 1];
feeRecipient = accounts[2] || accounts[accounts.length - 1];
[tokenRegistry, exchange] = await Promise.all([TokenRegistry.deployed(), Exchange.deployed()]);
exWrapper = new ExchangeWrapper(exchange);
zeroEx = new ZeroEx(web3.currentProvider, {
@@ -105,7 +113,12 @@ contract('Exchange', (accounts: string[]) => {
zrx.setBalance(taker, INITIAL_BALANCE, { from: tokenOwner }),
]);
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('internal functions', () => {
it('should include transferViaTokenTransferProxy', () => {
expect(exchange.transferViaTokenTransferProxy).to.be.undefined();

View File

@@ -1,9 +1,13 @@
import { ZeroEx } from '0x.js';
import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import ethUtil = require('ethereumjs-util');
import * as Web3 from 'web3';
import { Artifacts } from '../../util/artifacts';
import { constants } from '../../util/constants';
import { ExchangeWrapper } from '../../util/exchange_wrapper';
import { Order } from '../../util/order';
import { OrderFactory } from '../../util/order_factory';
@@ -13,16 +17,24 @@ chaiSetup.configure();
const expect = chai.expect;
const { Exchange, TokenRegistry } = new Artifacts(artifacts);
// 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('Exchange', (accounts: string[]) => {
const maker = accounts[0];
const feeRecipient = accounts[1] || accounts[accounts.length - 1];
describe('Exchange', () => {
const web3Wrapper = new Web3Wrapper(web3.currentProvider);
let maker: string;
let feeRecipient: string;
let order: Order;
let exchangeWrapper: ExchangeWrapper;
let orderFactory: OrderFactory;
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
maker = accounts[0];
feeRecipient = accounts[1] || accounts[accounts.length - 1];
const [tokenRegistry, exchange] = await Promise.all([TokenRegistry.deployed(), Exchange.deployed()]);
exchangeWrapper = new ExchangeWrapper(exchange);
const [repAddress, dgdAddress] = await Promise.all([
@@ -41,12 +53,15 @@ contract('Exchange', (accounts: string[]) => {
takerFee: ZeroEx.toBaseUnitAmount(new BigNumber(1), 18),
};
orderFactory = new OrderFactory(defaultOrderParams);
});
beforeEach(async () => {
order = await orderFactory.newSignedOrderAsync();
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('getOrderHash', () => {
it('should output the correct orderHash', async () => {
const orderHashHex = await exchangeWrapper.getOrderHashAsync(order);

View File

@@ -1,7 +1,10 @@
import { ZeroEx } from '0x.js';
import { BlockchainLifecycle } from '@0xproject/dev-utils';
import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import * as _ from 'lodash';
import * as Web3 from 'web3';
import { Artifacts } from '../../util/artifacts';
import { Balances } from '../../util/balances';
@@ -15,12 +18,17 @@ import { chaiSetup } from '../utils/chai_setup';
chaiSetup.configure();
const expect = chai.expect;
const { Exchange, TokenTransferProxy, DummyToken, TokenRegistry } = new Artifacts(artifacts);
// 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('Exchange', (accounts: string[]) => {
const maker = accounts[0];
const tokenOwner = accounts[0];
const taker = accounts[1] || accounts[accounts.length - 1];
const feeRecipient = accounts[2] || accounts[accounts.length - 1];
describe('Exchange', () => {
const web3Wrapper = new Web3Wrapper(web3.currentProvider);
let maker: string;
let tokenOwner: string;
let taker: string;
let feeRecipient: string;
const INIT_BAL = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
const INIT_ALLOW = ZeroEx.toBaseUnitAmount(new BigNumber(10000), 18);
@@ -38,6 +46,10 @@ contract('Exchange', (accounts: string[]) => {
let orderFactory: OrderFactory;
before(async () => {
const accounts = await web3Wrapper.getAvailableAddressesAsync();
tokenOwner = maker = accounts[0];
taker = accounts[1] || accounts[accounts.length - 1];
feeRecipient = accounts[2] || accounts[accounts.length - 1];
[tokenRegistry, exchange] = await Promise.all([TokenRegistry.deployed(), Exchange.deployed()]);
exWrapper = new ExchangeWrapper(exchange);
const [repAddress, dgdAddress, zrxAddress] = await Promise.all([
@@ -80,7 +92,12 @@ contract('Exchange', (accounts: string[]) => {
zrx.setBalance(taker, INIT_BAL, { from: tokenOwner }),
]);
});
beforeEach(async () => {
await blockchainLifecycle.startAsync();
});
afterEach(async () => {
await blockchainLifecycle.revertAsync();
});
describe('fillOrKillOrder', () => {
beforeEach(async () => {
balances = await dmyBalances.getAsync();