aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-cov/src/profiler_subprovider.ts
blob: 9fd815f07258b37b3efaf7a8ad52663213b0a2e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { AbstractArtifactAdapter } from './artifact_adapters/abstract_artifact_adapter';
import { ProfilerManager } from './profiler_manager';
import { TraceCollectionSubprovider } from './trace_collection_subprovider';
import { TraceInfo } from './types';

/**
 * 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);
    }
    public async handleTraceInfoAsync(traceInfo: TraceInfo): Promise<void> {
        await this._profilerManager.computeSingleTraceCoverageAsync(traceInfo);
    }
    /**
     * Write the test profiler results to a file in Istanbul format.
     */
    public async writeProfilerOutputAsync(): Promise<void> {
        await this._profilerManager.writeProfilerOutputAsync();
    }
}