diff options
author | Fabio Berger <me@fabioberger.com> | 2017-11-13 11:17:18 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-11-13 11:17:18 +0800 |
commit | c4ee2d73865a1444c079b9e2836b7630a0adf03e (patch) | |
tree | b9c7794e7022fb189675d914f5fe58dcabd67dec /packages/0x.js/test/utils/web3_factory.ts | |
parent | a74ec0effa818a86233fe64cb0dad2c61bbb4bb6 (diff) | |
download | dexon-0x-contracts-c4ee2d73865a1444c079b9e2836b7630a0adf03e.tar dexon-0x-contracts-c4ee2d73865a1444c079b9e2836b7630a0adf03e.tar.gz dexon-0x-contracts-c4ee2d73865a1444c079b9e2836b7630a0adf03e.tar.bz2 dexon-0x-contracts-c4ee2d73865a1444c079b9e2836b7630a0adf03e.tar.lz dexon-0x-contracts-c4ee2d73865a1444c079b9e2836b7630a0adf03e.tar.xz dexon-0x-contracts-c4ee2d73865a1444c079b9e2836b7630a0adf03e.tar.zst dexon-0x-contracts-c4ee2d73865a1444c079b9e2836b7630a0adf03e.zip |
Switch over to Lerna + Yarn Workspaces setup for a mono-repo approach
Diffstat (limited to 'packages/0x.js/test/utils/web3_factory.ts')
-rw-r--r-- | packages/0x.js/test/utils/web3_factory.ts | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/packages/0x.js/test/utils/web3_factory.ts b/packages/0x.js/test/utils/web3_factory.ts new file mode 100644 index 000000000..b20070c74 --- /dev/null +++ b/packages/0x.js/test/utils/web3_factory.ts @@ -0,0 +1,31 @@ +// HACK: web3 injects XMLHttpRequest into the global scope and ProviderEngine checks XMLHttpRequest +// to know whether it is running in a browser or node environment. We need it to be undefined since +// we are not running in a browser env. +// Filed issue: https://github.com/ethereum/web3.js/issues/844 +(global as any).XMLHttpRequest = undefined; +import ProviderEngine = require('web3-provider-engine'); +import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); +import * as Web3 from 'web3'; +import {constants} from './constants'; +import {EmptyWalletSubProvider} from '../../src/subproviders/empty_wallet_subprovider'; + +export const web3Factory = { + create(hasAddresses: boolean = true): Web3 { + const provider = this.getRpcProvider(hasAddresses); + const web3 = new Web3(); + web3.setProvider(provider); + return web3; + }, + getRpcProvider(hasAddresses: boolean = true): Web3.Provider { + const provider = new ProviderEngine(); + const rpcUrl = `http://${constants.RPC_HOST}:${constants.RPC_PORT}`; + if (!hasAddresses) { + provider.addProvider(new EmptyWalletSubProvider()); + } + provider.addProvider(new RpcSubprovider({ + rpcUrl, + })); + provider.start(); + return provider; + }, +}; |