Truffle: Truffle debug with external contracts

Created on 16 Apr 2020  路  5Comments  路  Source: trufflesuite/truffle

  • [x] I've asked for help in the Truffle Gitter before filing this issue.

Issue

I am using ganache-cli to fork main-net using the --fork flag, also unblocking a given address (using the -u flag) which has some tokens that I need to be able to run some transactions and test a few things.

I have deployed my contract (A) that I compile with truffle to this local fork. This contract speaks to another existing contract already deployed on main-net (B), which speaks to another existing contract (C).

Now it seems like my code is running fine and at some point calls a function of B which itself calls a function of C.

At some point within B or C (not sure), something wrong happens and I get a revert with no message allowing to understand what is wrong.

When I run truffle debug txHash, I can see the list of addresses involved in the transaction, and truffle recognizes my contract properly (great!), but doesn't recognise the others (which makes sense to me as the source code is not in my repo).

So I can step through my code until it calls B and then it's impossible for me to debug further.

I haven't found any recommendation around this kind of workflows, could you provide any guidance on how to debug what's happening in these other contracts?

My guess is that an ideal solution would involve me copying the contract's source, compiling it, and somehow telling truffle where this contract already lives?

Thank you for your help

Steps to Reproduce

Please provide the shortest amount of steps to reproduce your issue.

Expected Behavior

What you expected to happen.

Actual Results

What actually happened. Please give examples and support it with screenshots, copied output or error messages.

Environment

  • Operating System:
  • Ethereum client:
  • Truffle version (truffle version):
  • node version (node --version):
  • npm version (npm --version):
Debugger enhancement priority6 馃挱

Most helpful comment

This now exists! :D Just pass the --fetch-external option to the debugger and it'll be able to download sources off Etherscan. Support for getting them from Sourcify as well is planned. Closing, hope you like it! :)

All 5 comments

Yes, unfortunately there's not a lot we can do here; the debugger depends on having source code and other debugging information.

By the way, note that it is possible to still step through an external contract to some extent; while the debugger will simply skip over external contracts when using the n command (or other similar ones), you can use ; to step through one EVM instruction at a time. That's tedious and not very enlightening, though, so I'm assuming that's not what you want.

The best solution is probably the one you mention -- include the source code for the external contract in your Truffle project so that the debugger knows about it. As long as it ends up compiled with the artifacts in your build folder, you shouldn't need to do any additional work to let the debugger know about its address; the debugger can figure that out on its own. (Or rather the other way around -- the debugger will read the bytecode at that address and see that it matches the contract you included in your project.)

So, that's what I would suggest trying first. Hope that's helpful!

There's likely a new feature or enhancement here to obtain source code when it's not available (e.g., Truffle could grab verified contract sources from Etherscan before starting the debugger.)

Moving this to our backlog for when we get the chance. (Or anyone else who is interested in helping out with this, would very much appreciate it!)

This now exists! :D Just pass the --fetch-external option to the debugger and it'll be able to download sources off Etherscan. Support for getting them from Sourcify as well is planned. Closing, hope you like it! :)

Are the fetched contracts available on disk somewhere after they are fetched?

Are the fetched contracts available on disk somewhere after they are fetched?

They're not right now... this is something we can consider; could you open a new issue for that please?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rotcivegaf picture rotcivegaf  路  3Comments

ripper234 picture ripper234  路  4Comments

timothywangdev picture timothywangdev  路  3Comments

bmmpxf picture bmmpxf  路  3Comments

ysfAskri picture ysfAskri  路  4Comments