aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/test
diff options
context:
space:
mode:
Diffstat (limited to 'packages/0x.js/test')
-rw-r--r--packages/0x.js/test/0x.js_test.ts30
-rw-r--r--packages/0x.js/test/artifacts_test.ts8
-rw-r--r--packages/0x.js/test/assert_test.ts4
-rw-r--r--packages/0x.js/test/ether_token_wrapper_test.ts10
-rw-r--r--packages/0x.js/test/event_watcher_test.ts6
-rw-r--r--packages/0x.js/test/exchange_transfer_simulator_test.ts4
-rw-r--r--packages/0x.js/test/exchange_wrapper_test.ts8
-rw-r--r--packages/0x.js/test/expiration_watcher_test.ts5
-rw-r--r--packages/0x.js/test/order_state_watcher_test.ts5
-rw-r--r--packages/0x.js/test/order_validation_test.ts5
-rw-r--r--packages/0x.js/test/subscription_test.ts5
-rw-r--r--packages/0x.js/test/token_registry_wrapper_test.ts4
-rw-r--r--packages/0x.js/test/token_transfer_proxy_wrapper_test.ts5
-rw-r--r--packages/0x.js/test/token_wrapper_test.ts43
-rw-r--r--packages/0x.js/test/utils/deployer.ts18
-rw-r--r--packages/0x.js/test/utils/web3_wrapper.ts12
16 files changed, 103 insertions, 69 deletions
diff --git a/packages/0x.js/test/0x.js_test.ts b/packages/0x.js/test/0x.js_test.ts
index 70e85aa52..de5a6be58 100644
--- a/packages/0x.js/test/0x.js_test.ts
+++ b/packages/0x.js/test/0x.js_test.ts
@@ -1,16 +1,23 @@
+import { Deployer } from '@0xproject/deployer';
import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
+// HACK: This dependency is optional since it is only available when run from within
+// the monorepo. tslint doesn't handle optional dependencies
+// tslint:disable-next-line:no-implicit-dependencies
+import { runMigrationsAsync } from '@0xproject/migrations';
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import * as _ from 'lodash';
import 'mocha';
+import * as path from 'path';
import * as Sinon from 'sinon';
import { ApprovalContractEventArgs, LogWithDecodedArgs, Order, TokenEvents, ZeroEx } from '../src';
import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants';
+import { deployer } from './utils/deployer';
import { TokenUtils } from './utils/token_utils';
-import { web3, web3Wrapper } from './utils/web3_wrapper';
+import { provider, web3Wrapper } from './utils/web3_wrapper';
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
chaiSetup.configure();
@@ -19,10 +26,14 @@ const expect = chai.expect;
const SHOULD_ADD_PERSONAL_MESSAGE_PREFIX = false;
describe('ZeroEx library', () => {
- const config = {
- networkId: constants.TESTRPC_NETWORK_ID,
- };
- const zeroEx = new ZeroEx(web3.currentProvider, config);
+ let zeroEx: ZeroEx;
+ before(async () => {
+ await runMigrationsAsync(deployer);
+ const config = {
+ networkId: constants.TESTRPC_NETWORK_ID,
+ };
+ zeroEx = new ZeroEx(provider, config);
+ });
describe('#setProvider', () => {
it('overrides provider in nested web3s and invalidates contractInstances', async () => {
// Instantiate the contract instances with the current provider
@@ -31,10 +42,9 @@ describe('ZeroEx library', () => {
expect((zeroEx.exchange as any)._exchangeContractIfExists).to.not.be.undefined();
expect((zeroEx.tokenRegistry as any)._tokenRegistryContractIfExists).to.not.be.undefined();
- const newProvider = web3Factory.getRpcProvider();
// Add property to newProvider so that we can differentiate it from old provider
- (newProvider as any).zeroExTestId = 1;
- zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID);
+ (provider as any).zeroExTestId = 1;
+ zeroEx.setProvider(provider, constants.TESTRPC_NETWORK_ID);
// Check that contractInstances with old provider are removed after provider update
expect((zeroEx.exchange as any)._exchangeContractIfExists).to.be.undefined();
@@ -278,7 +288,7 @@ describe('ZeroEx library', () => {
exchangeContractAddress: ZeroEx.NULL_ADDRESS,
networkId: constants.TESTRPC_NETWORK_ID,
};
- const zeroExWithWrongExchangeAddress = new ZeroEx(web3.currentProvider, zeroExConfig);
+ const zeroExWithWrongExchangeAddress = new ZeroEx(provider, zeroExConfig);
expect(zeroExWithWrongExchangeAddress.exchange.getContractAddress()).to.be.equal(ZeroEx.NULL_ADDRESS);
});
it('allows to specify token registry token contract address', async () => {
@@ -286,7 +296,7 @@ describe('ZeroEx library', () => {
tokenRegistryContractAddress: ZeroEx.NULL_ADDRESS,
networkId: constants.TESTRPC_NETWORK_ID,
};
- const zeroExWithWrongTokenRegistryAddress = new ZeroEx(web3.currentProvider, zeroExConfig);
+ const zeroExWithWrongTokenRegistryAddress = new ZeroEx(provider, zeroExConfig);
expect(zeroExWithWrongTokenRegistryAddress.tokenRegistry.getContractAddress()).to.be.equal(
ZeroEx.NULL_ADDRESS,
);
diff --git a/packages/0x.js/test/artifacts_test.ts b/packages/0x.js/test/artifacts_test.ts
index e8ab9aa97..17f068a2e 100644
--- a/packages/0x.js/test/artifacts_test.ts
+++ b/packages/0x.js/test/artifacts_test.ts
@@ -17,11 +17,11 @@ describe('Artifacts', () => {
const packageJSONContent = fs.readFileSync('package.json', 'utf-8');
const packageJSON = JSON.parse(packageJSONContent);
const mnemonic = packageJSON.config.mnemonic;
- const web3Provider = new HDWalletProvider(mnemonic, kovanRpcUrl);
+ const provider = new HDWalletProvider(mnemonic, kovanRpcUrl);
const config = {
networkId: constants.KOVAN_NETWORK_ID,
};
- const zeroEx = new ZeroEx(web3Provider, config);
+ const zeroEx = new ZeroEx(provider, config);
it('token registry contract is deployed', async () => {
await (zeroEx.tokenRegistry as any)._getTokenRegistryContractAsync();
}).timeout(TIMEOUT);
@@ -37,11 +37,11 @@ describe('Artifacts', () => {
const packageJSONContent = fs.readFileSync('package.json', 'utf-8');
const packageJSON = JSON.parse(packageJSONContent);
const mnemonic = packageJSON.config.mnemonic;
- const web3Provider = new HDWalletProvider(mnemonic, ropstenRpcUrl);
+ const provider = new HDWalletProvider(mnemonic, ropstenRpcUrl);
const config = {
networkId: constants.ROPSTEN_NETWORK_ID,
};
- const zeroEx = new ZeroEx(web3Provider, config);
+ const zeroEx = new ZeroEx(provider, config);
it('token registry contract is deployed', async () => {
await (zeroEx.tokenRegistry as any)._getTokenRegistryContractAsync();
}).timeout(TIMEOUT);
diff --git a/packages/0x.js/test/assert_test.ts b/packages/0x.js/test/assert_test.ts
index c4451742f..b08f3e23b 100644
--- a/packages/0x.js/test/assert_test.ts
+++ b/packages/0x.js/test/assert_test.ts
@@ -6,15 +6,15 @@ import { ZeroEx } from '../src';
import { assert } from '../src/utils/assert';
import { constants } from './utils/constants';
+import { provider } from './utils/web3_wrapper';
const expect = chai.expect;
describe('Assertion library', () => {
- const web3 = web3Factory.create();
const config = {
networkId: constants.TESTRPC_NETWORK_ID,
};
- const zeroEx = new ZeroEx(web3.currentProvider, config);
+ const zeroEx = new ZeroEx(provider, config);
describe('#isSenderAddressHexAsync', () => {
it('throws when address is invalid', async () => {
const address = '0xdeadbeef';
diff --git a/packages/0x.js/test/ether_token_wrapper_test.ts b/packages/0x.js/test/ether_token_wrapper_test.ts
index 644101dc7..99c42fe0b 100644
--- a/packages/0x.js/test/ether_token_wrapper_test.ts
+++ b/packages/0x.js/test/ether_token_wrapper_test.ts
@@ -3,7 +3,6 @@ import { BigNumber } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import 'mocha';
-import * as Web3 from 'web3';
import {
ApprovalContractEventArgs,
@@ -24,7 +23,7 @@ import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants';
import { reportNodeCallbackErrors } from './utils/report_callback_errors';
import { TokenUtils } from './utils/token_utils';
-import { web3, web3Wrapper } from './utils/web3_wrapper';
+import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
@@ -55,7 +54,7 @@ describe('EtherTokenWrapper', () => {
const depositAmount = new BigNumber(42);
const withdrawalAmount = new BigNumber(42);
before(async () => {
- zeroEx = new ZeroEx(web3.currentProvider, zeroExConfig);
+ zeroEx = new ZeroEx(provider, zeroExConfig);
tokens = await zeroEx.tokenRegistry.getTokensAsync();
userAddresses = await zeroEx.getAvailableAddressesAsync();
addressWithETH = userAddresses[0];
@@ -79,7 +78,7 @@ describe('EtherTokenWrapper', () => {
const UNKNOWN_NETWORK_NETWORK_ID = 10;
expect(
() =>
- new ZeroEx(web3.currentProvider, {
+ new ZeroEx(provider, {
networkId: UNKNOWN_NETWORK_NETWORK_ID,
} as any),
).to.throw();
@@ -261,8 +260,7 @@ describe('EtherTokenWrapper', () => {
callbackNeverToBeCalled,
);
const callbackToBeCalled = reportNodeCallbackErrors(done)();
- const newProvider = web3Factory.getRpcProvider();
- zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID);
+ zeroEx.setProvider(provider, constants.TESTRPC_NETWORK_ID);
await zeroEx.etherToken.depositAsync(etherTokenAddress, transferAmount, addressWithETH);
zeroEx.etherToken.subscribe(
etherTokenAddress,
diff --git a/packages/0x.js/test/event_watcher_test.ts b/packages/0x.js/test/event_watcher_test.ts
index 2fa6c0580..40ffcc2f6 100644
--- a/packages/0x.js/test/event_watcher_test.ts
+++ b/packages/0x.js/test/event_watcher_test.ts
@@ -5,7 +5,6 @@ import * as chai from 'chai';
import * as _ from 'lodash';
import 'mocha';
import * as Sinon from 'sinon';
-import * as Web3 from 'web3';
import { LogEvent } from '../src';
import { EventWatcher } from '../src/order_watcher/event_watcher';
@@ -13,12 +12,12 @@ import { DoneCallback } from '../src/types';
import { chaiSetup } from './utils/chai_setup';
import { reportNodeCallbackErrors } from './utils/report_callback_errors';
+import { provider } from './utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
describe('EventWatcher', () => {
- let web3: Web3;
let stubs: Sinon.SinonStub[] = [];
let eventWatcher: EventWatcher;
let web3Wrapper: Web3Wrapper;
@@ -53,9 +52,8 @@ describe('EventWatcher', () => {
transactionIndex: 0,
};
before(async () => {
- web3 = web3Factory.create();
const pollingIntervalMs = 10;
- web3Wrapper = new Web3Wrapper(web3.currentProvider);
+ web3Wrapper = new Web3Wrapper(provider);
eventWatcher = new EventWatcher(web3Wrapper, pollingIntervalMs);
});
afterEach(() => {
diff --git a/packages/0x.js/test/exchange_transfer_simulator_test.ts b/packages/0x.js/test/exchange_transfer_simulator_test.ts
index 4447a61cb..cb976a0ae 100644
--- a/packages/0x.js/test/exchange_transfer_simulator_test.ts
+++ b/packages/0x.js/test/exchange_transfer_simulator_test.ts
@@ -9,7 +9,7 @@ import { ExchangeTransferSimulator } from '../src/utils/exchange_transfer_simula
import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants';
-import { web3, web3Wrapper } from './utils/web3_wrapper';
+import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
@@ -19,7 +19,7 @@ describe('ExchangeTransferSimulator', () => {
const config = {
networkId: constants.TESTRPC_NETWORK_ID,
};
- const zeroEx = new ZeroEx(web3.currentProvider, config);
+ const zeroEx = new ZeroEx(provider, config);
const transferAmount = new BigNumber(5);
let userAddresses: string[];
let tokens: Token[];
diff --git a/packages/0x.js/test/exchange_wrapper_test.ts b/packages/0x.js/test/exchange_wrapper_test.ts
index cfc390bae..cd74af5a1 100644
--- a/packages/0x.js/test/exchange_wrapper_test.ts
+++ b/packages/0x.js/test/exchange_wrapper_test.ts
@@ -4,7 +4,6 @@ import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import * as _ from 'lodash';
import 'mocha';
-import * as Web3 from 'web3';
import {
BlockRange,
@@ -26,7 +25,7 @@ import { constants } from './utils/constants';
import { FillScenarios } from './utils/fill_scenarios';
import { reportNodeCallbackErrors } from './utils/report_callback_errors';
import { TokenUtils } from './utils/token_utils';
-import { web3, web3Wrapper } from './utils/web3_wrapper';
+import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
@@ -46,7 +45,7 @@ describe('ExchangeWrapper', () => {
networkId: constants.TESTRPC_NETWORK_ID,
};
before(async () => {
- zeroEx = new ZeroEx(web3.currentProvider, config);
+ zeroEx = new ZeroEx(provider, config);
exchangeContractAddress = zeroEx.exchange.getContractAddress();
userAddresses = await zeroEx.getAvailableAddressesAsync();
tokens = await zeroEx.tokenRegistry.getTokensAsync();
@@ -977,8 +976,7 @@ describe('ExchangeWrapper', () => {
);
zeroEx.exchange.subscribe(ExchangeEvents.LogFill, indexFilterValues, callbackNeverToBeCalled);
- const newProvider = web3Factory.getRpcProvider();
- zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID);
+ zeroEx.setProvider(provider, constants.TESTRPC_NETWORK_ID);
const callback = reportNodeCallbackErrors(done)(
(logEvent: DecodedLogEvent<LogFillContractEventArgs>) => {
diff --git a/packages/0x.js/test/expiration_watcher_test.ts b/packages/0x.js/test/expiration_watcher_test.ts
index ed7a6e5e3..29b111fa3 100644
--- a/packages/0x.js/test/expiration_watcher_test.ts
+++ b/packages/0x.js/test/expiration_watcher_test.ts
@@ -4,7 +4,6 @@ import * as chai from 'chai';
import * as _ from 'lodash';
import 'mocha';
import * as Sinon from 'sinon';
-import * as Web3 from 'web3';
import { ZeroEx } from '../src/0x';
import { ExpirationWatcher } from '../src/order_watcher/expiration_watcher';
@@ -16,7 +15,7 @@ import { constants } from './utils/constants';
import { FillScenarios } from './utils/fill_scenarios';
import { reportNoErrorCallbackErrors } from './utils/report_callback_errors';
import { TokenUtils } from './utils/token_utils';
-import { web3, web3Wrapper } from './utils/web3_wrapper';
+import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
@@ -44,7 +43,7 @@ describe('ExpirationWatcher', () => {
const config = {
networkId: constants.TESTRPC_NETWORK_ID,
};
- zeroEx = new ZeroEx(web3.currentProvider, config);
+ zeroEx = new ZeroEx(provider, config);
exchangeContractAddress = zeroEx.exchange.getContractAddress();
userAddresses = await zeroEx.getAvailableAddressesAsync();
tokens = await zeroEx.tokenRegistry.getTokensAsync();
diff --git a/packages/0x.js/test/order_state_watcher_test.ts b/packages/0x.js/test/order_state_watcher_test.ts
index 4210e013f..45a292c8b 100644
--- a/packages/0x.js/test/order_state_watcher_test.ts
+++ b/packages/0x.js/test/order_state_watcher_test.ts
@@ -3,7 +3,6 @@ import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import * as _ from 'lodash';
import 'mocha';
-import * as Web3 from 'web3';
import {
ExchangeContractErrs,
@@ -23,7 +22,7 @@ import { constants } from './utils/constants';
import { FillScenarios } from './utils/fill_scenarios';
import { reportNodeCallbackErrors } from './utils/report_callback_errors';
import { TokenUtils } from './utils/token_utils';
-import { web3, web3Wrapper } from './utils/web3_wrapper';
+import { provider, web3Wrapper } from './utils/web3_wrapper';
const TIMEOUT_MS = 150;
@@ -51,7 +50,7 @@ describe('OrderStateWatcher', () => {
const decimals = constants.ZRX_DECIMALS;
const fillableAmount = ZeroEx.toBaseUnitAmount(new BigNumber(5), decimals);
before(async () => {
- zeroEx = new ZeroEx(web3.currentProvider, config);
+ zeroEx = new ZeroEx(provider, config);
orderStateWatcher = zeroEx.createOrderStateWatcher();
exchangeContractAddress = zeroEx.exchange.getContractAddress();
userAddresses = await zeroEx.getAvailableAddressesAsync();
diff --git a/packages/0x.js/test/order_validation_test.ts b/packages/0x.js/test/order_validation_test.ts
index 5472ca8f6..c894774b8 100644
--- a/packages/0x.js/test/order_validation_test.ts
+++ b/packages/0x.js/test/order_validation_test.ts
@@ -3,7 +3,6 @@ import { BlockParamLiteral } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import * as Sinon from 'sinon';
-import * as Web3 from 'web3';
import { ExchangeContractErrs, SignedOrder, Token, ZeroEx, ZeroExError } from '../src';
import { TradeSide, TransferType } from '../src/types';
@@ -14,7 +13,7 @@ import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants';
import { FillScenarios } from './utils/fill_scenarios';
import { TokenUtils } from './utils/token_utils';
-import { web3, web3Wrapper } from './utils/web3_wrapper';
+import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
@@ -40,7 +39,7 @@ describe('OrderValidation', () => {
networkId: constants.TESTRPC_NETWORK_ID,
};
before(async () => {
- zeroEx = new ZeroEx(web3.currentProvider, config);
+ zeroEx = new ZeroEx(provider, config);
exchangeContractAddress = zeroEx.exchange.getContractAddress();
userAddresses = await zeroEx.getAvailableAddressesAsync();
[coinbase, makerAddress, takerAddress, feeRecipient] = userAddresses;
diff --git a/packages/0x.js/test/subscription_test.ts b/packages/0x.js/test/subscription_test.ts
index 9b4751287..ed4f838c0 100644
--- a/packages/0x.js/test/subscription_test.ts
+++ b/packages/0x.js/test/subscription_test.ts
@@ -3,7 +3,6 @@ import { BigNumber } from '@0xproject/utils';
import * as _ from 'lodash';
import 'mocha';
import * as Sinon from 'sinon';
-import * as Web3 from 'web3';
import { ApprovalContractEventArgs, DecodedLogEvent, Token, TokenEvents, ZeroEx } from '../src';
import { DoneCallback } from '../src/types';
@@ -11,7 +10,7 @@ import { DoneCallback } from '../src/types';
import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants';
import { assertNodeCallbackError } from './utils/report_callback_errors';
-import { web3, web3Wrapper } from './utils/web3_wrapper';
+import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure();
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
@@ -26,7 +25,7 @@ describe('SubscriptionTest', () => {
networkId: constants.TESTRPC_NETWORK_ID,
};
before(async () => {
- zeroEx = new ZeroEx(web3.currentProvider, config);
+ zeroEx = new ZeroEx(provider, config);
userAddresses = await zeroEx.getAvailableAddressesAsync();
tokens = await zeroEx.tokenRegistry.getTokensAsync();
coinbase = userAddresses[0];
diff --git a/packages/0x.js/test/token_registry_wrapper_test.ts b/packages/0x.js/test/token_registry_wrapper_test.ts
index 3b7ce46fb..19caa2ed4 100644
--- a/packages/0x.js/test/token_registry_wrapper_test.ts
+++ b/packages/0x.js/test/token_registry_wrapper_test.ts
@@ -8,7 +8,7 @@ import { Token, ZeroEx } from '../src';
import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants';
-import { web3, web3Wrapper } from './utils/web3_wrapper';
+import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
@@ -31,7 +31,7 @@ describe('TokenRegistryWrapper', () => {
networkId: constants.TESTRPC_NETWORK_ID,
};
before(async () => {
- zeroEx = new ZeroEx(web3.currentProvider, config);
+ zeroEx = new ZeroEx(provider, config);
tokens = await zeroEx.tokenRegistry.getTokensAsync();
_.map(tokens, token => {
tokenAddressBySymbol[token.symbol] = token.address;
diff --git a/packages/0x.js/test/token_transfer_proxy_wrapper_test.ts b/packages/0x.js/test/token_transfer_proxy_wrapper_test.ts
index fb003634a..9415d7c08 100644
--- a/packages/0x.js/test/token_transfer_proxy_wrapper_test.ts
+++ b/packages/0x.js/test/token_transfer_proxy_wrapper_test.ts
@@ -1,14 +1,13 @@
-import { web3Factory } from '@0xproject/dev-utils';
import * as chai from 'chai';
import { ZeroEx } from '../src';
import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants';
+import { provider } from './utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
-const web3 = web3Factory.create();
describe('TokenTransferProxyWrapper', () => {
let zeroEx: ZeroEx;
@@ -16,7 +15,7 @@ describe('TokenTransferProxyWrapper', () => {
networkId: constants.TESTRPC_NETWORK_ID,
};
before(async () => {
- zeroEx = new ZeroEx(web3.currentProvider, config);
+ zeroEx = new ZeroEx(provider, config);
});
describe('#isAuthorizedAsync', () => {
it('should return false if the address is not authorized', async () => {
diff --git a/packages/0x.js/test/token_wrapper_test.ts b/packages/0x.js/test/token_wrapper_test.ts
index 0c6335d5e..04fd943aa 100644
--- a/packages/0x.js/test/token_wrapper_test.ts
+++ b/packages/0x.js/test/token_wrapper_test.ts
@@ -1,9 +1,10 @@
-import { BlockchainLifecycle, devConstants, web3Factory } from '@0xproject/dev-utils';
+import { BlockchainLifecycle, devConstants } from '@0xproject/dev-utils';
+import { EmptyWalletSubprovider } from '@0xproject/subproviders';
+import { Provider } from '@0xproject/types';
import { BigNumber } from '@0xproject/utils';
-import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as chai from 'chai';
import 'mocha';
-import * as Web3 from 'web3';
+import Web3ProviderEngine = require('web3-provider-engine');
import {
ApprovalContractEventArgs,
@@ -22,7 +23,7 @@ import { chaiSetup } from './utils/chai_setup';
import { constants } from './utils/constants';
import { reportNodeCallbackErrors } from './utils/report_callback_errors';
import { TokenUtils } from './utils/token_utils';
-import { web3, web3Wrapper } from './utils/web3_wrapper';
+import { provider, web3Wrapper } from './utils/web3_wrapper';
chaiSetup.configure();
const expect = chai.expect;
@@ -39,7 +40,7 @@ describe('TokenWrapper', () => {
networkId: constants.TESTRPC_NETWORK_ID,
};
before(async () => {
- zeroEx = new ZeroEx(web3.currentProvider, config);
+ zeroEx = new ZeroEx(provider, config);
userAddresses = await zeroEx.getAvailableAddressesAsync();
tokens = await zeroEx.tokenRegistry.getTokensAsync();
tokenUtils = new TokenUtils(tokens);
@@ -164,7 +165,7 @@ describe('TokenWrapper', () => {
});
});
describe('#getBalanceAsync', () => {
- describe('With web3 provider with accounts', () => {
+ describe('With provider with accounts', () => {
it('should return the balance for an existing ERC20 token', async () => {
const token = tokens[0];
const ownerAddress = coinbase;
@@ -187,14 +188,14 @@ describe('TokenWrapper', () => {
return expect(balance).to.be.bignumber.equal(expectedBalance);
});
});
- describe('With web3 provider without accounts', () => {
+ describe('With provider without accounts', () => {
let zeroExWithoutAccounts: ZeroEx;
before(async () => {
const hasAddresses = false;
- const web3WithoutAccounts = web3Factory.create({ hasAddresses });
- zeroExWithoutAccounts = new ZeroEx(web3WithoutAccounts.currentProvider, config);
+ const emptyWalletProvider = addEmptyWalletSubprovider(provider);
+ zeroExWithoutAccounts = new ZeroEx(emptyWalletProvider, config);
});
- it('should return balance even when called with Web3 provider instance without addresses', async () => {
+ it('should return balance even when called with provider instance without addresses', async () => {
const token = tokens[0];
const ownerAddress = coinbase;
const balance = await zeroExWithoutAccounts.token.getBalanceAsync(token.address, ownerAddress);
@@ -277,7 +278,7 @@ describe('TokenWrapper', () => {
});
});
describe('#getAllowanceAsync', () => {
- describe('With web3 provider with accounts', () => {
+ describe('With provider with accounts', () => {
it('should get the proxy allowance', async () => {
const token = tokens[0];
const ownerAddress = coinbase;
@@ -299,12 +300,12 @@ describe('TokenWrapper', () => {
return expect(allowance).to.be.bignumber.equal(expectedAllowance);
});
});
- describe('With web3 provider without accounts', () => {
+ describe('With provider without accounts', () => {
let zeroExWithoutAccounts: ZeroEx;
before(async () => {
const hasAddresses = false;
- const web3WithoutAccounts = web3Factory.create({ hasAddresses });
- zeroExWithoutAccounts = new ZeroEx(web3WithoutAccounts.currentProvider, config);
+ const emptyWalletProvider = addEmptyWalletSubprovider(provider);
+ zeroExWithoutAccounts = new ZeroEx(emptyWalletProvider, config);
});
it('should get the proxy allowance', async () => {
const token = tokens[0];
@@ -424,8 +425,7 @@ describe('TokenWrapper', () => {
);
zeroEx.token.subscribe(tokenAddress, TokenEvents.Transfer, indexFilterValues, callbackNeverToBeCalled);
const callbackToBeCalled = reportNodeCallbackErrors(done)();
- const newProvider = web3Factory.getRpcProvider();
- zeroEx.setProvider(newProvider, constants.TESTRPC_NETWORK_ID);
+ zeroEx.setProvider(provider, constants.TESTRPC_NETWORK_ID);
zeroEx.token.subscribe(tokenAddress, TokenEvents.Transfer, indexFilterValues, callbackToBeCalled);
await zeroEx.token.transferAsync(tokenAddress, coinbase, addressWithoutFunds, transferAmount);
})().catch(done);
@@ -515,3 +515,14 @@ describe('TokenWrapper', () => {
});
});
// tslint:disable:max-file-line-count
+
+function addEmptyWalletSubprovider(p: Provider): Provider {
+ const providerEngine = new Web3ProviderEngine();
+ providerEngine.addProvider(new EmptyWalletSubprovider());
+ const currentSubproviders = (p as any)._providers;
+ for (const subprovider of currentSubproviders) {
+ providerEngine.addProvider(subprovider);
+ }
+ providerEngine.start();
+ return providerEngine;
+}
diff --git a/packages/0x.js/test/utils/deployer.ts b/packages/0x.js/test/utils/deployer.ts
new file mode 100644
index 000000000..b092322e2
--- /dev/null
+++ b/packages/0x.js/test/utils/deployer.ts
@@ -0,0 +1,18 @@
+import { Deployer } from '@0xproject/deployer';
+import { devConstants } from '@0xproject/dev-utils';
+import * as path from 'path';
+
+import { constants } from './constants';
+
+import { provider } from './web3_wrapper';
+
+const artifactsDir = path.resolve('test', 'artifacts');
+const deployerOpts = {
+ artifactsDir,
+ provider,
+ networkId: constants.TESTRPC_NETWORK_ID,
+ defaults: {
+ gas: devConstants.GAS_ESTIMATE,
+ },
+};
+export const deployer = new Deployer(deployerOpts);
diff --git a/packages/0x.js/test/utils/web3_wrapper.ts b/packages/0x.js/test/utils/web3_wrapper.ts
index 4b374fc7e..b7b3f0b7f 100644
--- a/packages/0x.js/test/utils/web3_wrapper.ts
+++ b/packages/0x.js/test/utils/web3_wrapper.ts
@@ -1,6 +1,12 @@
-import { web3Factory } from '@0xproject/dev-utils';
+import { devConstants, web3Factory } from '@0xproject/dev-utils';
+import { Provider } from '@0xproject/types';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as Web3 from 'web3';
-export const web3 = web3Factory.create();
-export const web3Wrapper = new Web3Wrapper(web3.currentProvider);
+import { constants } from './constants';
+
+const web3 = web3Factory.create({ shouldUseInProcessGanache: true });
+const provider: Provider = web3.currentProvider;
+const web3Wrapper = new Web3Wrapper(web3.currentProvider);
+
+export { provider, web3Wrapper };