aboutsummaryrefslogtreecommitdiffstats
path: root/packages/contracts/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-06-12 01:54:59 +0800
committerFabio Berger <me@fabioberger.com>2018-06-12 01:54:59 +0800
commit60f5a52964d6965d35eb3c3cb15abc8471de6fd6 (patch)
tree3912c687aa7e3eb9891d1f4d5a46d516805a4503 /packages/contracts/src
parent89b7b56a2cb38d95f65067e5493e8135cb1e7e98 (diff)
parent7e5866ce3fffc67633d3ab84cc3d2a6abdd22ce5 (diff)
downloaddexon-0x-contracts-60f5a52964d6965d35eb3c3cb15abc8471de6fd6.tar.gz
dexon-0x-contracts-60f5a52964d6965d35eb3c3cb15abc8471de6fd6.tar.zst
dexon-0x-contracts-60f5a52964d6965d35eb3c3cb15abc8471de6fd6.zip
Merge branch 'v2-prototype' into fix/contract-wrappers/exchangeTransferSimulator
* v2-prototype: Fix a bug in SolCompilerArtifacts adapter config overriding Increase timeout for contract migrations Remove some copy-paste code Await transactions in migrations Fix typos Await transactions in migrations Await fake transactions Fix a typo Implement SolidityProfiler & adapt sol-cov to work with Geth # Conflicts: # packages/migrations/CHANGELOG.json
Diffstat (limited to 'packages/contracts/src')
-rw-r--r--packages/contracts/src/utils/coverage.ts3
-rw-r--r--packages/contracts/src/utils/profiler.ts27
-rw-r--r--packages/contracts/src/utils/web3_wrapper.ts22
3 files changed, 51 insertions, 1 deletions
diff --git a/packages/contracts/src/utils/coverage.ts b/packages/contracts/src/utils/coverage.ts
index 41c83f703..de29a3ecc 100644
--- a/packages/contracts/src/utils/coverage.ts
+++ b/packages/contracts/src/utils/coverage.ts
@@ -14,7 +14,8 @@ export const coverage = {
_getCoverageSubprovider(): CoverageSubprovider {
const defaultFromAddress = devConstants.TESTRPC_FIRST_ADDRESS;
const solCompilerArtifactAdapter = new SolCompilerArtifactAdapter();
- const subprovider = new CoverageSubprovider(solCompilerArtifactAdapter, defaultFromAddress);
+ const isVerbose = true;
+ const subprovider = new CoverageSubprovider(solCompilerArtifactAdapter, defaultFromAddress, isVerbose);
return subprovider;
},
};
diff --git a/packages/contracts/src/utils/profiler.ts b/packages/contracts/src/utils/profiler.ts
new file mode 100644
index 000000000..85ee24f22
--- /dev/null
+++ b/packages/contracts/src/utils/profiler.ts
@@ -0,0 +1,27 @@
+import { devConstants } from '@0xproject/dev-utils';
+import { ProfilerSubprovider, SolCompilerArtifactAdapter } from '@0xproject/sol-cov';
+import * as _ from 'lodash';
+
+let profilerSubprovider: ProfilerSubprovider;
+
+export const profiler = {
+ start(): void {
+ profiler.getProfilerSubproviderSingleton().start();
+ },
+ stop(): void {
+ profiler.getProfilerSubproviderSingleton().stop();
+ },
+ getProfilerSubproviderSingleton(): ProfilerSubprovider {
+ if (_.isUndefined(profilerSubprovider)) {
+ profilerSubprovider = profiler._getProfilerSubprovider();
+ }
+ return profilerSubprovider;
+ },
+ _getProfilerSubprovider(): ProfilerSubprovider {
+ const defaultFromAddress = devConstants.TESTRPC_FIRST_ADDRESS;
+ const solCompilerArtifactAdapter = new SolCompilerArtifactAdapter();
+ const isVerbose = true;
+ const subprovider = new ProfilerSubprovider(solCompilerArtifactAdapter, defaultFromAddress, isVerbose);
+ return subprovider;
+ },
+};
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);