foundry-rs / foundry-rs/foundry

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

Open
#7,773 1 comment 9 reactions 0 assignees View on GitHub
A-cheatcodes T-feature
Dominant language
Rust
Stars
10.6k
Forks
2.6k
Avg merge
18h 20m
Merged PRs (30d)
510

Description

### 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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.