aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-cov/src/collect_contract_data.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/sol-cov/src/collect_contract_data.ts')
-rw-r--r--packages/sol-cov/src/collect_contract_data.ts28
1 files changed, 8 insertions, 20 deletions
diff --git a/packages/sol-cov/src/collect_contract_data.ts b/packages/sol-cov/src/collect_contract_data.ts
index a0ce2640f..1d8bc7178 100644
--- a/packages/sol-cov/src/collect_contract_data.ts
+++ b/packages/sol-cov/src/collect_contract_data.ts
@@ -6,30 +6,18 @@ import * as path from 'path';
import { ContractData } from './types';
export const collectContractsData = (artifactsPath: string, sourcesPath: string, networkId: number) => {
- const sourcesGlob = `${sourcesPath}/**/*.sol`;
- const sourceFileNames = glob.sync(sourcesGlob, { absolute: true });
- const contractsDataIfExists: Array<ContractData | {}> = _.map(sourceFileNames, sourceFileName => {
- const baseName = path.basename(sourceFileName, '.sol');
- const artifactFileName = path.join(artifactsPath, `${baseName}.json`);
- if (!fs.existsSync(artifactFileName)) {
- // If the contract isn't directly compiled, but is imported as the part of the other contract - we don't
- // have an artifact for it and therefore can't do anything useful with it
- return {};
- }
+ const artifactsGlob = `${artifactsPath}/**/*.json`;
+ const artifactFileNames = glob.sync(artifactsGlob, { absolute: true });
+ const contractsDataIfExists: Array<ContractData | {}> = _.map(artifactFileNames, artifactFileName => {
const artifact = JSON.parse(fs.readFileSync(artifactFileName).toString());
- const sources = _.map(artifact.networks[networkId].sources, source => {
- const includedFileName = glob.sync(`${sourcesPath}/**/${source}`, { absolute: true })[0];
- return includedFileName;
- });
- const sourceCodes = _.map(sources, source => {
- const includedSourceCode = fs.readFileSync(source).toString();
- return includedSourceCode;
- });
+ const sources = artifact.networks[networkId].sources;
+ const contractName = artifact.contract_name;
+ // We don't compute coverage for dependencies
+ const sourceCodes = _.map(sources, (source: string) => fs.readFileSync(source).toString());
if (_.isUndefined(artifact.networks[networkId])) {
- throw new Error(`No ${baseName} artifacts found for networkId ${networkId}`);
+ throw new Error(`No ${contractName} artifacts found for networkId ${networkId}`);
}
const contractData = {
- baseName,
sourceCodes,
sources,
sourceMap: artifact.networks[networkId].source_map,