aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-cov/src/trace.ts
diff options
context:
space:
mode:
authorAlex Browne <stephenalexbrowne@gmail.com>2018-06-15 06:46:59 +0800
committerAlex Browne <stephenalexbrowne@gmail.com>2018-06-15 06:46:59 +0800
commit263bfb1bdad8acdb9b534edf6e79024e8da35721 (patch)
tree0f0b609ce5ef7b6ca3173efe4f51a2f2ce5f7761 /packages/sol-cov/src/trace.ts
parent7ab921669bf52c1cb2d43350b2cccc8efe91bdbd (diff)
downloaddexon-sol-tools-263bfb1bdad8acdb9b534edf6e79024e8da35721.tar
dexon-sol-tools-263bfb1bdad8acdb9b534edf6e79024e8da35721.tar.gz
dexon-sol-tools-263bfb1bdad8acdb9b534edf6e79024e8da35721.tar.bz2
dexon-sol-tools-263bfb1bdad8acdb9b534edf6e79024e8da35721.tar.lz
dexon-sol-tools-263bfb1bdad8acdb9b534edf6e79024e8da35721.tar.xz
dexon-sol-tools-263bfb1bdad8acdb9b534edf6e79024e8da35721.tar.zst
dexon-sol-tools-263bfb1bdad8acdb9b534edf6e79024e8da35721.zip
Fix a bug in revert_trace.ts
Diffstat (limited to 'packages/sol-cov/src/trace.ts')
-rw-r--r--packages/sol-cov/src/trace.ts16
1 files changed, 8 insertions, 8 deletions
diff --git a/packages/sol-cov/src/trace.ts b/packages/sol-cov/src/trace.ts
index b43fd19a2..fad2e5e08 100644
--- a/packages/sol-cov/src/trace.ts
+++ b/packages/sol-cov/src/trace.ts
@@ -11,7 +11,7 @@ export interface TraceByContractAddress {
export function getTracesByContractAddress(structLogs: StructLog[], startAddress: string): TraceByContractAddress {
const traceByContractAddress: TraceByContractAddress = {};
let currentTraceSegment = [];
- const callStack = [startAddress];
+ const addressStack = [startAddress];
if (_.isEmpty(structLogs)) {
return traceByContractAddress;
}
@@ -19,7 +19,7 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress
// tslint:disable-next-line:prefer-for-of
for (let i = 0; i < normalizedStructLogs.length; i++) {
const structLog = normalizedStructLogs[i];
- if (structLog.depth !== callStack.length - 1) {
+ if (structLog.depth !== addressStack.length - 1) {
throw new Error("Malformed trace. Trace depth doesn't match call stack depth");
}
// After that check we have a guarantee that call stack is never empty
@@ -28,7 +28,7 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress
currentTraceSegment.push(structLog);
if (utils.isCallLike(structLog.op)) {
- const currentAddress = _.last(callStack) as string;
+ const currentAddress = _.last(addressStack) as string;
const jumpAddressOffset = 1;
const newAddress = utils.getAddressFromStackEntry(
structLog.stack[structLog.stack.length - jumpAddressOffset - 1],
@@ -41,14 +41,14 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress
// function. We manually check if the call depth had changed to handle that case.
const nextStructLog = normalizedStructLogs[i + 1];
if (nextStructLog.depth !== structLog.depth) {
- callStack.push(newAddress);
+ addressStack.push(newAddress);
traceByContractAddress[currentAddress] = (traceByContractAddress[currentAddress] || []).concat(
currentTraceSegment,
);
currentTraceSegment = [];
}
} else if (utils.isEndOpcode(structLog.op)) {
- const currentAddress = callStack.pop() as string;
+ const currentAddress = addressStack.pop() as string;
traceByContractAddress[currentAddress] = (traceByContractAddress[currentAddress] || []).concat(
currentTraceSegment,
);
@@ -75,7 +75,7 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress
if (nextStructLog.depth === structLog.depth) {
continue;
} else if (nextStructLog.depth === structLog.depth - 1) {
- const currentAddress = callStack.pop() as string;
+ const currentAddress = addressStack.pop() as string;
traceByContractAddress[currentAddress] = (traceByContractAddress[currentAddress] || []).concat(
currentTraceSegment,
);
@@ -86,11 +86,11 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress
}
}
}
- if (callStack.length !== 0) {
+ if (addressStack.length !== 0) {
logUtils.warn('Malformed trace. Call stack non empty at the end');
}
if (currentTraceSegment.length !== 0) {
- const currentAddress = callStack.pop() as string;
+ const currentAddress = addressStack.pop() as string;
traceByContractAddress[currentAddress] = (traceByContractAddress[currentAddress] || []).concat(
currentTraceSegment,
);