blob: bb20e98be422b58d8db49df4dae0753e34888370 (
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
|
import * as fs from 'fs';
import * as glob from 'glob';
import * as _ from 'lodash';
import * as path from 'path';
import { ContractData } from './types';
export const collectContractsData = (artifactsPath: string, sourcesPath: string, networkId: number) => {
const artifactsGlob = `${artifactsPath}/**/*.json`;
const artifactFileNames = glob.sync(artifactsGlob, { absolute: true });
const contractsData: ContractData[] = [];
_.forEach(artifactFileNames, artifactFileName => {
const artifact = JSON.parse(fs.readFileSync(artifactFileName).toString());
const sources = _.keys(artifact.sources);
const contractName = artifact.contractName;
// We don't compute coverage for dependencies
const sourceCodes = _.map(sources, (source: string) =>
fs.readFileSync(path.join(sourcesPath, source)).toString(),
);
const contractData = {
sourceCodes,
sources,
bytecode: artifact.compilerOutput.evm.bytecode.object,
sourceMap: artifact.compilerOutput.evm.bytecode.sourceMap,
runtimeBytecode: artifact.compilerOutput.evm.deployedBytecode.object,
sourceMapRuntime: artifact.compilerOutput.evm.deployedBytecode.sourceMap,
};
contractsData.push(contractData);
});
return contractsData;
};
|