-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: add useSeed cheatcode to set RNG seed #10698
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
base: master
Are you sure you want to change the base?
Conversation
Gm @DaniPopes @mattsse @grandizzy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you, makes sense. Please correct tests and run forge fmt
for the new Seed.t.sol
file in order to fix CI
testdata/default/cheats/Seed.t.sol
Outdated
vm.setSeed(seed); | ||
|
||
// Call a foundry cheatcode to get a random value (this depends on the integration) | ||
uint256 rand1 = uint256(vm.randUint()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be vm.randomUint()
instead vm.randUint()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gm, just did it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW @grandizzy, how can I run the tests on my end? It's not really clear in the docs.
I just want to run only Seed.t.sol using the forge
binary to verify that the implementation works properly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for those you can cargo run test_cheats_local_default
uint256 seed = 123456789; | ||
vm.setSeed(seed); | ||
|
||
// Call a foundry cheatcode to get a random value (this depends on the integration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think should only assert same values when seed set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found the issue. It was related to how the seed was being stored in the config. Since config is wrapped in an Arc, calling Arc::make_mut
only modifies the underlying data if there are no other strong references. In my case, the config was being cloned elsewhere, so make_mut
was creating a new copy, and the mutation wasn't visible where it needed to be.
I fixed it by explicitly cloning the config, updating the seed, and replacing the entire Arc inside Cheatcodes
. I also made sure to reset the RNG instance so the new seed takes effect.
The tests are working properly now. Let me know if you can take another look, sorry for the noise! :b
Closes #10664