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.1k stars 1.67k forks source link

feat: add `vm.clearTransient` #6908

Open andreas-blockswap opened 7 months ago

andreas-blockswap commented 7 months ago

Component

Forge

Describe the feature you would like

In solc version 0.8.24, transactions compose differently than message calls. While adding support for solc 0.8.24 (issue #6903) I think that it will be useful with a cheat code to clear the transient storage, so that we can model transactions with message calls.

For example a cheat code function clearTransientStorage(address) to zero the transient storage. This cheat code can be used to model a transaction a.f(x) with

vm.clearTransientStorage(address(a));
a.f(x);
vm.clearTransientStorage(address(a));

and transaction composition of a.f(x) and a.g(y) can be modeled with

vm.clearTransientStorage(address(a));
a.f(x);
vm.clearTransientStorage(address(a));
a.g(y);
vm.clearTransientStorage(address(a));

Additional context

No response

kaihiroi commented 7 months ago

I think the transient storage context should be split by default for each top-level call in the Foundry test runner.

Also, I would like transient storage to be cleared when explicitly switching the runtime context using prank etc.

cloud1992 commented 2 months ago

Hello, was this implemented?

kaihiroi commented 2 months ago

Through this comment, I learned that running tests with the --isolate option allows the top-level call to be executed as a context-independent tx.