Skip to content

Feature request: adding console.log(string,bytes32) #129

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
0xPhaze opened this issue Jul 15, 2022 · 6 comments
Closed

Feature request: adding console.log(string,bytes32) #129

0xPhaze opened this issue Jul 15, 2022 · 6 comments

Comments

@0xPhaze
Copy link
Contributor

0xPhaze commented Jul 15, 2022

I often find myself needing to log bytes32 and currently this only works with console.logBytes32.
Is there a possibility of extending console to add in console.log(bytes32) or console.log(string,bytes32)?

@PaulRBerg
Copy link
Contributor

Related: NomicFoundation/hardhat#1440

@0xPhaze
Copy link
Contributor Author

0xPhaze commented Jul 17, 2022

Maybe console2 could pick up these changes quicker than waiting for changes to console.
And couldn't I just be required to explicitly cast to bytes32 in the case of ambiguity. For example: console.log('var', bytes32(0x1337)). This would still be a nicer UX compared to console.logBytes32, imo, but either is good.

@PaulRBerg
Copy link
Contributor

I agree, not having to use console.logBytes32 would be a better DX.

@mds1
Copy link
Collaborator

mds1 commented Jul 17, 2022

I'd say PRs for things like this into console2.sol are good, but we should leave console.sol 1:1 with hardhat. @ZeroEkkusu let me know if that seems reasonable.

And couldn't I just be required to explicitly cast to bytes32 in the case of ambiguity. For example: console.log('var', bytes32(0x1337)). This would still be a nicer UX compared to console.logBytes32, imo, but either is good.

Yea if there's ambiguity in your call solc will just force you to cast and be explicit, which I think is ok

@ZeroEkkusu
Copy link
Collaborator

Agree with console/console2.

@mds1
Copy link
Collaborator

mds1 commented Mar 9, 2023

Is there a possibility of extending console to add in console.log(bytes32) or console.log(string,bytes32)?

As hinted at above, the reason it's console.logBytes32(bytes32) and why we shouldn't add support for console.log(bytes32) (and similar for the overload with a leading string arg) is because then something like console.log("x") becomes ambiguous, as solc doesn't know if "x" is bytes32 or a string. So this would end up being a big breaking change for users by requiring type casts to existing code. As a result I'm going to close this 🙂

If you'd prefer the overload + required casting, I'd suggest leaving a comment on foundry-rs/foundry#3782 since there may eventually be a vm.consoleLog type of cheat

@mds1 mds1 closed this as completed Mar 9, 2023
@mds1 mds1 closed this as not planned Won't fix, can't repro, duplicate, stale Mar 9, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants