aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-cov/src/trace.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-06-09 02:18:32 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-06-09 05:56:45 +0800
commit760bab8f866ec3d5fc7627ce9bbf5c2eaaef1f36 (patch)
tree05911f7eaa9cd8a48448b371f46186d2ffc5541e /packages/sol-cov/src/trace.ts
parent817c332d11835f02726f0609374d1c25c9ab39b5 (diff)
downloaddexon-0x-contracts-760bab8f866ec3d5fc7627ce9bbf5c2eaaef1f36.tar.gz
dexon-0x-contracts-760bab8f866ec3d5fc7627ce9bbf5c2eaaef1f36.tar.zst
dexon-0x-contracts-760bab8f866ec3d5fc7627ce9bbf5c2eaaef1f36.zip
Implement SolidityProfiler & adapt sol-cov to work with Geth
Diffstat (limited to 'packages/sol-cov/src/trace.ts')
-rw-r--r--packages/sol-cov/src/trace.ts16
1 files changed, 14 insertions, 2 deletions
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;
}