forge-std icon indicating copy to clipboard operation
forge-std copied to clipboard

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

Open DrakeEvans opened this issue 2 years ago • 1 comments

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");

DrakeEvans avatar Aug 23 '23 18:08 DrakeEvans

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: https://github.com/foundry-rs/forge-std/issues/225).

As a result, and in the interest of https://github.com/foundry-rs/foundry/issues/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 avatar Aug 24 '23 22:08 mds1

Closing, and created https://github.com/foundry-rs/foundry/issues/7773 to track

mds1 avatar Apr 24 '24 21:04 mds1