readCallers

Signature

enum CallerMode {
    None,
    Broadcast,
    RecurrentBroadcast,
    Prank,
    RecurrentPrank
}

function readCallers() 
external 
returns (CallerMode callerMode, address msgSender, address txOrigin);

Description

Reads the current CallerMode, msg.sender, and tx.origin.

The CallerMode enum indicates if there is an active caller modification and the type.

  • If there is an active prank:

    • callerMode will be equal to:
      • CallerMode.Prank if the prank has been set with prank.
      • CallerMode.RecurrentPrank if the prank has been set with startPrank.
  • If there is an active broadcast:

    • callerMode will be equal to:
      • CallerMode.Broadcast if the broadcast has been set with broadcast.
      • CallerMode.RecurrentBroadcast if the broadcast has been set with startBroadcast.
  • If no caller modification is active:

    • callerMode will be equal to CallerMode.None.

Examples

CallerMode callerMode;
address msgSender;
address txOrigin;

// Example 1
(callerMode, msgSender, txOrigin) = vm.readCallers();
assertEq(callerMode, CallerMode.None);
assertEq(msgSender, defaultSenderAddress);
assertEq(txOrigin, defaultOriginAddress);

// Example 2
vm.prank(senderPrankAddress);
(callerMode, msgSender, txOrigin) = vm.readCallers();
assertEq(callerMode, CallerMode.Prank);
assertEq(msgSender, senderPrankAddress);
assertEq(txOrigin, defaultOriginAddress);

// Example 3
vm.prank(senderPrankAddress, originPrankAddress);
(callerMode, msgSender, txOrigin) = vm.readCallers();
assertEq(callerMode, CallerMode.Prank);
assertEq(msgSender, senderPrankAddress);
assertEq(txOrigin, originPrankAddress);

// Example 4
vm.broadcast(broadcastAddress);
(callerMode, msgSender, txOrigin) = vm.readCallers();
assertEq(callerMode, CallerMode.Broadcast);
assertEq(msgSender, broadcastAddress);
assertEq(txOrigin, broadcastAddress);

SEE ALSO