foundry-rs / foundry

Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.
https://getfoundry.sh
Apache License 2.0
8.35k stars 1.77k forks source link

feat(`cheatcodes`): Add `vm.print` to replace `console.log` library #7773

Open mds1 opened 7 months ago

mds1 commented 7 months ago

Component

Forge

Describe the feature you would like

We can remove the large codegen'd console.log libraries in forge-std and replace them with native vm.print cheats (not vm.log since that naming would cause confusion with event logs).

As part of this, we should have methods to print all the structs and enums in Vm.sol, both as standalone, and array variants (e.g. vm.print(AccountAccess) and vm.print(AccountAccess[]) because you get an array back from vm.stopAndReturnStateDiff().

Additionally, all print methods should be pure.

Performance expectations:

This allows us to remove the console and console2 libraries. However, we still have the safeconsole library which does not affect memory. If possible, it would be great for the print cheats to replace that as well. Ref https://github.com/foundry-rs/forge-std/pull/375

This issue is something we've discussed in the past and the idea to add print methods for structs is inspired by https://github.com/foundry-rs/forge-std/pull/439.

Additional context

No response

maurelian commented 1 month ago

Would love to see this, as it would resolve a dilemma wherein we need to choose between:

  1. adding import { console2 as console } from "forge-std/console2.sol"; to every test file, even if it remains unused (which breaks our linting rules).
  2. having to manually add it when debugging a test.