aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/contracts/src/utils/web3_wrapper.ts3
-rw-r--r--packages/contracts/test/utils/coverage.ts6
-rw-r--r--packages/sol-cov/src/trace.ts24
3 files changed, 22 insertions, 11 deletions
diff --git a/packages/contracts/src/utils/web3_wrapper.ts b/packages/contracts/src/utils/web3_wrapper.ts
index 5d3d9f7c9..02595506b 100644
--- a/packages/contracts/src/utils/web3_wrapper.ts
+++ b/packages/contracts/src/utils/web3_wrapper.ts
@@ -13,6 +13,7 @@ const providerConfigs = { shouldUseInProcessGanache: true };
export const provider = web3Factory.getRpcProvider(providerConfigs);
const isCoverageEnabled = env.parseBoolean(EnvVars.SolidityCoverage);
if (isCoverageEnabled) {
- prependSubprovider(provider, coverage.getCoverageSubproviderSingleton());
+ const coverageSubprovider = coverage.getCoverageSubproviderSingleton();
+ prependSubprovider(provider, coverageSubprovider);
}
export const web3Wrapper = new Web3Wrapper(provider);
diff --git a/packages/contracts/test/utils/coverage.ts b/packages/contracts/test/utils/coverage.ts
index eeb47667f..3b2a8d7b2 100644
--- a/packages/contracts/test/utils/coverage.ts
+++ b/packages/contracts/test/utils/coverage.ts
@@ -16,8 +16,8 @@ export const coverage = {
const defaultFromAddress = devConstants.TESTRPC_FIRST_ADDRESS;
const CONFIG_FILE = 'compiler.json';
const config = JSON.parse(fs.readFileSync(CONFIG_FILE).toString());
- const zeroExArtifactsAdapter = new SolCompilerArtifactAdapter(config.artifactsDir, config.contractsDir);
- const coverageSubrpovider = new CoverageSubprovider(zeroExArtifactsAdapter, defaultFromAddress);
- return coverageSubprovider;
+ const solCompilerArtifactAdapter = new SolCompilerArtifactAdapter(config.artifactsDir, config.contractsDir);
+ const subprovider = new CoverageSubprovider(solCompilerArtifactAdapter, defaultFromAddress);
+ return subprovider;
},
};
diff --git a/packages/sol-cov/src/trace.ts b/packages/sol-cov/src/trace.ts
index 81c8bb0ff..feebaaab5 100644
--- a/packages/sol-cov/src/trace.ts
+++ b/packages/sol-cov/src/trace.ts
@@ -13,7 +13,8 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress
let currentTraceSegment = [];
const callStack = [startAddress];
// tslint:disable-next-line:prefer-for-of
- for (const structLog of structLogs) {
+ for (let i = 0; i < structLogs.length; i++) {
+ const structLog = structLogs[i];
if (structLog.depth !== callStack.length - 1) {
throw new Error("Malformed trace. trace depth doesn't match call stack depth");
}
@@ -26,13 +27,22 @@ export function getTracesByContractAddress(structLogs: StructLog[], startAddress
const currentAddress = _.last(callStack) as string;
const jumpAddressOffset = structLog.op === OpCode.DelegateCall ? 4 : 2;
const newAddress = addressUtils.padZeros(
- new BigNumber(addHexPrefix(structLog.stack[jumpAddressOffset])).toString(16),
+ new BigNumber(addHexPrefix(structLog.stack[structLog.stack.length - jumpAddressOffset])).toString(16),
);
- callStack.push(newAddress);
- traceByContractAddress[currentAddress] = (traceByContractAddress[currentAddress] || []).concat(
- currentTraceSegment,
- );
- currentTraceSegment = [];
+ if (structLog === _.last(structLogs)) {
+ throw new Error('CALL-like opcode can not be the last one');
+ }
+ // Sometimes calls don't change the execution context (current address). When we do a transfer to an
+ // externally owned account - it does the call and immidiately returns because there is no fallback
+ // function. We manually check if the call depth had changed to handle that case.
+ const nextStructLog = structLogs[i + 1];
+ if (nextStructLog.depth !== structLog.depth) {
+ callStack.push(newAddress);
+ traceByContractAddress[currentAddress] = (traceByContractAddress[currentAddress] || []).concat(
+ currentTraceSegment,
+ );
+ currentTraceSegment = [];
+ }
} else if (
_.includes([OpCode.Return, OpCode.Stop, OpCode.Revert, OpCode.Invalid, OpCode.SelfDestruct], structLog.op)
) {