diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-06-09 02:18:32 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-06-09 05:56:45 +0800 |
commit | 760bab8f866ec3d5fc7627ce9bbf5c2eaaef1f36 (patch) | |
tree | 05911f7eaa9cd8a48448b371f46186d2ffc5541e /packages/contracts/src/utils/web3_wrapper.ts | |
parent | 817c332d11835f02726f0609374d1c25c9ab39b5 (diff) | |
download | dexon-0x-contracts-760bab8f866ec3d5fc7627ce9bbf5c2eaaef1f36.tar dexon-0x-contracts-760bab8f866ec3d5fc7627ce9bbf5c2eaaef1f36.tar.gz dexon-0x-contracts-760bab8f866ec3d5fc7627ce9bbf5c2eaaef1f36.tar.bz2 dexon-0x-contracts-760bab8f866ec3d5fc7627ce9bbf5c2eaaef1f36.tar.lz dexon-0x-contracts-760bab8f866ec3d5fc7627ce9bbf5c2eaaef1f36.tar.xz dexon-0x-contracts-760bab8f866ec3d5fc7627ce9bbf5c2eaaef1f36.tar.zst dexon-0x-contracts-760bab8f866ec3d5fc7627ce9bbf5c2eaaef1f36.zip |
Implement SolidityProfiler & adapt sol-cov to work with Geth
Diffstat (limited to 'packages/contracts/src/utils/web3_wrapper.ts')
-rw-r--r-- | packages/contracts/src/utils/web3_wrapper.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/packages/contracts/src/utils/web3_wrapper.ts b/packages/contracts/src/utils/web3_wrapper.ts index df9bf88c8..c475d96a9 100644 --- a/packages/contracts/src/utils/web3_wrapper.ts +++ b/packages/contracts/src/utils/web3_wrapper.ts @@ -1,8 +1,10 @@ import { devConstants, env, EnvVars, web3Factory } from '@0xproject/dev-utils'; import { prependSubprovider } from '@0xproject/subproviders'; +import { logUtils } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { coverage } from './coverage'; +import { profiler } from './profiler'; enum ProviderType { Ganache = 'ganache', @@ -45,9 +47,29 @@ const providerConfigs = testProvider === ProviderType.Ganache ? ganacheConfigs : export const provider = web3Factory.getRpcProvider(providerConfigs); const isCoverageEnabled = env.parseBoolean(EnvVars.SolidityCoverage); +const isProfilerEnabled = env.parseBoolean(EnvVars.SolidityProfiler); +if (isCoverageEnabled && isProfilerEnabled) { + throw new Error( + `Unfortunately for now you can't enable both coverage and profiler at the same time. They both use coverage.json file and there is no way to configure that.`, + ); +} if (isCoverageEnabled) { const coverageSubprovider = coverage.getCoverageSubproviderSingleton(); prependSubprovider(provider, coverageSubprovider); } +if (isProfilerEnabled) { + if (testProvider === ProviderType.Ganache) { + logUtils.warn( + "Gas costs in Ganache traces are incorrect and we don't recommend using it for profiling. Please switch to Geth", + ); + process.exit(1); + } + const profilerSubprovider = profiler.getProfilerSubproviderSingleton(); + logUtils.log( + "By default profilerSubprovider is stopped so that you don't get noise from setup code. Don't forget to start it before the code you want to profile and stop it afterwards", + ); + profilerSubprovider.stop(); + prependSubprovider(provider, profilerSubprovider); +} export const web3Wrapper = new Web3Wrapper(provider); |