I have a test in foundry where I prank msg.sender as such:

address USER = address(1);
console.log("msg.sender from test", msg.sender);

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?

1 Answer 1


Your understanding is correct. The prank cheatcode only applies to calls made from your tests; you cannot use the prank cheatcodes to change the msg.sender of the test functions themselves.

To quote the Foundry Book (emphasis mine):

Sets msg.sender to the specified address for the next call.

Worth noting that you can change the default msg.sender used for test functions by setting the sender option in your Foundry config:

# foundry.toml
sender = "0xcafe..."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.