aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2019-01-15 20:33:24 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2019-01-15 20:37:10 +0800
commit63a63543be74d9e8822b7b111aa46350a5f524d8 (patch)
tree054119646cd9994351b67552b4402af009d7fb66 /packages
parent75a4bbc5f2bf38c2ea8c18f21dc9b54eaf5bb422 (diff)
downloaddexon-0x-contracts-63a63543be74d9e8822b7b111aa46350a5f524d8.tar.gz
dexon-0x-contracts-63a63543be74d9e8822b7b111aa46350a5f524d8.tar.zst
dexon-0x-contracts-63a63543be74d9e8822b7b111aa46350a5f524d8.zip
Make mapping namings direct
Diffstat (limited to 'packages')
-rw-r--r--packages/sol-coverage/src/coverage_subprovider.ts4
-rw-r--r--packages/sol-profiler/src/profiler_subprovider.ts6
-rw-r--r--packages/sol-trace/src/revert_trace_subprovider.ts4
-rw-r--r--packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts6
-rw-r--r--packages/sol-tracing-utils/src/collect_coverage_entries.ts8
-rw-r--r--packages/sol-tracing-utils/src/get_source_range_snippet.ts8
-rw-r--r--packages/sol-tracing-utils/src/source_maps.ts6
-rw-r--r--packages/sol-tracing-utils/src/trace.ts22
-rw-r--r--packages/sol-tracing-utils/src/trace_info_subprovider.ts12
-rw-r--r--packages/sol-tracing-utils/test/trace_test.ts4
10 files changed, 40 insertions, 40 deletions
diff --git a/packages/sol-coverage/src/coverage_subprovider.ts b/packages/sol-coverage/src/coverage_subprovider.ts
index 21d25ed74..d03963ed6 100644
--- a/packages/sol-coverage/src/coverage_subprovider.ts
+++ b/packages/sol-coverage/src/coverage_subprovider.ts
@@ -81,12 +81,12 @@ export const coverageHandler: SingleFileSubtraceHandler = (
const branchIds = _.keys(coverageEntriesDescription.branchMap);
for (const branchId of branchIds) {
const branchDescription = coverageEntriesDescription.branchMap[branchId];
- const isBranchCoveredByBranchIndex = _.map(branchDescription.locations, location => {
+ const branchIndexToIsBranchCovered = _.map(branchDescription.locations, location => {
const isBranchCovered = _.some(sourceRanges, range => utils.isRangeInside(range.location, location));
const timesBranchCovered = Number(isBranchCovered);
return timesBranchCovered;
});
- branchCoverage[branchId] = isBranchCoveredByBranchIndex;
+ branchCoverage[branchId] = branchIndexToIsBranchCovered;
}
const statementCoverage: StatementCoverage = {};
const statementIds = _.keys(coverageEntriesDescription.statementMap);
diff --git a/packages/sol-profiler/src/profiler_subprovider.ts b/packages/sol-profiler/src/profiler_subprovider.ts
index c3ed13ea5..9f195f768 100644
--- a/packages/sol-profiler/src/profiler_subprovider.ts
+++ b/packages/sol-profiler/src/profiler_subprovider.ts
@@ -63,7 +63,7 @@ export const profilerHandler: SingleFileSubtraceHandler = (
): Coverage => {
const absoluteFileName = contractData.sources[fileIndex];
const profilerEntriesDescription = collectCoverageEntries(contractData.sourceCodes[fileIndex]);
- const gasConsumedByStatement: { [statementId: string]: number } = {};
+ const statementToGasConsumed: { [statementId: string]: number } = {};
const statementIds = _.keys(profilerEntriesDescription.statementMap);
for (const statementId of statementIds) {
const statementDescription = profilerEntriesDescription.statementMap[statementId];
@@ -83,14 +83,14 @@ export const profilerHandler: SingleFileSubtraceHandler = (
}
}),
);
- gasConsumedByStatement[statementId] = totalGasCost;
+ statementToGasConsumed[statementId] = totalGasCost;
}
const partialProfilerOutput = {
[absoluteFileName]: {
...profilerEntriesDescription,
path: absoluteFileName,
f: {}, // I's meaningless in profiling context
- s: gasConsumedByStatement,
+ s: statementToGasConsumed,
b: {}, // I's meaningless in profiling context
},
};
diff --git a/packages/sol-trace/src/revert_trace_subprovider.ts b/packages/sol-trace/src/revert_trace_subprovider.ts
index d36cba08b..fa065cfcb 100644
--- a/packages/sol-trace/src/revert_trace_subprovider.ts
+++ b/packages/sol-trace/src/revert_trace_subprovider.ts
@@ -106,8 +106,8 @@ export class RevertTraceSubprovider extends TraceCollectionSubprovider {
continue;
}
- const fileIndexByFileName = _.invert(contractData.sources);
- const fileIndex = _.parseInt(fileIndexByFileName[sourceRange.fileName]);
+ const fileNameToFileIndex = _.invert(contractData.sources);
+ const fileIndex = _.parseInt(fileNameToFileIndex[sourceRange.fileName]);
const sourceSnippet = getSourceRangeSnippet(sourceRange, contractData.sourceCodes[fileIndex]);
if (sourceSnippet !== null) {
sourceSnippets.push(sourceSnippet);
diff --git a/packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts b/packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts
index 7d85f6c68..d52587f2c 100644
--- a/packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts
+++ b/packages/sol-tracing-utils/src/artifact_adapters/sol_compiler_artifact_adapter.ts
@@ -5,7 +5,7 @@ import * as glob from 'glob';
import * as _ from 'lodash';
import * as path from 'path';
-import { ContractData } from '../types';
+import { ContractData, SourceCodes, Sources } from '../types';
import { AbstractArtifactAdapter } from './abstract_artifact_adapter';
@@ -43,8 +43,8 @@ export class SolCompilerArtifactAdapter extends AbstractArtifactAdapter {
logUtils.warn(`${artifactFileName} doesn't contain bytecode. Skipping...`);
continue;
}
- const sources: { [sourceId: number]: string } = {};
- const sourceCodes: { [sourceId: number]: string } = {};
+ const sources: Sources = {};
+ const sourceCodes: SourceCodes = {};
_.map(artifact.sources, (value: { id: number }, relativeFilePath: string) => {
const filePath = path.resolve(this._sourcesPath, relativeFilePath);
const fileContent = fs.readFileSync(filePath).toString();
diff --git a/packages/sol-tracing-utils/src/collect_coverage_entries.ts b/packages/sol-tracing-utils/src/collect_coverage_entries.ts
index 3ca794f8e..9e3591d74 100644
--- a/packages/sol-tracing-utils/src/collect_coverage_entries.ts
+++ b/packages/sol-tracing-utils/src/collect_coverage_entries.ts
@@ -8,19 +8,19 @@ import { getOffsetToLocation } from './source_maps';
const IGNORE_RE = /\/\*\s*solcov\s+ignore\s+next\s*\*\/\s*/gm;
// Parsing source code for each transaction/code is slow and therefore we cache it
-const coverageEntriesBySourceHash: { [sourceHash: string]: CoverageEntriesDescription } = {};
+const sourceHashToCoverageEntries: { [sourceHash: string]: CoverageEntriesDescription } = {};
export const collectCoverageEntries = (contractSource: string) => {
const sourceHash = ethUtil.sha3(contractSource).toString('hex');
- if (_.isUndefined(coverageEntriesBySourceHash[sourceHash]) && !_.isUndefined(contractSource)) {
+ if (_.isUndefined(sourceHashToCoverageEntries[sourceHash]) && !_.isUndefined(contractSource)) {
const ast = parser.parse(contractSource, { range: true });
const offsetToLocation = getOffsetToLocation(contractSource);
const ignoreRangesBegingingAt = gatherRangesToIgnore(contractSource);
const visitor = new ASTVisitor(offsetToLocation, ignoreRangesBegingingAt);
parser.visit(ast, visitor);
- coverageEntriesBySourceHash[sourceHash] = visitor.getCollectedCoverageEntries();
+ sourceHashToCoverageEntries[sourceHash] = visitor.getCollectedCoverageEntries();
}
- const coverageEntriesDescription = coverageEntriesBySourceHash[sourceHash];
+ const coverageEntriesDescription = sourceHashToCoverageEntries[sourceHash];
return coverageEntriesDescription;
};
diff --git a/packages/sol-tracing-utils/src/get_source_range_snippet.ts b/packages/sol-tracing-utils/src/get_source_range_snippet.ts
index f578675d3..7aef00fee 100644
--- a/packages/sol-tracing-utils/src/get_source_range_snippet.ts
+++ b/packages/sol-tracing-utils/src/get_source_range_snippet.ts
@@ -13,7 +13,7 @@ interface ASTInfo {
}
// Parsing source code for each transaction/code is slow and therefore we cache it
-const parsedSourceByHash: { [sourceHash: string]: Parser.ASTNode } = {};
+const hashToParsedSource: { [sourceHash: string]: Parser.ASTNode } = {};
/**
* Gets the source range snippet by source range to be used by revert trace.
@@ -22,10 +22,10 @@ const parsedSourceByHash: { [sourceHash: string]: Parser.ASTNode } = {};
*/
export function getSourceRangeSnippet(sourceRange: SourceRange, sourceCode: string): SourceSnippet | null {
const sourceHash = ethUtil.sha3(sourceCode).toString('hex');
- if (_.isUndefined(parsedSourceByHash[sourceHash])) {
- parsedSourceByHash[sourceHash] = Parser.parse(sourceCode, { loc: true });
+ if (_.isUndefined(hashToParsedSource[sourceHash])) {
+ hashToParsedSource[sourceHash] = Parser.parse(sourceCode, { loc: true });
}
- const astNode = parsedSourceByHash[sourceHash];
+ const astNode = hashToParsedSource[sourceHash];
const visitor = new ASTInfoVisitor();
Parser.visit(astNode, visitor);
const astInfo = visitor.getASTInfoForRange(sourceRange);
diff --git a/packages/sol-tracing-utils/src/source_maps.ts b/packages/sol-tracing-utils/src/source_maps.ts
index 0a2d3c88a..8c17652d9 100644
--- a/packages/sol-tracing-utils/src/source_maps.ts
+++ b/packages/sol-tracing-utils/src/source_maps.ts
@@ -1,7 +1,7 @@
import * as _ from 'lodash';
import { getPcToInstructionIndexMapping } from './instructions';
-import { OffsetToLocation, SourceRange } from './types';
+import { OffsetToLocation, SourceCodes, SourceRange, Sources } from './types';
const RADIX = 10;
@@ -39,10 +39,10 @@ export function getOffsetToLocation(str: string): OffsetToLocation {
* @param indexToSource index to source file path
*/
export function parseSourceMap(
- sourceCodes: { [fileIndex: number]: string },
+ sourceCodes: SourceCodes,
srcMap: string,
bytecodeHex: string,
- sources: { [fileIndex: number]: string },
+ sources: Sources,
): { [programCounter: number]: SourceRange } {
const bytecode = Uint8Array.from(Buffer.from(bytecodeHex, 'hex'));
const pcToInstructionIndex: { [programCounter: number]: number } = getPcToInstructionIndexMapping(bytecode);
diff --git a/packages/sol-tracing-utils/src/trace.ts b/packages/sol-tracing-utils/src/trace.ts
index 770080af3..973452b24 100644
--- a/packages/sol-tracing-utils/src/trace.ts
+++ b/packages/sol-tracing-utils/src/trace.ts
@@ -4,21 +4,21 @@ import * as _ from 'lodash';
import { utils } from './utils';
-export interface TraceByContractAddress {
+export interface ContractAddressToTraces {
[contractAddress: string]: StructLog[];
}
/**
- * Converts linear stack trace to `TraceByContractAddress`.
+ * Converts linear stack trace to `ContractAddressToTraces`.
* @param structLogs stack trace
* @param startAddress initial context address
*/
-export function getTracesByContractAddress(structLogs: StructLog[], startAddress: string): TraceByContractAddress {
- const traceByContractAddress: TraceByContractAddress = {};
+export function getContractAddressToTraces(structLogs: StructLog[], startAddress: string): ContractAddressToTraces {
+ const contractAddressToTraces: ContractAddressToTraces = {};
let currentTraceSegment = [];
const addressStack = [startAddress];
if (_.isEmpty(structLogs)) {
- return traceByContractAddress;
+ return contractAddressToTraces;
}
const normalizedStructLogs = utils.normalizeStructLogs(structLogs);
// tslint:disable-next-line:prefer-for-of
@@ -45,14 +45,14 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress
const nextStructLog = normalizedStructLogs[i + 1];
if (nextStructLog.depth !== structLog.depth) {
addressStack.push(newAddress);
- traceByContractAddress[currentAddress] = (traceByContractAddress[currentAddress] || []).concat(
+ contractAddressToTraces[currentAddress] = (contractAddressToTraces[currentAddress] || []).concat(
currentTraceSegment,
);
currentTraceSegment = [];
}
} else if (utils.isEndOpcode(structLog.op)) {
const currentAddress = addressStack.pop() as string;
- traceByContractAddress[currentAddress] = (traceByContractAddress[currentAddress] || []).concat(
+ contractAddressToTraces[currentAddress] = (contractAddressToTraces[currentAddress] || []).concat(
currentTraceSegment,
);
currentTraceSegment = [];
@@ -71,7 +71,7 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress
logUtils.warn(
"Detected a contract created from within another contract. We currently do not support that scenario. We'll just skip that trace",
);
- return traceByContractAddress;
+ return contractAddressToTraces;
} else {
if (structLog !== _.last(normalizedStructLogs)) {
const nextStructLog = normalizedStructLogs[i + 1];
@@ -79,7 +79,7 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress
continue;
} else if (nextStructLog.depth === structLog.depth - 1) {
const currentAddress = addressStack.pop() as string;
- traceByContractAddress[currentAddress] = (traceByContractAddress[currentAddress] || []).concat(
+ contractAddressToTraces[currentAddress] = (contractAddressToTraces[currentAddress] || []).concat(
currentTraceSegment,
);
currentTraceSegment = [];
@@ -94,11 +94,11 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress
}
if (currentTraceSegment.length !== 0) {
const currentAddress = addressStack.pop() as string;
- traceByContractAddress[currentAddress] = (traceByContractAddress[currentAddress] || []).concat(
+ contractAddressToTraces[currentAddress] = (contractAddressToTraces[currentAddress] || []).concat(
currentTraceSegment,
);
currentTraceSegment = [];
logUtils.warn('Malformed trace. Current trace segment non empty at the end');
}
- return traceByContractAddress;
+ return contractAddressToTraces;
}
diff --git a/packages/sol-tracing-utils/src/trace_info_subprovider.ts b/packages/sol-tracing-utils/src/trace_info_subprovider.ts
index 38a55646d..b75fc7bf7 100644
--- a/packages/sol-tracing-utils/src/trace_info_subprovider.ts
+++ b/packages/sol-tracing-utils/src/trace_info_subprovider.ts
@@ -2,7 +2,7 @@ import { NodeType } from '@0x/web3-wrapper';
import * as _ from 'lodash';
import { constants } from './constants';
-import { getTracesByContractAddress } from './trace';
+import { getContractAddressToTraces } from './trace';
import { TraceCollectionSubprovider } from './trace_collection_subprovider';
import { TraceInfo, TraceInfoExistingContract, TraceInfoNewContract } from './types';
@@ -50,13 +50,13 @@ export abstract class TraceInfoSubprovider extends TraceCollectionSubprovider {
disableStorage: true,
});
}
- const tracesByContractAddress = getTracesByContractAddress(trace.structLogs, address);
- const subcallAddresses = _.keys(tracesByContractAddress);
+ const contractAddressToTraces = getContractAddressToTraces(trace.structLogs, address);
+ const subcallAddresses = _.keys(contractAddressToTraces);
if (address === constants.NEW_CONTRACT) {
for (const subcallAddress of subcallAddresses) {
let traceInfo: TraceInfoNewContract | TraceInfoExistingContract;
if (subcallAddress === 'NEW_CONTRACT') {
- const traceForThatSubcall = tracesByContractAddress[subcallAddress];
+ const traceForThatSubcall = contractAddressToTraces[subcallAddress];
traceInfo = {
subtrace: traceForThatSubcall,
txHash,
@@ -65,7 +65,7 @@ export abstract class TraceInfoSubprovider extends TraceCollectionSubprovider {
};
} else {
const runtimeBytecode = await this._web3Wrapper.getContractCodeAsync(subcallAddress);
- const traceForThatSubcall = tracesByContractAddress[subcallAddress];
+ const traceForThatSubcall = contractAddressToTraces[subcallAddress];
traceInfo = {
subtrace: traceForThatSubcall,
txHash,
@@ -78,7 +78,7 @@ export abstract class TraceInfoSubprovider extends TraceCollectionSubprovider {
} else {
for (const subcallAddress of subcallAddresses) {
const runtimeBytecode = await this._web3Wrapper.getContractCodeAsync(subcallAddress);
- const traceForThatSubcall = tracesByContractAddress[subcallAddress];
+ const traceForThatSubcall = contractAddressToTraces[subcallAddress];
const traceInfo: TraceInfoExistingContract = {
subtrace: traceForThatSubcall,
txHash,
diff --git a/packages/sol-tracing-utils/test/trace_test.ts b/packages/sol-tracing-utils/test/trace_test.ts
index 7a034362c..c9ed93e63 100644
--- a/packages/sol-tracing-utils/test/trace_test.ts
+++ b/packages/sol-tracing-utils/test/trace_test.ts
@@ -3,7 +3,7 @@ import { OpCode, StructLog } from 'ethereum-types';
import * as _ from 'lodash';
import 'mocha';
-import { getTracesByContractAddress } from '../src/trace';
+import { getContractAddressToTraces } from '../src/trace';
const expect = chai.expect;
@@ -44,7 +44,7 @@ describe('Trace', () => {
];
const fullTrace = _.map(trace, compactStructLog => addDefaultStructLogFields(compactStructLog));
const startAddress = '0x0000000000000000000000000000000000000001';
- const traceByContractAddress = getTracesByContractAddress(fullTrace, startAddress);
+ const traceByContractAddress = getContractAddressToTraces(fullTrace, startAddress);
const expectedTraceByContractAddress = {
[startAddress]: [fullTrace[0], fullTrace[2]],
[delegateCallAddress]: [fullTrace[1]],