eth-brownie / brownie

A Python-based development and testing framework for smart contracts targeting the Ethereum Virtual Machine.
https://eth-brownie.readthedocs.io
MIT License
2.65k stars 552 forks source link

Add support for `console.log` #480

Open iamdefinitelyahuman opened 4 years ago

iamdefinitelyahuman commented 4 years ago

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.
alcuadrado commented 4 years ago

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

aet00 commented 3 years ago

Has this feature been implemented now? @iamdefinitelyahuman

iamdefinitelyahuman commented 3 years ago

Not yet, need #1043 first

anticlimactic commented 2 years ago

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

Keref commented 2 years ago

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.

zmeghji commented 2 years ago

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 commented 2 years ago

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/

BlinkyStitt commented 2 years ago

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

Keref commented 2 years ago

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

Hugo0 commented 2 years ago

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

0xm4ud commented 1 year ago

Submitted a PR with the implemented feature.