From 7a41a5249fcb8457cb8beb823ce9a1362cdbfa98 Mon Sep 17 00:00:00 2001 From: perissology Date: Thu, 14 Jun 2018 11:17:04 -0700 Subject: Collect coverage for provided sources When solidity generates source maps during contract compilation, the contracts are referred to by an id, which corresponds to an array index. We may not want to cover all sources that were included in a compilation, but because we use array indexes (vs. the id that is provided by solidity compiler) to map the contract to the sourceMap, the provided sourceCodes array must include the code at the correct index. This can result in empty slots in the sourceCodes array. This commit allows the coverage to only be collected for the contracts with provided sourceCode. --- packages/sol-cov/src/coverage_subprovider.ts | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'packages/sol-cov/src/coverage_subprovider.ts') diff --git a/packages/sol-cov/src/coverage_subprovider.ts b/packages/sol-cov/src/coverage_subprovider.ts index 0fa7f873e..2f0bcbb93 100644 --- a/packages/sol-cov/src/coverage_subprovider.ts +++ b/packages/sol-cov/src/coverage_subprovider.ts @@ -66,6 +66,12 @@ export const coverageHandler: SingleFileSubtraceHandler = ( ): Coverage => { const absoluteFileName = contractData.sources[fileIndex]; const coverageEntriesDescription = collectCoverageEntries(contractData.sourceCodes[fileIndex]); + + // if the source wasn't provided for the fileIndex, we can't cover the file + if (_.isUndefined(coverageEntriesDescription)) { + return {}; + } + let sourceRanges = _.map(subtrace, structLog => pcToSourceRange[structLog.pc]); sourceRanges = _.compact(sourceRanges); // Some PC's don't map to a source range and we just ignore them. // By default lodash does a shallow object comparasion. We JSON.stringify them and compare as strings. -- cgit