Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow isolate config to be defined inline #6908

Closed
andreas-blockswap opened this issue Jan 26, 2024 · 9 comments · Fixed by #9430
Closed

feat: allow isolate config to be defined inline #6908

andreas-blockswap opened this issue Jan 26, 2024 · 9 comments · Fixed by #9430
Assignees
Labels
A-cheatcodes Area: cheatcodes P-normal Priority: normal T-feature Type: feature T-to-discuss Type: requires discussion
Milestone

Comments

@andreas-blockswap
Copy link

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
Copy link

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
Copy link

Hello, was this implemented?

@kaihiroi
Copy link

kaihiroi commented Jul 3, 2024

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.

@zerosnacks zerosnacks changed the title Clear Transient Storage Cheat Code for Solc 0.8.24 feat: add vm.clearTransient Jul 10, 2024
@zerosnacks zerosnacks added A-cheatcodes Area: cheatcodes T-to-discuss Type: requires discussion labels Jul 10, 2024
@zerosnacks zerosnacks added this to the v1.0.0 milestone Jul 26, 2024
@grandizzy
Copy link
Collaborator

@andreas-blockswap does running in --isolate mode meet your requirement?

@grandizzy grandizzy removed this from the v1.0.0 milestone Oct 3, 2024
@0xdapper
Copy link
Contributor

I think this is still useful, otherwise you are forced to use the whole test suite in isolated to get it to pass in CI? or have some hacks where transient tests get filtered with --mt --mc and both of them be separately ran instead of just a single forge test command in the CI. Is there anyway to clear transient storage atm without this new cheatcode?

@mds1
Copy link
Collaborator

mds1 commented Oct 15, 2024

What about using inline config to specify specific tests that run in isolate mode, this way a single forge test invocation can be used? I am unsure if this is currently supported, but @0xdapper I think this would address your feedback without needing to add a new cheatcode, and should be safer since you don't have to remember to add calls to a cheat

@grandizzy
Copy link
Collaborator

Nice, yeah, I am in favour of this approach too, inline is not supported atm but can be easily added

@0xdapper
Copy link
Contributor

Yes, the inline config would address it. But I still think vm.clearTransient, vm.tstore, vm.tload are all useful cheats. Inline would still be more restrictive in the sense that it is all or nothing, and you would need additional hacks like making external self calls(this.performSomethingWithoutContextChange) while with vm.clearTransient you would control when you want to clear. Maybe it is not a useful general pattern but that could potentially be highlighted in the docs that --isolate might normally the preferred way to test things if you are looking to test some transient state functions?

@grandizzy grandizzy changed the title feat: add vm.clearTransient feat: allow isolate config to be defined inline Nov 7, 2024
@grandizzy grandizzy added this to the v1.0.0 milestone Nov 7, 2024
@grandizzy grandizzy added the P-normal Priority: normal label Nov 12, 2024
@yash-atreya yash-atreya self-assigned this Nov 18, 2024
@yash-atreya yash-atreya moved this from Todo to In Progress in Foundry Nov 18, 2024
@grandizzy
Copy link
Collaborator

ref #5371

@yash-atreya yash-atreya moved this from In Progress to Ready For Review in Foundry Nov 19, 2024
@DaniPopes DaniPopes assigned DaniPopes and unassigned yash-atreya Nov 30, 2024
@github-project-automation github-project-automation bot moved this from Ready For Review to Done in Foundry Dec 2, 2024
@grandizzy grandizzy moved this from Done to Completed in Foundry Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cheatcodes Area: cheatcodes P-normal Priority: normal T-feature Type: feature T-to-discuss Type: requires discussion
Projects
Status: Completed
9 participants