Add ability to quickly switch between Geth and Ganache by changing a const
This commit is contained in:
parent
cd7cb025ad
commit
2004c0d739
@ -5,14 +5,27 @@ import { Provider } from 'ethereum-types';
|
|||||||
|
|
||||||
import { coverage } from './coverage';
|
import { coverage } from './coverage';
|
||||||
|
|
||||||
export const txDefaults = {
|
const useGeth = false;
|
||||||
|
|
||||||
|
const ganacheTxDefaults = {
|
||||||
from: devConstants.TESTRPC_FIRST_ADDRESS,
|
from: devConstants.TESTRPC_FIRST_ADDRESS,
|
||||||
// gas: devConstants.GAS_LIMIT,
|
gas: devConstants.GAS_LIMIT,
|
||||||
};
|
};
|
||||||
const providerConfigs = {
|
const gethTxDefaults = {
|
||||||
|
from: devConstants.TESTRPC_FIRST_ADDRESS,
|
||||||
|
};
|
||||||
|
export const txDefaults = useGeth ? gethTxDefaults : ganacheTxDefaults;
|
||||||
|
|
||||||
|
const gethConfigs = {
|
||||||
shouldUseInProcessGanache: false,
|
shouldUseInProcessGanache: false,
|
||||||
rpcUrl: 'http://localhost:8501',
|
rpcUrl: 'http://localhost:8501',
|
||||||
|
shouldUseFakeGasEstimate: false,
|
||||||
};
|
};
|
||||||
|
const ganacheConfigs = {
|
||||||
|
shouldUseInProcessGanache: true,
|
||||||
|
};
|
||||||
|
const providerConfigs = useGeth ? gethConfigs : ganacheConfigs;
|
||||||
|
|
||||||
export const provider = web3Factory.getRpcProvider(providerConfigs);
|
export const provider = web3Factory.getRpcProvider(providerConfigs);
|
||||||
const isCoverageEnabled = env.parseBoolean(EnvVars.SolidityCoverage);
|
const isCoverageEnabled = env.parseBoolean(EnvVars.SolidityCoverage);
|
||||||
if (isCoverageEnabled) {
|
if (isCoverageEnabled) {
|
||||||
|
@ -19,16 +19,22 @@ export interface Web3Config {
|
|||||||
hasAddresses?: boolean; // default: true
|
hasAddresses?: boolean; // default: true
|
||||||
shouldUseInProcessGanache?: boolean; // default: false
|
shouldUseInProcessGanache?: boolean; // default: false
|
||||||
rpcUrl?: string; // default: localhost:8545
|
rpcUrl?: string; // default: localhost:8545
|
||||||
|
shouldUseFakeGasEstimate?: boolean; // default: true
|
||||||
}
|
}
|
||||||
|
|
||||||
export const web3Factory = {
|
export const web3Factory = {
|
||||||
getRpcProvider(config: Web3Config = {}): ProviderEngine {
|
getRpcProvider(config: Web3Config = {}): ProviderEngine {
|
||||||
const provider = new ProviderEngine();
|
const provider = new ProviderEngine();
|
||||||
const hasAddresses = _.isUndefined(config.hasAddresses) || config.hasAddresses;
|
const hasAddresses = _.isUndefined(config.hasAddresses) || config.hasAddresses;
|
||||||
|
config.shouldUseFakeGasEstimate =
|
||||||
|
_.isUndefined(config.shouldUseFakeGasEstimate) || config.shouldUseFakeGasEstimate;
|
||||||
if (!hasAddresses) {
|
if (!hasAddresses) {
|
||||||
provider.addProvider(new EmptyWalletSubprovider());
|
provider.addProvider(new EmptyWalletSubprovider());
|
||||||
}
|
}
|
||||||
// provider.addProvider(new FakeGasEstimateSubprovider(constants.GAS_LIMIT));
|
|
||||||
|
if (config.shouldUseFakeGasEstimate) {
|
||||||
|
provider.addProvider(new FakeGasEstimateSubprovider(constants.GAS_LIMIT));
|
||||||
|
}
|
||||||
const logger = {
|
const logger = {
|
||||||
log: (arg: any) => {
|
log: (arg: any) => {
|
||||||
fs.appendFileSync('ganache.log', `${arg}\n`);
|
fs.appendFileSync('ganache.log', `${arg}\n`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user