Skip to content

Commit

Permalink
forge fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardJES committed Sep 13, 2024
1 parent 84f2fb2 commit 325c218
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 70 deletions.
1 change: 1 addition & 0 deletions crates/cheatcodes/spec/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ interface Vm {
#[cheatcode(group = Evm, safety = Unsafe)]
function startPrank(address msgSender, bool delegateCall) external;

/// Sets the *next* delegate call's `msg.sender` to be the input address, and the `tx.origin` to be the second input.
#[cheatcode(group = Evm, safety = Unsafe)]
function prank(address msgSender, address txOrigin, bool delegateCall) external;

Expand Down
91 changes: 21 additions & 70 deletions testdata/default/cheats/Prank.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,16 @@ contract PrankTest is DSTest {
vm.prank(address(proxy), true);

// Assert correct `msg.sender`
(bool success, ) = address(impl).delegatecall(
abi.encodeWithSignature(
"assertCorrectCaller(address)",
address(proxy)
)
);
(bool success,) =
address(impl).delegatecall(abi.encodeWithSignature("assertCorrectCaller(address)", address(proxy)));
require(success, "prank2: delegate call failed assertCorrectCaller");

// Assert storage updates
uint256 num = 42;
vm.prank(address(proxy), true);
(bool successTwo, ) = address(impl).delegatecall(
abi.encodeWithSignature("setNum(uint256)", num)
);
(bool successTwo,) = address(impl).delegatecall(abi.encodeWithSignature("setNum(uint256)", num));
require(successTwo, "prank2: delegate call failed setNum");
require(
proxy.num() == num,
"prank2: proxy's storage was not set correctly"
);
require(proxy.num() == num, "prank2: proxy's storage was not set correctly");
vm.stopPrank();
}

Expand All @@ -144,27 +135,15 @@ contract PrankTest is DSTest {
vm.startPrank(address(proxy), true);

// Assert correct `msg.sender`
(bool success, ) = address(impl).delegatecall(
abi.encodeWithSignature(
"assertCorrectCaller(address)",
address(proxy)
)
);
require(
success,
"startPrank2: delegate call failed assertCorrectCaller"
);
(bool success,) =
address(impl).delegatecall(abi.encodeWithSignature("assertCorrectCaller(address)", address(proxy)));
require(success, "startPrank2: delegate call failed assertCorrectCaller");

// Assert storage updates
uint256 num = 42;
(bool successTwo, ) = address(impl).delegatecall(
abi.encodeWithSignature("setNum(uint256)", num)
);
(bool successTwo,) = address(impl).delegatecall(abi.encodeWithSignature("setNum(uint256)", num));
require(successTwo, "startPrank2: delegate call failed setNum");
require(
proxy.num() == num,
"startPrank2: proxy's storage was not set correctly"
);
require(proxy.num() == num, "startPrank2: proxy's storage was not set correctly");
vm.stopPrank();
}

Expand All @@ -174,32 +153,21 @@ contract PrankTest is DSTest {
vm.prank(address(proxy), origin, true);

// Assert correct `msg.sender`
(bool success, ) = address(impl).delegatecall(
abi.encodeWithSignature(
"assertCorrectCaller(address)",
address(proxy)
)
);
(bool success,) =
address(impl).delegatecall(abi.encodeWithSignature("assertCorrectCaller(address)", address(proxy)));
require(success, "prank3: delegate call failed assertCorrectCaller");

// Assert correct `tx.origin`
vm.prank(address(proxy), origin, true);
(bool successTwo, ) = address(impl).delegatecall(
abi.encodeWithSignature("assertCorrectOrigin(address)", origin)
);
(bool successTwo,) = address(impl).delegatecall(abi.encodeWithSignature("assertCorrectOrigin(address)", origin));
require(successTwo, "prank3: delegate call failed assertCorrectOrigin");

// Assert storage updates
uint256 num = 42;
vm.prank(address(proxy), address(origin), true);
(bool successThree, ) = address(impl).delegatecall(
abi.encodeWithSignature("setNum(uint256)", num)
);
(bool successThree,) = address(impl).delegatecall(abi.encodeWithSignature("setNum(uint256)", num));
require(successThree, "prank3: delegate call failed setNum");
require(
proxy.num() == num,
"prank3: proxy's storage was not set correctly"
);
require(proxy.num() == num, "prank3: proxy's storage was not set correctly");
vm.stopPrank();
}

Expand All @@ -209,36 +177,19 @@ contract PrankTest is DSTest {
vm.startPrank(address(proxy), origin, true);

// Assert correct `msg.sender`
(bool success, ) = address(impl).delegatecall(
abi.encodeWithSignature(
"assertCorrectCaller(address)",
address(proxy)
)
);
require(
success,
"startPrank3: delegate call failed assertCorrectCaller"
);
(bool success,) =
address(impl).delegatecall(abi.encodeWithSignature("assertCorrectCaller(address)", address(proxy)));
require(success, "startPrank3: delegate call failed assertCorrectCaller");

// Assert correct `tx.origin`
(bool successTwo, ) = address(impl).delegatecall(
abi.encodeWithSignature("assertCorrectOrigin(address)", origin)
);
require(
successTwo,
"startPrank3: delegate call failed assertCorrectOrigin"
);
(bool successTwo,) = address(impl).delegatecall(abi.encodeWithSignature("assertCorrectOrigin(address)", origin));
require(successTwo, "startPrank3: delegate call failed assertCorrectOrigin");

// Assert storage updates
uint256 num = 42;
(bool successThree, ) = address(impl).delegatecall(
abi.encodeWithSignature("setNum(uint256)", num)
);
(bool successThree,) = address(impl).delegatecall(abi.encodeWithSignature("setNum(uint256)", num));
require(successThree, "startPrank3: delegate call failed setNum");
require(
proxy.num() == num,
"startPrank3: proxy's storage was not set correctly"
);
require(proxy.num() == num, "startPrank3: proxy's storage was not set correctly");
vm.stopPrank();
}

Expand Down

0 comments on commit 325c218

Please sign in to comment.