Feature Request: Improved delegatecall detection
Current Situation
Currently, there doesn't seem to be a straightforward way to detect or expect delegatecall operations using vm.expectCall in forge-std. The only method I've found to identify a delegatecall is by using state diff recording, which is not as convenient or explicit as vm.expectCall. Here's an example of the current workaround:
vm.startStateDiffRecording();
address(1).delegatecall("");
VmSafe.AccountAccess[] memory accountAccesses = vm.stopAndReturnStateDiff();
console2.log(accountAccesses[0].kind == VmSafe.AccountAccessKind.DelegateCall);
Feature Request
To improve the testing capabilities for delegatecall operations, I propose one or both of the following enhancements:
-
Introduce a new function:
vm.expectDelegateCallThis would work similarly tovm.expectCallbut specifically fordelegatecalloperations. -
Extend
vm.expectCallwith anAccountAccessKindoption This would allow users to specify the type of call they're expecting, includingdelegatecall.
Rationale
These additions would make it easier and more intuitive to write tests involving delegatecall operations. It would align with the existing patterns in forge-std, making the testing process more consistent across different types of contract interactions.
Potential Implementation
For the vm.expectDelegateCall option:
function expectDelegateCall(address target, bytes memory data) external;
For the extended vm.expectCall:
function expectCall(
address target,
bytes memory data,
VmSafe.AccountAccessKind kind
) external;