brownie icon indicating copy to clipboard operation
brownie copied to clipboard

Add support for `console.log`

Open iamdefinitelyahuman opened this issue 4 years ago • 11 comments

Overview

Brownie should support console.log as implemented by Buidler

Specification

  1. Access to the functionality comes from an import: import "@nomiclabs/buidler/console.sol";
  2. The imported contract is available at: nomiclabs/buidler/packages/buidler-core/console.sol
  3. console is a library. log sends a call to an empty account with a particular signature depending on the param type(s) given. It will be possible to extract these from the debug_traceTransaction output.

Considerations

  1. How to handle importing console.sol without reliance on NPM? The solution will likely require expanding the brownie package manager.
  2. The implementation must produce consistent results with buidler. Should examine their test cases around this and write similar ones for Brownie.

iamdefinitelyahuman avatar May 03 '20 09:05 iamdefinitelyahuman

Forgot to mention that https://tenderly.dev/ implements the same console.log functionality.

alcuadrado avatar May 03 '20 20:05 alcuadrado

Has this feature been implemented now? @iamdefinitelyahuman

aet00 avatar Jul 02 '21 08:07 aet00

Not yet, need #1043 first

iamdefinitelyahuman avatar Jul 04 '21 23:07 iamdefinitelyahuman

how about now? because it looks like #1043 has been merged. @iamdefinitelyahuman

anticlimactic avatar Feb 22 '22 10:02 anticlimactic

The issue is still open so I comment how I got it to work: I just installed hardhat and dependencies normally with npm, then I run my network with npx hardhat node --network hardhat.

The solidity import uses absolute path import "../node_modules/hardhat/console.sol"; . It works and I get the console logs in the hardhat console when I do testing with brownie.

Keref avatar May 26 '22 02:05 Keref

Emitting events with the data you want to log could be an alternative if you don't want to use hardhat: https://permanentiteration.com/console-log-alternative-for-brownie/

zmeghji avatar Jun 02 '22 21:06 zmeghji

Emitting events don't work if the tx reverts. Also don't spam your blog posts here.

Emitting events with the data you want to log could be an alternative if you don't want to use hardhat: https://permanentiteration.com/console-log-alternative-for-brownie/

Keref avatar Jun 03 '22 02:06 Keref

Actually I am pretty sure that there's still logs up to the revert.

BlinkyStitt avatar Jun 03 '22 05:06 BlinkyStitt

My bad: with eth-brownie indeed tx.events will return the events of a failed tx too

Keref avatar Jun 03 '22 06:06 Keref

Emitting events with the data you want to log could be an alternative if you don't want to use hardhat: https://permanentiteration.com/console-log-alternative-for-brownie/

I actually appreciate the blogpost spam, thanks. Good workaround @zmeghji <3

Hugo0 avatar Aug 09 '22 12:08 Hugo0

Submitted a PR with the implemented feature.

0xm4ud avatar Apr 13 '23 20:04 0xm4ud