diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-03-12 19:31:33 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-03-12 19:31:33 +0800 |
commit | 1cdfbbadaa1363ed8f5ecfca61576db70c0c1fb1 (patch) | |
tree | d87622263d20d97e87264effa5f4c0feaec41a30 /packages/sol-cov/src/coverage_manager.ts | |
parent | 2a9913b8fbcc4911593eab0ecdec3b62328e0b31 (diff) | |
download | dexon-0x-contracts-1cdfbbadaa1363ed8f5ecfca61576db70c0c1fb1.tar dexon-0x-contracts-1cdfbbadaa1363ed8f5ecfca61576db70c0c1fb1.tar.gz dexon-0x-contracts-1cdfbbadaa1363ed8f5ecfca61576db70c0c1fb1.tar.bz2 dexon-0x-contracts-1cdfbbadaa1363ed8f5ecfca61576db70c0c1fb1.tar.lz dexon-0x-contracts-1cdfbbadaa1363ed8f5ecfca61576db70c0c1fb1.tar.xz dexon-0x-contracts-1cdfbbadaa1363ed8f5ecfca61576db70c0c1fb1.tar.zst dexon-0x-contracts-1cdfbbadaa1363ed8f5ecfca61576db70c0c1fb1.zip |
Add a HACK to detect coverage of the modifiers with no parameters
Diffstat (limited to 'packages/sol-cov/src/coverage_manager.ts')
-rw-r--r-- | packages/sol-cov/src/coverage_manager.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/packages/sol-cov/src/coverage_manager.ts b/packages/sol-cov/src/coverage_manager.ts index 4ca6b0ec8..b70ca6f3f 100644 --- a/packages/sol-cov/src/coverage_manager.ts +++ b/packages/sol-cov/src/coverage_manager.ts @@ -69,6 +69,30 @@ export class CoverageManager { ); functionCoverage[fnId] = isCovered; } + // HACK: Solidity doesn't emit any opcodes that map back to modifiers with no args, that's why we map back to the + // function range and check if there is any covered statement within that range. + for (const modifierStatementId of coverageEntriesDescription.modifiersStatementIds) { + if (statementCoverage[modifierStatementId]) { + // Already detected as covered + continue; + } + const modifierDescription = coverageEntriesDescription.statementMap[modifierStatementId]; + const enclosingFunction = _.find(coverageEntriesDescription.fnMap, functionDescription => + utils.isRangeInside(modifierDescription, functionDescription.loc), + ) as FunctionDescription; + const isModifierCovered = _.some( + coverageEntriesDescription.statementMap, + (statementDescription: StatementDescription, statementId: number) => { + const isInsideTheModifierEnclosingFunction = utils.isRangeInside( + statementDescription, + enclosingFunction.loc, + ); + const isCovered = statementCoverage[statementId]; + return isInsideTheModifierEnclosingFunction && isCovered; + }, + ); + statementCoverage[modifierStatementId] = isModifierCovered; + } const partialCoverage = { [contractData.sources[fileIndex]]: { ...coverageEntriesDescription, |