I have a test in foundry where I prank msg.sender
as such:
address USER = address(1);
vm.startPrank(USER);
myContract.doStuff();
console.log("msg.sender from test", msg.sender);
vm.stopPrank();
And in myContract
, I have:
function doStuff() public {
console.log("msg.sender from contract", msg.sender);
And as an output, I get:
msg.sender from test 0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38
msg.sender from contract 0x0000000000000000000000000000000000000001
Is this correct? Why is msg.sender
not being pranked in my test?
Best Answer
Your understanding is correct. The
prank
cheatcode only applies to calls made from your tests; you cannot use the prank cheatcodes to change themsg.sender
of the test functions themselves.To quote the Foundry Book (emphasis mine):
Worth noting that you can change the default
msg.sender
used for test functions by setting thesender
option in your Foundry config: