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(forge): change startPrank to overwrite existing prank instead of erroring #4826

Merged
merged 16 commits into from
May 11, 2023
Merged
28 changes: 24 additions & 4 deletions testdata/cheats/Prank.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,28 @@ contract PrankTest is DSTest {
);
}

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"
);
}
Comment on lines +173 to +193
Copy link
Member

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?

Copy link
Collaborator

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!


function testStartPrank1AfterStartPrank0(address sender, address origin) public {
// Perform the prank
address oldOrigin = tx.origin;
Expand All @@ -186,9 +208,7 @@ contract PrankTest is DSTest {

// Overwrite the prank
cheats.startPrank(sender, origin);
victim.assertCallerAndOrigin(
sender, "msg.sender was not set during prank", origin, "tx.origin was not set"
);
victim.assertCallerAndOrigin(sender, "msg.sender was not set during prank", origin, "tx.origin was not set");

// Ensure prank is still up as startPrank covers multiple calls
victim.assertCallerAndOrigin(
Expand All @@ -210,7 +230,7 @@ contract PrankTest is DSTest {
// try to overwrite the prank. This should fail.
cheats.startPrank(address(this), origin);
}

function testFailOverwriteUnusedPrankAfterSuccessfulPrank(address sender, address origin) public {
// Set the prank, but not use it
address oldOrigin = tx.origin;
Expand Down