From 6e0aef5f2bd8cd3ca9086abf4794028feac5ae9b Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Tue, 22 May 2018 15:14:07 -0700 Subject: Fix depth tracking in a tracer --- packages/sol-cov/src/trace.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/sol-cov/src/trace.ts b/packages/sol-cov/src/trace.ts index 389bd8309..28fc7d004 100644 --- a/packages/sol-cov/src/trace.ts +++ b/packages/sol-cov/src/trace.ts @@ -25,7 +25,7 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress if (_.includes([OpCode.CallCode, OpCode.StaticCall, OpCode.Call, OpCode.DelegateCall], structLog.op)) { const currentAddress = _.last(callStack) as string; - const jumpAddressOffset = structLog.op === OpCode.DelegateCall ? 4 : 2; + const jumpAddressOffset = 1; const newAddress = addressUtils.padZeros( new BigNumber(addHexPrefix(structLog.stack[structLog.stack.length - jumpAddressOffset - 1])).toString( 16, @@ -65,6 +65,21 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress "Detected a contract created from within another contract. Sol-cov currently doesn't support that scenario. We'll just skip that trace", ); return traceByContractAddress; + } else { + if (structLog !== _.last(structLogs)) { + const nextStructLog = structLogs[i + 1]; + if (nextStructLog.depth === structLog.depth) { + continue; + } else if (nextStructLog.depth === structLog.depth - 1) { + const currentAddress = callStack.pop() as string; + traceByContractAddress[currentAddress] = (traceByContractAddress[currentAddress] || []).concat( + currentTraceSegment, + ); + currentTraceSegment = []; + } else { + throw new Error('Shit broke'); + } + } } } if (callStack.length !== 0) { -- cgit v1.2.3