aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-06-02 04:19:36 +0800
committerAlex Browne <stephenalexbrowne@gmail.com>2018-06-07 03:39:44 +0800
commit2004c0d7398a5e77d08e3b4d8030c0f22cb09cc8 (patch)
tree0d6bfd516496b55fbda9c11d97afaee069bcf436
parentcd7cb025adeac3c499cc548456e4a8d181ab76e6 (diff)
downloaddexon-sol-tools-2004c0d7398a5e77d08e3b4d8030c0f22cb09cc8.tar
dexon-sol-tools-2004c0d7398a5e77d08e3b4d8030c0f22cb09cc8.tar.gz
dexon-sol-tools-2004c0d7398a5e77d08e3b4d8030c0f22cb09cc8.tar.bz2
dexon-sol-tools-2004c0d7398a5e77d08e3b4d8030c0f22cb09cc8.tar.lz
dexon-sol-tools-2004c0d7398a5e77d08e3b4d8030c0f22cb09cc8.tar.xz
dexon-sol-tools-2004c0d7398a5e77d08e3b4d8030c0f22cb09cc8.tar.zst
dexon-sol-tools-2004c0d7398a5e77d08e3b4d8030c0f22cb09cc8.zip
Add ability to quickly switch between Geth and Ganache by changing a const
-rw-r--r--packages/contracts/src/utils/web3_wrapper.ts19
-rw-r--r--packages/dev-utils/src/web3_factory.ts8
2 files changed, 23 insertions, 4 deletions
diff --git a/packages/contracts/src/utils/web3_wrapper.ts b/packages/contracts/src/utils/web3_wrapper.ts
index a89d7e8d0..bd582e841 100644
--- a/packages/contracts/src/utils/web3_wrapper.ts
+++ b/packages/contracts/src/utils/web3_wrapper.ts
@@ -5,14 +5,27 @@ import { Provider } from 'ethereum-types';
import { coverage } from './coverage';
-export const txDefaults = {
+const useGeth = false;
+
+const ganacheTxDefaults = {
+ from: devConstants.TESTRPC_FIRST_ADDRESS,
+ gas: devConstants.GAS_LIMIT,
+};
+const gethTxDefaults = {
from: devConstants.TESTRPC_FIRST_ADDRESS,
- // gas: devConstants.GAS_LIMIT,
};
-const providerConfigs = {
+export const txDefaults = useGeth ? gethTxDefaults : ganacheTxDefaults;
+
+const gethConfigs = {
shouldUseInProcessGanache: false,
rpcUrl: 'http://localhost:8501',
+ shouldUseFakeGasEstimate: false,
+};
+const ganacheConfigs = {
+ shouldUseInProcessGanache: true,
};
+const providerConfigs = useGeth ? gethConfigs : ganacheConfigs;
+
export const provider = web3Factory.getRpcProvider(providerConfigs);
const isCoverageEnabled = env.parseBoolean(EnvVars.SolidityCoverage);
if (isCoverageEnabled) {
diff --git a/packages/dev-utils/src/web3_factory.ts b/packages/dev-utils/src/web3_factory.ts
index d8379825a..25201228d 100644
--- a/packages/dev-utils/src/web3_factory.ts
+++ b/packages/dev-utils/src/web3_factory.ts
@@ -19,16 +19,22 @@ export interface Web3Config {
hasAddresses?: boolean; // default: true
shouldUseInProcessGanache?: boolean; // default: false
rpcUrl?: string; // default: localhost:8545
+ shouldUseFakeGasEstimate?: boolean; // default: true
}
export const web3Factory = {
getRpcProvider(config: Web3Config = {}): ProviderEngine {
const provider = new ProviderEngine();
const hasAddresses = _.isUndefined(config.hasAddresses) || config.hasAddresses;
+ config.shouldUseFakeGasEstimate =
+ _.isUndefined(config.shouldUseFakeGasEstimate) || config.shouldUseFakeGasEstimate;
if (!hasAddresses) {
provider.addProvider(new EmptyWalletSubprovider());
}
- // provider.addProvider(new FakeGasEstimateSubprovider(constants.GAS_LIMIT));
+
+ if (config.shouldUseFakeGasEstimate) {
+ provider.addProvider(new FakeGasEstimateSubprovider(constants.GAS_LIMIT));
+ }
const logger = {
log: (arg: any) => {
fs.appendFileSync('ganache.log', `${arg}\n`);