aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-cov/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-03-18 21:01:18 +0800
committerFabio Berger <me@fabioberger.com>2018-03-18 21:01:18 +0800
commit4948551703fb3cb9f8470d9f4a61a9a5473e5afa (patch)
tree2e7d4d2e9c98cb6bebf7bdd17444d4b351220018 /packages/sol-cov/src
parentd7bf003d511321ec6cb8814cb1549c46b4efba86 (diff)
parentd4c1b3b0bd26e730ce6687469cdf7283877543e1 (diff)
downloaddexon-sol-tools-4948551703fb3cb9f8470d9f4a61a9a5473e5afa.tar
dexon-sol-tools-4948551703fb3cb9f8470d9f4a61a9a5473e5afa.tar.gz
dexon-sol-tools-4948551703fb3cb9f8470d9f4a61a9a5473e5afa.tar.bz2
dexon-sol-tools-4948551703fb3cb9f8470d9f4a61a9a5473e5afa.tar.lz
dexon-sol-tools-4948551703fb3cb9f8470d9f4a61a9a5473e5afa.tar.xz
dexon-sol-tools-4948551703fb3cb9f8470d9f4a61a9a5473e5afa.tar.zst
dexon-sol-tools-4948551703fb3cb9f8470d9f4a61a9a5473e5afa.zip
merge development
Diffstat (limited to 'packages/sol-cov/src')
-rw-r--r--packages/sol-cov/src/ast_visitor.ts4
-rw-r--r--packages/sol-cov/src/collect_coverage_entries.ts2
-rw-r--r--packages/sol-cov/src/constants.ts5
-rw-r--r--packages/sol-cov/src/coverage_manager.ts2
-rw-r--r--packages/sol-cov/src/globals.d.ts3
-rw-r--r--packages/sol-cov/src/instructions.ts9
-rw-r--r--packages/sol-cov/src/source_maps.ts11
7 files changed, 20 insertions, 16 deletions
diff --git a/packages/sol-cov/src/ast_visitor.ts b/packages/sol-cov/src/ast_visitor.ts
index 66190afec..88309d3eb 100644
--- a/packages/sol-cov/src/ast_visitor.ts
+++ b/packages/sol-cov/src/ast_visitor.ts
@@ -113,8 +113,8 @@ export class ASTVisitor {
this._statementMap[this._entryId++] = this._getExpressionRange(ast);
}
private _getExpressionRange(ast: Parser.ASTNode): SingleFileSourceRange {
- const start = this._locationByOffset[ast.range[0] - 1];
- const end = this._locationByOffset[ast.range[1]];
+ const start = this._locationByOffset[ast.range[0]];
+ const end = this._locationByOffset[ast.range[1] + 1];
const range = {
start,
end,
diff --git a/packages/sol-cov/src/collect_coverage_entries.ts b/packages/sol-cov/src/collect_coverage_entries.ts
index 6da81fbfc..97218616c 100644
--- a/packages/sol-cov/src/collect_coverage_entries.ts
+++ b/packages/sol-cov/src/collect_coverage_entries.ts
@@ -10,7 +10,7 @@ import { getLocationByOffset } from './source_maps';
// Parsing source code for each transaction/code is slow and therefore we cache it
const coverageEntriesBySourceHash: { [sourceHash: string]: CoverageEntriesDescription } = {};
-export const collectCoverageEntries = (contractSource: string, fileName: string) => {
+export const collectCoverageEntries = (contractSource: string) => {
const sourceHash = ethUtil.sha3(contractSource).toString('hex');
if (_.isUndefined(coverageEntriesBySourceHash[sourceHash])) {
const ast = parser.parse(contractSource, { range: true });
diff --git a/packages/sol-cov/src/constants.ts b/packages/sol-cov/src/constants.ts
index 970734f2d..64d2228a3 100644
--- a/packages/sol-cov/src/constants.ts
+++ b/packages/sol-cov/src/constants.ts
@@ -1,3 +1,8 @@
+// tslint:disable:number-literal-format
export const constants = {
NEW_CONTRACT: 'NEW_CONTRACT',
+ PUSH1: 0x60,
+ PUSH2: 0x61,
+ PUSH32: 0x7f,
+ TIMESTAMP: 0x42,
};
diff --git a/packages/sol-cov/src/coverage_manager.ts b/packages/sol-cov/src/coverage_manager.ts
index b1ba8b22b..230ccc3c9 100644
--- a/packages/sol-cov/src/coverage_manager.ts
+++ b/packages/sol-cov/src/coverage_manager.ts
@@ -39,7 +39,7 @@ export class CoverageManager {
fileIndex: number,
): Coverage {
const fileName = contractData.sources[fileIndex];
- const coverageEntriesDescription = collectCoverageEntries(contractData.sourceCodes[fileIndex], fileName);
+ const coverageEntriesDescription = collectCoverageEntries(contractData.sourceCodes[fileIndex]);
let sourceRanges = _.map(coveredPcs, coveredPc => pcToSourceRange[coveredPc]);
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.
diff --git a/packages/sol-cov/src/globals.d.ts b/packages/sol-cov/src/globals.d.ts
index 3e457f0b5..0ee0f394c 100644
--- a/packages/sol-cov/src/globals.d.ts
+++ b/packages/sol-cov/src/globals.d.ts
@@ -1,5 +1,6 @@
-// tslint:disable:completed-docs
+declare module 'dirty-chai';
+// tslint:disable:completed-docs
declare module '*.json' {
const json: any;
/* tslint:disable */
diff --git a/packages/sol-cov/src/instructions.ts b/packages/sol-cov/src/instructions.ts
index c6506e58d..40987dbe5 100644
--- a/packages/sol-cov/src/instructions.ts
+++ b/packages/sol-cov/src/instructions.ts
@@ -1,9 +1,8 @@
-// tslint:disable:number-literal-format
-const PUSH1 = 0x60;
-const PUSH32 = 0x7f;
-const isPush = (inst: number) => inst >= PUSH1 && inst <= PUSH32;
+import { constants } from './constants';
-const pushDataLength = (inst: number) => inst - PUSH1 + 1;
+const isPush = (inst: number) => inst >= constants.PUSH1 && inst <= constants.PUSH32;
+
+const pushDataLength = (inst: number) => inst - constants.PUSH1 + 1;
const instructionLength = (inst: number) => (isPush(inst) ? pushDataLength(inst) + 1 : 1);
diff --git a/packages/sol-cov/src/source_maps.ts b/packages/sol-cov/src/source_maps.ts
index 9b3ea9e24..694171442 100644
--- a/packages/sol-cov/src/source_maps.ts
+++ b/packages/sol-cov/src/source_maps.ts
@@ -12,12 +12,12 @@ export interface SourceLocation {
}
export function getLocationByOffset(str: string): LocationByOffset {
- const locationByOffset: LocationByOffset = {};
+ const locationByOffset: LocationByOffset = { 0: { line: 1, column: 0 } };
let currentOffset = 0;
for (const char of str.split('')) {
- const location = locationByOffset[currentOffset - 1] || { line: 1, column: 0 };
+ const location = locationByOffset[currentOffset];
const isNewline = char === '\n';
- locationByOffset[currentOffset] = {
+ locationByOffset[currentOffset + 1] = {
line: location.line + (isNewline ? 1 : 0),
column: isNewline ? 0 : location.column + 1,
};
@@ -59,9 +59,8 @@ export function parseSourceMap(
if (parsedEntry.fileIndex !== -1) {
const sourceRange = {
location: {
- start: locationByOffsetByFileIndex[parsedEntry.fileIndex][parsedEntry.offset - 1],
- end:
- locationByOffsetByFileIndex[parsedEntry.fileIndex][parsedEntry.offset + parsedEntry.length - 1],
+ start: locationByOffsetByFileIndex[parsedEntry.fileIndex][parsedEntry.offset],
+ end: locationByOffsetByFileIndex[parsedEntry.fileIndex][parsedEntry.offset + parsedEntry.length],
},
fileName: sources[parsedEntry.fileIndex],
};