Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: add a log helper library to easily log entire structs directly #439

Closed

Conversation

DrakeEvans
Copy link
Contributor

@DrakeEvans DrakeEvans commented Aug 23, 2023

This is meant to be a placeholder draft PR to discuss a file which allows the logging of the entire struct.

This adds a log(name: String) function to all the structs defined in forge-std so that they can easily be logged to the console during testing.

by adding using forgeStdLogHelper for *; to a test file, any struct returned by a forge-std file can be logged to the console by calling someStruct.log("someStruct");

@mds1
Copy link
Collaborator

mds1 commented Aug 24, 2023

This is interesting, and I like the idea. My main objection with adding this as-is to forge-std is it's impact on compile time. With via-ir, this library takes ~3s to compile for me:

$ hyperfine 'solc $(forge re) src/forgeStdLogHelper.sol --via-ir'
Benchmark 1: solc $(forge re) src/forgeStdLogHelper.sol --via-ir
  Time (mean ± σ):      3.007 s ±  0.079 s    [User: 2.838 s, System: 0.126 s]
  Range (min … max):    2.929 s …  3.209 s    10 runs

Compile times are becoming the speed bottleneck for devs these days, especially with via-ir (related: #225).

As a result, and in the interest of foundry-rs/foundry#3782, I'd prefer to implement this (and more generally, all console.log functionality) as native cheats upstream in forge. We can add a lot of vm.print() signatures to the cheatcode interface and remove the need for all the solidity console.log libraries we currently have here. (logs have existing meaning in the EVM, hence why I'd name it vm.print instead of vm.log)

@mds1
Copy link
Collaborator

mds1 commented Apr 24, 2024

Closing, and created foundry-rs/foundry#7773 to track

@mds1 mds1 closed this Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants