From 760bab8f866ec3d5fc7627ce9bbf5c2eaaef1f36 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 8 Jun 2018 11:18:32 -0700 Subject: Implement SolidityProfiler & adapt sol-cov to work with Geth --- packages/sol-cov/src/trace.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'packages/sol-cov/src/trace.ts') diff --git a/packages/sol-cov/src/trace.ts b/packages/sol-cov/src/trace.ts index c725de3d0..45e45e9c5 100644 --- a/packages/sol-cov/src/trace.ts +++ b/packages/sol-cov/src/trace.ts @@ -16,6 +16,13 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress const traceByContractAddress: TraceByContractAddress = {}; let currentTraceSegment = []; const callStack = [startAddress]; + if (_.isEmpty(structLogs)) { + return traceByContractAddress; + } + if (structLogs[0].depth === 1) { + // Geth uses 1-indexed depth counter whilst ganache starts from 0 + _.forEach(structLogs, structLog => structLog.depth--); + } // tslint:disable-next-line:prefer-for-of for (let i = 0; i < structLogs.length; i++) { const structLog = structLogs[i]; @@ -95,10 +102,15 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress } } if (callStack.length !== 0) { - throw new Error('Malformed trace. Call stack non empty at the end'); + logUtils.warn('Malformed trace. Call stack non empty at the end'); } if (currentTraceSegment.length !== 0) { - throw new Error('Malformed trace. Current trace segment non empty at the end'); + const currentAddress = callStack.pop() as string; + traceByContractAddress[currentAddress] = (traceByContractAddress[currentAddress] || []).concat( + currentTraceSegment, + ); + currentTraceSegment = []; + logUtils.warn('Malformed trace. Current trace segment non empty at the end'); } return traceByContractAddress; } -- cgit v1.2.3