foundry icon indicating copy to clipboard operation
foundry copied to clipboard

`vm.print` to replace `console.log` library

Open mds1 opened this issue 1 year ago • 0 comments

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:

  • Build time should decrease since there is less solidity logic.
  • Run time should be similar, since console.logs already had ABI encoding to execute the staticcall, so there is no extra ABI encoding overhead at runtime.

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

mds1 avatar Apr 24 '24 20:04 mds1