The startPrank cheatcode will set the msg.sender for all subsequent calls until stopPrank is called. This is in
contrast to prank where prank only applies to the next message call.
contract TestContract {
address owner = address(123);
ImportantContract ic;
AnotherImportantContract aic;
function deployImportantContract() public {
require(msg.sender == owner);
// Deploy important contract
ic = new ImportantContract(msg.sender);
}
function deployAnotherImportantContract() public {
require(msg.sender == owner);
// Deploy another important contract
aic = new AnotherImportantContract(msg.sender);
}
function test() public {
// Obtain our cheat code contract reference.
IStdCheats cheats = IStdCheats(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
// Prank and deploy important contracts
cheats.startPrank(owner);
deployImportantContract();
deployAnotherImportantContract();
cheats.stopPrank();
assert(ic.owner() == owner);
assert(aic.owner() == owner);
}function startPrank(address) external;