foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Feature Request: Improved delegatecall detection

Open kaihiroi opened this issue 1 year ago • 0 comments

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:

  1. Introduce a new function: vm.expectDelegateCall This would work similarly to vm.expectCall but specifically for delegatecall operations.

  2. Extend vm.expectCall with an AccountAccessKind option This would allow users to specify the type of call they're expecting, including delegatecall.

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;

kaihiroi avatar Jun 27 '24 10:06 kaihiroi