Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Introduce subprovider for printing revert stack traces #705

Merged
merged 9 commits into from
Jun 15, 2018

Conversation

albrow
Copy link
Contributor

@albrow albrow commented Jun 14, 2018

Description

This PR introduces a new subprovider, RevertTraceSubprovider, which can be enabled in the contracts tests by setting SOLIDITY_REVERT_TRACE=true (or running yarn wsrun test:trace contracts).

Much like the coverage and profiler subproviders, the RevertTraceSubprovider will inject itself into calls to eth_sendTransaction, eth_call, and eth_estimateGas. It gets the trace data for each transaction, keeps track of the call stack, and looks for the REVERT opcode. If it sees the REVERT opcode, it will simply print out the stack trace which led to the revert.

In effect this means that if our tests cause a revert, we will be able to see the origin of that revert as a line number in a Solidity file 🎉

screen shot 2018-06-13 at 7 10 36 pm

screen shot 2018-06-13 at 7 10 28 pm

It's not perfect, but it's a good starting point. One thing we would like to add in the future is including function calls in the stack trace. Right now, entries only appear in the stack trace when we call to another contract (e.g., via the CALL opcode) and we don't track function calls within the same contract.

Motivation and Context

How Has This Been Tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • Change requires a change to the documentation.
  • Added tests to cover my changes.
  • Added new entries to the relevant CHANGELOG.jsons.
  • Labeled this PR with the 'WIP' label if it is a work in progress.
  • Labeled this PR with the labels corresponding to the changed package.

@albrow albrow added the WIP label Jun 14, 2018
@coveralls
Copy link

coveralls commented Jun 14, 2018

Coverage Status

Coverage increased (+0.02%) to 79.421% when pulling 7032825 on feature/revert-trace-subprovider into 0e354e5 on v2-prototype.

@albrow albrow requested a review from LogvinovLeon June 14, 2018 23:05
@albrow albrow removed the WIP label Jun 14, 2018
@albrow albrow changed the title [WIP] Introduce subprovider for printing revert stack traces Introduce subprovider for printing revert stack traces Jun 14, 2018
const enabledSubproviderCount = _.filter([isCoverageEnabled, isProfilerEnabled, isRevertTraceEnabled], _.identity)
.length;
if (enabledSubproviderCount > 1) {
throw new Error(`Only one of coverage, profiler, and revert trace subproviders can be enabled at a time`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use or instead of and?

@albrow albrow merged commit ff0960b into v2-prototype Jun 15, 2018
@albrow albrow deleted the feature/revert-trace-subprovider branch June 15, 2018 00:07
@jdkanani
Copy link

jdkanani commented Jun 16, 2018

I just added revert trace for @trufflesuite. Have to manage sources and sourceCodes fields globally instead of contract-wise.

Thanks for inspiration :) @dekz

screen shot 2018-06-17 at 12 38 37 am

@jdkanani
Copy link

I created sol-trace https://github.com/maticnetwork/sol-trace package for @trufflesuite.

If you have the plan to support it in sol-cov out of the box, let me know I will make sol-trace deprecated.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants