Skip to content

WIP: add vm.stopRecordAndReturnAccesses() cheatcode #10370

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tushar994
Copy link
Contributor

@tushar994 tushar994 commented Apr 25, 2025

Motivation

solves #10240

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@tushar994 tushar994 changed the title add vm.stopAndReturnAccesses() cheatcode add vm.stopRecordAndReturnAccesses() cheatcode Apr 25, 2025
Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good! However, I realized that this might not cover all use cases: calling stopRecordAndReturnAccesses resets the accesses and it returns them for one address; if I want to stop and return for multiple addresses, this is not possible as accesses calls after will always return empty arrays;

I think we need a stopRecord that stops recording without clearing, and then clear on the next record call instead.

@grandizzy @mattsse thoughts?

@tushar994 tushar994 changed the title add vm.stopRecordAndReturnAccesses() cheatcode WIP: add vm.stopRecordAndReturnAccesses() cheatcode Apr 26, 2025
@tushar994
Copy link
Contributor Author

@grandizzy sorry for noob question, but how do I run the integration tests in testdata/default/cheats locally?

@DaniPopes
Copy link
Member

they are defined here https://github.com/foundry-rs/foundry/blob/master/crates/forge/tests/it/cheats.rs
cargo test -p forge --test it test_cheats_local_default

@grandizzy
Copy link
Collaborator

grandizzy commented Apr 26, 2025

I think we need a stopRecord that stops recording without clearing, and then clear on the next record call instead.

@grandizzy @mattsse thoughts?

Thanks, this looks good! However, I realized that this might not cover all use cases: calling stopRecordAndReturnAccesses resets the accesses and it returns them for one address; if I want to stop and return for multiple addresses, this is not possible as accesses calls after will always return empty arrays;

I think we need a stopRecord that stops recording without clearing, and then clear on the next record call instead.

@grandizzy @mattsse thoughts?

Yeah, that makes sense. So stopRecord should not set state.accesses to None but rather set a flag to mark it as stopped/no new records allowed - that is to still be able to retrieve records after (would here make sense to have a resumeRecord that will reallow records in case one wants to skip some actions?). Then a new record call should set the flag to true and reset all recorded accesses. @DaniPopes @tushar994 wdyt?

@tushar994 tushar994 closed this Apr 26, 2025
@github-project-automation github-project-automation bot moved this to Done in Foundry Apr 26, 2025
@tushar994
Copy link
Contributor Author

I think we need a stopRecord that stops recording without clearing, and then clear on the next record call instead.
@grandizzy @mattsse thoughts?

Thanks, this looks good! However, I realized that this might not cover all use cases: calling stopRecordAndReturnAccesses resets the accesses and it returns them for one address; if I want to stop and return for multiple addresses, this is not possible as accesses calls after will always return empty arrays;
I think we need a stopRecord that stops recording without clearing, and then clear on the next record call instead.
@grandizzy @mattsse thoughts?

Yeah, that makes sense. So stopRecord should not set state.accesses to None but rather set a flag to mark it as stopped/no new records allowed - that is to still be able to retrieve records after (would here make sense to have a resumeRecord that will reallow records in case one wants to skip some actions?). Then a new record call should set the flag to true and reset all recorded accesses. @DaniPopes @tushar994 wdyt?

I had thought the same, but didnt implement it because I thought i'd just stick to what was proposed in the issue. Will implement that! thank you!

@tushar994 tushar994 reopened this Apr 26, 2025
@tushar994
Copy link
Contributor Author

sorry closed it by accident

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants