NomicFoundation / hardhat

Hardhat is a development environment to compile, deploy, test, and debug your Ethereum software.
https://hardhat.org
Other
7.33k stars 1.42k forks source link

Stack traces for caught reverts #1103

Open gitpusha opened 3 years ago

gitpusha commented 3 years ago

Hi,

Heads up: I am not sure if hardhat already generates stack traces for caught reverts because I virtually never saw hardhat stack traces yet due to #1077

It would be great if hardhat would also generate stack traces for any evm reverts or errors that happen during a transaction, even if they are caught in a solidity try catch or similar statement. Maybe in a --verbose mode where such information is logged.

Many protocols need to catch reverts for their safety, but when testing this makes debugging caught reverts much harder as the transaction returns without error, even though you might wanna see some reason.

We usually bubble up revert messages and emit them in events to aid our debugging. This is quite helpful already.

But it would be nice to also have stack traces for such caught reverts.

Unfortunately I do not know the hardhat network evm implementation code (shamefully) and I am not sure how this would be implemented. It seems like it might be quite complex. I am not sure how a revert that is caught in solidity looks on evm-level.

alcuadrado commented 3 years ago

This is a good idea. How do you imagine this would look? How/When would this info be shown?

I believe what you want is the entire execution trace of a contract, like what Tenderly and Brownie show.

zhengger commented 3 years ago

This is a good idea. How do you imagine this would look? How/When would this info be shown?

I believe what you want is the entire execution trace of a contract, like what Tenderly and Brownie show.

Is there anything similar like remix's trace debug function in hardhat?

gitpusha commented 3 years ago

Sorry for the late reply @alcuadrado - I still slack with my github notifications:

This is a good idea. How do you imagine this would look? How/When would this info be shown?

I think any caught reverts could be logged to the console as the tests run with a stack trace, without exiting the process of course.

I believe what you want is the entire execution trace of a contract, like what Tenderly and Brownie show.

Yeah, that would be great. I used Tenderly before and liked it. I didnt try Brownie yet.

AdvaithD commented 3 years ago

Any update on this? Just ran into one such instance, using tenderly.dev as a quick fix for now. Would be great to have functionality similar to truffle debug.

shmuel-web commented 2 years ago

Hi

Joining the request here I also think being able to log the stack trace is a good idea Especially when integrating smart contracts with other projects when you don't have a full understanding of the other project codebase

and smart contract composability is really important so it's a great feature to a dev environment

I imagine it looking something like this

console.trace()

or similar to the JS API MDN

Thanks

nuliknol commented 1 year ago

great idea, I don't know why isn't this implemented