aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-03-12 10:33:24 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-03-12 10:37:30 +0800
commitd6c2e47bbd099f380c8fd4790d6d7be17d3532e5 (patch)
treed592edbd5a0319a4511923f57bc4e0e7f4502c28
parente2b2bf1e0ddad1b665c68f76b8088b517ed6c537 (diff)
downloaddexon-sol-tools-d6c2e47bbd099f380c8fd4790d6d7be17d3532e5.tar
dexon-sol-tools-d6c2e47bbd099f380c8fd4790d6d7be17d3532e5.tar.gz
dexon-sol-tools-d6c2e47bbd099f380c8fd4790d6d7be17d3532e5.tar.bz2
dexon-sol-tools-d6c2e47bbd099f380c8fd4790d6d7be17d3532e5.tar.lz
dexon-sol-tools-d6c2e47bbd099f380c8fd4790d6d7be17d3532e5.tar.xz
dexon-sol-tools-d6c2e47bbd099f380c8fd4790d6d7be17d3532e5.tar.zst
dexon-sol-tools-d6c2e47bbd099f380c8fd4790d6d7be17d3532e5.zip
Make env variables parsing more strict and add docs
-rw-r--r--packages/dev-utils/README.md2
-rw-r--r--packages/dev-utils/src/web3_factory.ts11
2 files changed, 11 insertions, 2 deletions
diff --git a/packages/dev-utils/README.md b/packages/dev-utils/README.md
index 59db0abbe..0c4175e35 100644
--- a/packages/dev-utils/README.md
+++ b/packages/dev-utils/README.md
@@ -11,6 +11,8 @@ VERBOSE_GANACHE: boolean. Enables verbose Ganache logging. Every request/respons
SOLIDITY_COVERAGE: boolean. If set - adds coverage subprovider which intercepts all calls/transactions and can be later used to compute code coverage.
```
+Boolean env variables should be either `true` or `false`. Defaults to `false` if not set.
+
## Install
```bash
diff --git a/packages/dev-utils/src/web3_factory.ts b/packages/dev-utils/src/web3_factory.ts
index 1bbdad81e..3e4b39686 100644
--- a/packages/dev-utils/src/web3_factory.ts
+++ b/packages/dev-utils/src/web3_factory.ts
@@ -13,6 +13,7 @@ import * as process from 'process';
import { constants } from './constants';
import { coverage } from './coverage';
+import { env } from './env';
// HACK: web3 leaks XMLHttpRequest into the global scope and causes requests to hang
// because they are using the wrong XHR package.
@@ -26,6 +27,11 @@ export interface Web3Config {
shouldUseInProcessGanache?: boolean; // default: false
}
+enum EnvVars {
+ SolidityCoverage = 'SOLIDITY_COVERAGE',
+ VerboseGanache = 'VERBOSE_GANACHE',
+}
+
export const web3Factory = {
create(config: Web3Config = {}): Web3 {
const provider = this.getRpcProvider(config);
@@ -35,7 +41,8 @@ export const web3Factory = {
},
getRpcProvider(config: Web3Config = {}): Web3.Provider {
const provider = new ProviderEngine();
- if (process.env.SOLIDITY_COVERAGE) {
+ const isCoverageEnabled = env.parseBoolean(EnvVars.SolidityCoverage);
+ if (isCoverageEnabled) {
provider.addProvider(coverage.getCoverageSubproviderSingleton());
}
const hasAddresses = _.isUndefined(config.hasAddresses) || config.hasAddresses;
@@ -53,7 +60,7 @@ export const web3Factory = {
provider.addProvider(
new GanacheSubprovider({
logger,
- verbose: process.env.VERBOSE_GANACHE,
+ verbose: env.parseBoolean(EnvVars.SolidityCoverage),
port: 8545,
networkId: 50,
mnemonic: 'concert load couple harbor equip island argue ramp clarify fence smart topic',