aboutsummaryrefslogtreecommitdiffstats
path: root/test/utils/web3_factory.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-05-29 15:09:54 +0800
committerFabio Berger <me@fabioberger.com>2017-05-29 15:09:54 +0800
commit62cc3b919c73b7726793808e3b9631dba41cef28 (patch)
tree22c5f1728c56b09fa0e15e5e645c1f891224a6ee /test/utils/web3_factory.ts
parent281b9eaa5d207d32ae38fbab25cbca83fe81efa1 (diff)
parentb897bdab79fe566ffc8c19c6ec9f1bb7260fa95e (diff)
downloaddexon-sol-tools-62cc3b919c73b7726793808e3b9631dba41cef28.tar
dexon-sol-tools-62cc3b919c73b7726793808e3b9631dba41cef28.tar.gz
dexon-sol-tools-62cc3b919c73b7726793808e3b9631dba41cef28.tar.bz2
dexon-sol-tools-62cc3b919c73b7726793808e3b9631dba41cef28.tar.lz
dexon-sol-tools-62cc3b919c73b7726793808e3b9631dba41cef28.tar.xz
dexon-sol-tools-62cc3b919c73b7726793808e3b9631dba41cef28.tar.zst
dexon-sol-tools-62cc3b919c73b7726793808e3b9631dba41cef28.zip
Merge branch 'master' of github.com:0xProject/0x.js
# Conflicts: # src/ts/0x.js.ts # src/ts/utils/utils.ts
Diffstat (limited to 'test/utils/web3_factory.ts')
-rw-r--r--test/utils/web3_factory.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/test/utils/web3_factory.ts b/test/utils/web3_factory.ts
new file mode 100644
index 000000000..493fbc2df
--- /dev/null
+++ b/test/utils/web3_factory.ts
@@ -0,0 +1,23 @@
+// 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';
+
+export const web3Factory = {
+ create(): Web3 {
+ const provider = new ProviderEngine();
+ const rpcUrl = `http://${constants.RPC_HOST}:${constants.RPC_PORT}`;
+ provider.addProvider(new RpcSubprovider({
+ rpcUrl,
+ }));
+ provider.start();
+ const web3 = new Web3();
+ web3.setProvider(provider);
+ return web3;
+ },
+};