aboutsummaryrefslogtreecommitdiffstats
path: root/packages/metacoin/test/utils
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-06-13 22:10:05 +0800
committerFabio Berger <me@fabioberger.com>2018-06-13 22:10:05 +0800
commitb4fead9606ecc9655b2038fcef1c75217752f67d (patch)
treeb363eee11085850328837004b41ff23c5d31efb6 /packages/metacoin/test/utils
parent61243b418e4d962cd8d8a1d7a49f04510b3c1c7f (diff)
parent4efd28c092e74b438d0397069c0c55cc90c537f2 (diff)
downloaddexon-0x-contracts-b4fead9606ecc9655b2038fcef1c75217752f67d.tar.gz
dexon-0x-contracts-b4fead9606ecc9655b2038fcef1c75217752f67d.tar.zst
dexon-0x-contracts-b4fead9606ecc9655b2038fcef1c75217752f67d.zip
Merge branch 'v2-prototype' into feature/combinatorial-testing
* v2-prototype: (26 commits) Rename _coverageCollector -> _profilerCollector in TraceCollectionSubprovider Refactor sol-cov to de-duplicate code for coverage and profiling Rename popByte and popAddress Hard code test addresses/bytes32 instead of generating pseudorandom ones Update artifacts Rename computeCoverageAsync -> computeSingleTraceCoverageAsync Fix linter errors Refactor sol-cov to avoid keeping traceInfo in memory Unpop byte rather than making deep copy Pass gas in to marketBuyOrdersNoThrow Looks up the memory location of makerAssetData/takerAssetData Make ZRX_PROXY_ID constant rather than popping it from ZRX_ASSET_DATA Add tests for deepCopyBytes and missing write methods from LibBytes Pop id from assetData before dispatching to AssetProxies Upgrade solidity-parser-entlr 0.2.11 => 0.2.12 Fix import order Fix typos Add CHANGELOGs Speed-up sol-cov Increase delay when sending transactions during devnet startup ...
Diffstat (limited to 'packages/metacoin/test/utils')
-rw-r--r--packages/metacoin/test/utils/profiler.ts27
-rw-r--r--packages/metacoin/test/utils/web3_wrapper.ts69
2 files changed, 85 insertions, 11 deletions
diff --git a/packages/metacoin/test/utils/profiler.ts b/packages/metacoin/test/utils/profiler.ts
new file mode 100644
index 000000000..701337451
--- /dev/null
+++ b/packages/metacoin/test/utils/profiler.ts
@@ -0,0 +1,27 @@
+import { devConstants } from '@0xproject/dev-utils';
+import { ProfilerSubprovider, SolCompilerArtifactAdapter } from '@0xproject/sol-cov';
+import * as _ from 'lodash';
+
+import { config } from './config';
+
+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 zeroExArtifactsAdapter = new SolCompilerArtifactAdapter(config.artifactsDir, config.contractsDir);
+ return new ProfilerSubprovider(zeroExArtifactsAdapter, defaultFromAddress);
+ },
+};
diff --git a/packages/metacoin/test/utils/web3_wrapper.ts b/packages/metacoin/test/utils/web3_wrapper.ts
index 273cdf961..d3655cb6a 100644
--- a/packages/metacoin/test/utils/web3_wrapper.ts
+++ b/packages/metacoin/test/utils/web3_wrapper.ts
@@ -1,31 +1,78 @@
import { env, EnvVars } from '@0xproject/dev-utils';
import { GanacheSubprovider, prependSubprovider } from '@0xproject/subproviders';
+import { errorUtils, logUtils } from '@0xproject/utils';
import { Web3Wrapper } from '@0xproject/web3-wrapper';
import * as fs from 'fs';
import ProviderEngine = require('web3-provider-engine');
+import RpcSubprovider = require('web3-provider-engine/subproviders/rpc');
import { config } from './config';
import { coverage } from './coverage';
+import { profiler } from './profiler';
+
+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 errorUtils.spawnSwitchErr('TEST_PROVIDER', process.env.TEST_PROVIDER);
+}
export const provider = new ProviderEngine();
-provider.addProvider(
- new GanacheSubprovider({
- logger: {
- log: (arg: any) => {
- fs.appendFileSync(config.ganacheLogFile, `${arg}\n`);
+if (testProvider === ProviderType.Ganache) {
+ provider.addProvider(
+ new GanacheSubprovider({
+ logger: {
+ log: (arg: any) => {
+ fs.appendFileSync(config.ganacheLogFile, `${arg}\n`);
+ },
},
- },
- verbose: env.parseBoolean(EnvVars.SolidityCoverage),
- networkId: config.networkId,
- mnemonic: config.mnemonic,
- }),
-);
+ verbose: env.parseBoolean(EnvVars.SolidityCoverage),
+ networkId: config.networkId,
+ mnemonic: config.mnemonic,
+ }),
+ );
+} else {
+ provider.addProvider(new RpcSubprovider({ rpcUrl: 'http://localhost:8501' }));
+}
provider.start();
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. Check README for more details",
+ );
+ 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);