-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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(forge): change startPrank to overwrite existing prank instead of erroring #4826
Conversation
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.
codewise lgtm,
wdyt @mds1
Should we just change the behavior of Also it looks like this only adds Also one edge case to make sure we handle is: vm.startPrank(msgSender, txOrigin);
// --- do stuff ---
// now we change prank, but need to make sure to reset txOrigin
vm.startPrank(msgSender); |
Works for me |
…rank instead of erroring as per review suggestion
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.
lgtm,
pending @mds1 and lint
Looks good! Just two questions:
|
Both suggestions are reasonable.
Agreed, implemented in 15ac502 Will add tests for this as well
Will add tests for |
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.
lgtm, this seems to work!
just rebased because we landed a big pr on master
Will add tests for startPrank as well
this is the only thing missing, right?
cc @mds1 How do we use a prank in the tests? Specifically, I want to invoke Cheatcodes::call such that the prank is applied here https://github.com/foundry-rs/foundry/pull/4826/files#diff-3a6637039aa2043110b6bf828cf9c802d7621bdd472a536ea43f56421026eb64R597-R616 ? This would require executing a call that that uses the prank. I don't see any example of this in I do expect the added tests to fail now because we added an error for calls to |
hey hey @4meta5 thanks for the work! I've pushed some commits to your branch to get it over the line, hope you don't mind:
cc @mattsse / @mds1 should be g2g bar CI (github is having problems) |
@Evalir just confirming if you or @4meta5 handled these items too / have test cases for them? #4826 (comment) |
Ah whoops, seems I stashed & didn't upload that edge case: It is handled, but just pushed the missing test |
function testStartPrank0AfterPrank1(address sender, address origin) public { | ||
// Perform the prank | ||
address oldOrigin = tx.origin; | ||
Victim victim = new Victim(); | ||
cheats.startPrank(sender, origin); | ||
victim.assertCallerAndOrigin( | ||
sender, "msg.sender was not set during prank", origin, "tx.origin was not set during prank" | ||
); | ||
|
||
// Overwrite the prank | ||
cheats.startPrank(sender); | ||
victim.assertCallerAndOrigin( | ||
sender, "msg.sender was not set during prank", oldOrigin, "tx.origin invariant failed" | ||
); | ||
|
||
cheats.stopPrank(); | ||
// Ensure we cleaned up correctly after stopping the prank | ||
victim.assertCallerAndOrigin( | ||
address(this), "msg.sender was not cleaned up", oldOrigin, "tx.origin invariant failed" | ||
); | ||
} |
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.
Just to confirm: this should be the edge case you're talking about @mds1 right?
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.
Yep that's it, thanks!
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.
sweet,
tysm @4meta5
This is awesome! I'm glad that this was implemented. Am I correct that now I can replace all of our uses of |
Yep you should be able to! We should also get a PR in to forge-std that logs a deprecation warning when using |
Cool feature, but should contract deployment count also as if state was applied? Currently I have some code that fails with this:
|
Closes #4779
Motivation
There is user demand for a
startPrank
orchangePrank
cheatcode that allows optimistically setting a new prank such that any existing prank is overwritten and there is no error if the existing prank is not set.Solution
startPrank
is changed to allow overwriting existing pranks instead of erroring. It is not able to overwrite existing pranks unless the existing prank has already been applied at least once.