Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: mockCall with actions #7831

Open
PraneshASP opened this issue May 2, 2024 · 0 comments
Open

Feat: mockCall with actions #7831

PraneshASP opened this issue May 2, 2024 · 0 comments
Labels
T-feature Type: feature

Comments

@PraneshASP
Copy link
Contributor

Component

Forge

Describe the feature you would like

Currently, the mockCall() method can only return values. It would be useful to have a similar method called mockCallWithAction(), which takes in encoded calldata and address as additional parameter. For example, in ERC4626 vault's withdraw() method returns the asset amount as well as performs a transfer call which sends funds to the caller/recipient.

So, instead of just doing:

vm.mockCall(
  address(vault),
  abi.encodeWithSelector(IERC4626.withdraw.selector),
  true
);

We can do something like this:

struct Action {
  address target,
  bytes data
 }
  
bytes memory transferCalldata = abi.encodeWithSelector(IERC20.transfer.selector, receiver, 10e18);

Actions[] memory actions = new Action()[1];

actions.push({target: tokenAddress, data: transferCalldata});

vm.mockCallWithActions(
  address(vault),
  abi.encodeWithSelector(IERC4626.withdraw.selector),
  true,
  actions
);

It would also be nice to include actions the ability to trigger specific cheatcodes like deal(), etc.,

This would be super useful during integration testing. Happy to take this on. Let me know wdyt.

Additional context

No response

@PraneshASP PraneshASP added the T-feature Type: feature label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-feature Type: feature
Projects
None yet
Development

No branches or pull requests

1 participant