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(cheatcodes): mockCall with bytes4 data #9267

Merged
merged 5 commits into from
Nov 7, 2024
Merged

Conversation

yash-atreya
Copy link
Member

@yash-atreya yash-atreya commented Nov 6, 2024

Motivation

Closes #9213

Solution

  • Add overloads for mock cheatcodes with bytes4 data arg to pass the selector like token.balanceOf.selector instead of abi.encodeWithSelector

Copy link
Collaborator

@grandizzy grandizzy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked again the ticket and I think we got this wrong when discussed action, looks like the proposal is just to add 2 more sigs to make UX better but keep existings @zerosnacks could you also double check please

function mockCall(address where, bytes4 data, bytes calldata retdata) external;

function mockCall(
    address where,
    uint256 value,
    bytes4 data,
    bytes calldata retdata
) external;

@zerosnacks
Copy link
Member

I checked again the ticket and I think we got this wrong when discussed action, looks like the proposal is just to add 2 more sigs to make UX better but keep existings @zerosnacks could you also double check please

function mockCall(address where, bytes4 data, bytes calldata retdata) external;

function mockCall(
    address where,
    uint256 value,
    bytes4 data,
    bytes calldata retdata
) external;

You are correct, this should be additive - not deprecating the current implementation

@yash-atreya yash-atreya enabled auto-merge (squash) November 6, 2024 18:03
@yash-atreya yash-atreya requested a review from grandizzy November 6, 2024 18:03
@grandizzy
Copy link
Collaborator

looks good, I'll push a change to make the same for vm.mockCallRevert sigs and then merge if OK with you @yash-atreya

@zerosnacks zerosnacks self-requested a review November 7, 2024 16:12
Copy link
Member

@zerosnacks zerosnacks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation LGTM, small note regarding name of bytes4 data never mind, this is OK

@yash-atreya yash-atreya merged commit adaad3d into master Nov 7, 2024
21 checks passed
@yash-atreya yash-atreya deleted the yash/b4-mocks branch November 7, 2024 16:13
@zerosnacks zerosnacks restored the yash/b4-mocks branch November 7, 2024 16:13
@zerosnacks zerosnacks deleted the yash/b4-mocks branch November 7, 2024 16:15
@smartcontracts
Copy link
Contributor

Woot, thank you all!

yash-atreya added a commit to foundry-rs/forge-std that referenced this pull request Nov 8, 2024
Ref: foundry-rs/foundry#9267

Adds the following overloads for `vm.mockCall`. 
```solidity
function mockCall(address callee, bytes4 data, bytes calldata returnData) external;

function mockCall(address callee, uint256 msgValue, bytes4 data, bytes calldata returnData) external;

function mockCallRevert(address callee, uint256 msgValue, bytes4 data, bytes calldata revertData) external;

function mockCallRevert(address callee, bytes4 data, bytes calldata revertData) external;
```
rplusq pushed a commit to rplusq/foundry that referenced this pull request Nov 29, 2024
* feat(`cheatcodes`): mockCall with bytes4

* fix

* fix
@grandizzy grandizzy added T-feature Type: feature C-forge Command: forge labels Dec 18, 2024
thomas-lamb-tech pushed a commit to thomas-lamb-tech/std_forge that referenced this pull request Dec 26, 2024
Ref: foundry-rs/foundry#9267

Adds the following overloads for `vm.mockCall`. 
```solidity
function mockCall(address callee, bytes4 data, bytes calldata returnData) external;

function mockCall(address callee, uint256 msgValue, bytes4 data, bytes calldata returnData) external;

function mockCallRevert(address callee, uint256 msgValue, bytes4 data, bytes calldata revertData) external;

function mockCallRevert(address callee, bytes4 data, bytes calldata revertData) external;
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge T-feature Type: feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(cheatcodes): Consider accepting bytes4 as data input to vm.mockCall
4 participants