Use an enum for ProviderType in contracts/src/utils/web3_wrapper

This commit is contained in:
Alex Browne 2018-06-06 10:56:01 -07:00
parent 3baf14b793
commit 5d2f9d7a33
No known key found for this signature in database
GPG Key ID: 7974B08A447ABE31

View File

@ -5,7 +5,25 @@ import { Provider } from 'ethereum-types';
import { coverage } from './coverage'; import { coverage } from './coverage';
const testProvider = process.env.TEST_PROVIDER || 'ganache'; enum ProviderType {
Ganache = 'ganache',
Geth = 'geth',
}
let testProvider: ProviderType;
switch (process.env.TEST_PROVIDER) {
case undefined:
testProvider = ProviderType.Ganache;
break;
case 'ganache':
testProvider = ProviderType.Ganache;
break;
case 'geth':
testProvider = ProviderType.Geth;
break;
default:
throw new Error(`Unknown TEST_PROVIDER: ${process.env.TEST_PROVIDER}`);
}
const ganacheTxDefaults = { const ganacheTxDefaults = {
from: devConstants.TESTRPC_FIRST_ADDRESS, from: devConstants.TESTRPC_FIRST_ADDRESS,
@ -14,7 +32,7 @@ const ganacheTxDefaults = {
const gethTxDefaults = { const gethTxDefaults = {
from: devConstants.TESTRPC_FIRST_ADDRESS, from: devConstants.TESTRPC_FIRST_ADDRESS,
}; };
export const txDefaults = testProvider === 'ganache' ? ganacheTxDefaults : gethTxDefaults; export const txDefaults = testProvider === ProviderType.Ganache ? ganacheTxDefaults : gethTxDefaults;
const gethConfigs = { const gethConfigs = {
shouldUseInProcessGanache: false, shouldUseInProcessGanache: false,
@ -24,8 +42,7 @@ const gethConfigs = {
const ganacheConfigs = { const ganacheConfigs = {
shouldUseInProcessGanache: true, shouldUseInProcessGanache: true,
}; };
const providerConfigs = testProvider === ProviderType.Ganache ? ganacheConfigs : gethConfigs;
const providerConfigs = testProvider === 'ganache' ? ganacheConfigs : gethConfigs;
export const provider = web3Factory.getRpcProvider(providerConfigs); export const provider = web3Factory.getRpcProvider(providerConfigs);
const isCoverageEnabled = env.parseBoolean(EnvVars.SolidityCoverage); const isCoverageEnabled = env.parseBoolean(EnvVars.SolidityCoverage);