diff options
11 files changed, 42 insertions, 107 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]], @@ -2152,10 +2152,6 @@ aes-js@^0.2.3: version "0.2.4" resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-0.2.4.tgz#94b881ab717286d015fa219e08fb66709dda5a3d" -aes-js@^3.1.1: - version "3.1.2" - resolved "https://registry.npmjs.org/aes-js/-/aes-js-3.1.2.tgz#db9aabde85d5caabbfc0d4f2a4446960f627146a" - agent-base@4, agent-base@^4.1.0, agent-base@~4.2.0: version "4.2.1" resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.2.1.tgz#d89e5999f797875674c07d87f260fc41e83e8ca9" @@ -3725,7 +3721,7 @@ bs-logger@0.x: dependencies: fast-json-stable-stringify "^2.0.0" -bs58@=4.0.1, bs58@^4.0.0: +bs58@=4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/bs58/-/bs58-4.0.1.tgz#be161e76c354f6f788ae4071f63f34e8c4f0a42a" dependencies: @@ -3748,14 +3744,6 @@ bs58check@^1.0.8: bs58 "^3.1.0" create-hash "^1.1.0" -bs58check@^2.1.2: - version "2.1.2" - resolved "https://registry.npmjs.org/bs58check/-/bs58check-2.1.2.tgz#53b018291228d82a5aa08e7d796fdafda54aebfc" - dependencies: - bs58 "^4.0.0" - create-hash "^1.1.0" - safe-buffer "^5.1.2" - bser@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/bser/-/bser-2.0.0.tgz#9ac78d3ed5d915804fd87acb158bc797147a1719" @@ -6511,18 +6499,6 @@ ethereumjs-util@^5.2.0: safe-buffer "^5.1.1" secp256k1 "^3.0.1" -ethereumjs-util@^6.0.0: - version "6.0.0" - resolved "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-6.0.0.tgz#f14841c182b918615afefd744207c7932c8536c0" - dependencies: - bn.js "^4.11.0" - create-hash "^1.1.2" - ethjs-util "^0.1.6" - keccak "^1.0.2" - rlp "^2.0.0" - safe-buffer "^5.1.1" - secp256k1 "^3.0.1" - ethereumjs-vm@2.3.5: version "2.3.5" resolved "https://registry.yarnpkg.com/ethereumjs-vm/-/ethereumjs-vm-2.3.5.tgz#e69306737b8a7ea80c633ceb9b7dd561897007de" @@ -6567,20 +6543,6 @@ ethereumjs-wallet@0.6.0: utf8 "^2.1.1" uuid "^2.0.1" -ethereumjs-wallet@~0.6.0: - version "0.6.3" - resolved "https://registry.npmjs.org/ethereumjs-wallet/-/ethereumjs-wallet-0.6.3.tgz#b0eae6f327637c2aeb9ccb9047b982ac542e6ab1" - dependencies: - aes-js "^3.1.1" - bs58check "^2.1.2" - ethereumjs-util "^6.0.0" - hdkey "^1.1.0" - randombytes "^2.0.6" - safe-buffer "^5.1.2" - scrypt.js "^0.3.0" - utf8 "^3.0.0" - uuid "^3.3.2" - ethers@~4.0.4: version "4.0.4" resolved "https://registry.yarnpkg.com/ethers/-/ethers-4.0.4.tgz#d3f85e8b27f4b59537e06526439b0fb15b44dc65" @@ -6626,13 +6588,6 @@ ethjs-util@^0.1.3: is-hex-prefixed "1.0.0" strip-hex-prefix "1.0.0" -ethjs-util@^0.1.6: - version "0.1.6" - resolved "https://registry.npmjs.org/ethjs-util/-/ethjs-util-0.1.6.tgz#f308b62f185f9fe6237132fb2a9818866a5cd536" - dependencies: - is-hex-prefixed "1.0.0" - strip-hex-prefix "1.0.0" - ev-emitter@^1.0.0, ev-emitter@^1.0.1, ev-emitter@^1.0.2: version "1.1.1" resolved "https://registry.yarnpkg.com/ev-emitter/-/ev-emitter-1.1.1.tgz#8f18b0ce5c76a5d18017f71c0a795c65b9138f2a" @@ -8267,14 +8222,6 @@ hdkey@^0.7.0, hdkey@^0.7.1: coinstring "^2.0.0" secp256k1 "^3.0.1" -hdkey@^1.1.0: - version "1.1.0" - resolved "https://registry.npmjs.org/hdkey/-/hdkey-1.1.0.tgz#e74e7b01d2c47f797fa65d1d839adb7a44639f29" - dependencies: - coinstring "^2.0.0" - safe-buffer "^5.1.1" - secp256k1 "^3.0.1" - he@1.1.1, he@1.1.x: version "1.1.1" resolved "https://registry.yarnpkg.com/he/-/he-1.1.1.tgz#93410fd21b009735151f8868c2f271f3427e23fd" @@ -13458,7 +13405,7 @@ randomatic@^1.1.3: is-number "^3.0.0" kind-of "^4.0.0" -randombytes@^2.0.0, randombytes@^2.0.1, randombytes@^2.0.5, randombytes@^2.0.6: +randombytes@^2.0.0, randombytes@^2.0.1, randombytes@^2.0.5: version "2.0.6" resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.0.6.tgz#d302c522948588848a8d300c932b44c24231da80" dependencies: @@ -14862,14 +14809,6 @@ scrypt.js@0.2.0, scrypt.js@^0.2.0: scrypt "^6.0.2" scryptsy "^1.2.1" -scrypt.js@^0.3.0: - version "0.3.0" - resolved "https://registry.npmjs.org/scrypt.js/-/scrypt.js-0.3.0.tgz#6c62d61728ad533c8c376a2e5e3e86d41a95c4c0" - dependencies: - scryptsy "^1.2.1" - optionalDependencies: - scrypt "^6.0.2" - scrypt@^6.0.2: version "6.0.3" resolved "https://registry.yarnpkg.com/scrypt/-/scrypt-6.0.3.tgz#04e014a5682b53fa50c2d5cce167d719c06d870d" @@ -17137,10 +17076,6 @@ utf8@^2.1.1: version "2.1.2" resolved "https://registry.yarnpkg.com/utf8/-/utf8-2.1.2.tgz#1fa0d9270e9be850d9b05027f63519bf46457d96" -utf8@^3.0.0: - version "3.0.0" - resolved "https://registry.npmjs.org/utf8/-/utf8-3.0.0.tgz#f052eed1364d696e769ef058b183df88c87f69d1" - util-deprecate@^1.0.1, util-deprecate@^1.0.2, util-deprecate@~1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" |