Add support for `console.log`
Overview
Brownie should support console.log as implemented by Buidler
Specification
- Access to the functionality comes from an import:
import "@nomiclabs/buidler/console.sol"; - The imported contract is available at: nomiclabs/buidler/packages/buidler-core/console.sol
-
consoleis a library.logsends 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 thedebug_traceTransactionoutput.
Considerations
- How to handle importing
console.solwithout reliance on NPM? The solution will likely require expanding the brownie package manager. - The implementation must produce consistent results with buidler. Should examine their test cases around this and write similar ones for Brownie.
Forgot to mention that https://tenderly.dev/ implements the same console.log functionality.
Has this feature been implemented now? @iamdefinitelyahuman
Not yet, need #1043 first
how about now? because it looks like #1043 has been merged. @iamdefinitelyahuman
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.
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/
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/
Actually I am pretty sure that there's still logs up to the revert.
My bad: with eth-brownie indeed tx.events will return the events of a failed tx too
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
Submitted a PR with the implemented feature.