From 760bab8f866ec3d5fc7627ce9bbf5c2eaaef1f36 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 8 Jun 2018 11:18:32 -0700 Subject: Implement SolidityProfiler & adapt sol-cov to work with Geth --- packages/sol-cov/src/profiler_subprovider.ts | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 packages/sol-cov/src/profiler_subprovider.ts (limited to 'packages/sol-cov/src/profiler_subprovider.ts') diff --git a/packages/sol-cov/src/profiler_subprovider.ts b/packages/sol-cov/src/profiler_subprovider.ts new file mode 100644 index 000000000..ac878c070 --- /dev/null +++ b/packages/sol-cov/src/profiler_subprovider.ts @@ -0,0 +1,36 @@ +import * as _ from 'lodash'; + +import { AbstractArtifactAdapter } from './artifact_adapters/abstract_artifact_adapter'; +import { ProfilerManager } from './profiler_manager'; +import { TraceCollectionSubprovider } from './trace_collection_subprovider'; + +/** + * This class implements the [web3-provider-engine](https://github.com/MetaMask/provider-engine) subprovider interface. + * ProfilerSubprovider is used to profile Solidity code while running tests. + */ +export class ProfilerSubprovider extends TraceCollectionSubprovider { + private _profilerManager: ProfilerManager; + /** + * Instantiates a ProfilerSubprovider instance + * @param artifactAdapter Adapter for used artifacts format (0x, truffle, giveth, etc.) + * @param defaultFromAddress default from address to use when sending transactions + * @param isVerbose If true, we will log any unknown transactions. Otherwise we will ignore them + */ + constructor(artifactAdapter: AbstractArtifactAdapter, defaultFromAddress: string, isVerbose: boolean = true) { + const traceCollectionSubproviderConfig = { + shouldCollectTransactionTraces: true, + shouldCollectGasEstimateTraces: false, + shouldCollectCallTraces: false, + }; + super(defaultFromAddress, traceCollectionSubproviderConfig); + this._profilerManager = new ProfilerManager(artifactAdapter, isVerbose); + } + /** + * Write the test profiler results to a file in Istanbul format. + */ + public async writeProfilerOutputAsync(): Promise { + const traceInfos = this.getCollectedTraceInfos(); + _.forEach(traceInfos, traceInfo => this._profilerManager.appendTraceInfo(traceInfo)); + await this._profilerManager.writeProfilerOutputAsync(); + } +} -- cgit v1.2.3