aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-cov/src/artifact_adapters/truffle.ts
blob: e891bb46493a39b76e60000340e1341e79cc539a (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
37
38
39
40
41
42
43
import { Compiler, CompilerOptions } from '@0xproject/sol-compiler';
import * as fs from 'fs';
import * as glob from 'glob';
import * as _ from 'lodash';
import * as path from 'path';
import * as rimraf from 'rimraf';

import { ContractData } from '../types';

import { ZeroExArtifactAdapter } from './0x';
import { AbstractArtifactAdapter } from './abstract';

export class TruffleArtifactAdapter extends AbstractArtifactAdapter {
    private _solcVersion: string;
    private _sourcesPath: string;
    constructor(sourcesPath: string, solcVersion: string) {
        super();
        this._solcVersion = solcVersion;
        this._sourcesPath = sourcesPath;
    }
    public async collectContractsDataAsync(): Promise<ContractData[]> {
        const artifactsDir = '0x-artifacts';
        const compilerOptions: CompilerOptions = {
            contractsDir: this._sourcesPath,
            artifactsDir,
            compilerSettings: {
                outputSelection: {
                    ['*']: {
                        ['*']: ['abi', 'evm.bytecode.object', 'evm.deployedBytecode.object'],
                    },
                },
            },
            contracts: '*',
            solcVersion: this._solcVersion,
        };
        const compiler = new Compiler(compilerOptions);
        await compiler.compileAsync();
        const zeroExArtifactAdapter = new ZeroExArtifactAdapter(artifactsDir, this._sourcesPath);
        const contractsDataFrom0xArtifacts = await zeroExArtifactAdapter.collectContractsDataAsync();
        rimraf.sync(artifactsDir);
        return contractsDataFrom0xArtifacts;
    }
}