zemse / hardhat-tracer

🕵️ allows you to see internal calls, events and storage operations in the console
MIT License
355 stars 36 forks source link

How to trace a code snippet? #47

Open RLSoftwareDev opened 1 year ago

RLSoftwareDev commented 1 year ago

I was picking some random await someContract.someContractCall() to sandwich with hre.tracer.enabled=true/false and trace but still not getting anything. Is it supposed to print something on console while running a test like npx hardhat test? I can see the tracer object is working as console.log(hre.tracer._internal) prints something.

Feel like I'm missing something pretty basic. Would appreciate some help!

zemse commented 1 year ago

Thanks for pointing this out, this should have ideally worked but it didn't because the default verbosity was set to 0. Just published hardhat-tracer@2.3.1 with the fix, you can update to it.

Without updating, the following prop can be added to the hh config.

tracer: {
  defaultVerbosity: 3,
},
RLSoftwareDev commented 1 year ago

Thanks for getting back so quickly. With 2.3.1 everything is traced by default, even without the --trace flag. I tried playing around with defaultVerbosity both in hh config and in node_modules but didn't see any change.

zemse commented 1 year ago

Ah :(

In the original case, i.e. with 2.3.0, npx hardhat test --trace should print the trace for sandwiched code snippet

nishuzumi commented 1 year ago

Same issue

georgeroman commented 1 year ago

One workaround for this is to run in all-traces mode (eg. npx hardhat test --trace) and wrap the code snippet for which you don't want traces (eg. hre.tracer.enabled = false; ...; hre.tracer.enabled = true;). It can be a bit inconvenient but it works.