Skip to content

feat: expectAndMockCall #676

@deluca-mike

Description

@deluca-mike

It would be nice to have this:

vm.expectAndMockCall(
    inboxes_[0],
    abi.encodeWithSelector(
        MockERC20Inbox.sendContractTransaction.selector,
        100_001,
        1_000_000,
        _appChainGateway,
        0,
        abi.encodeCall(IAppChainGatewayLike.receiveParameters, (0, keyChains_, values_))
    ),
    abi.encode(uint256(11))
);

instead of this:

vm.expectCall(
    inboxes_[0],
    abi.encodeWithSelector(
        MockERC20Inbox.sendContractTransaction.selector,
        100_000,
        1_000_000,
        _appChainGateway,
        0,
        abi.encodeCall(IAppChainGatewayLike.receiveParameters, (0, keyChains_, values_))
    )
);

vm.mockCall(
    inboxes_[0],
    abi.encodeWithSelector(
        MockERC20Inbox.sendContractTransaction.selector,
        100_001,
        1_000_000,
        _appChainGateway,
        0,
        abi.encodeCall(IAppChainGatewayLike.receiveParameters, (0, keyChains_, values_))
    ),
    abi.encode(uint256(11))
);

Sure, we could make a helper function:

function _expectAndMockCall(address callee, bytes memory data, bytes memory returnData) internal {
    vm.expectCall(callee, data);
    vm.mockCall(callee, data, returnData);
}

but forge-std is that helper tooling, so it probably makes sense that it lives there.

See this foundry issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions