Skip to content

bug(cheatcodes): mockCall does not mock correctly when methods does not return a value #10703

Open
@lemunozm

Description

@lemunozm

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge Version: 1.2.2-nightly

What version of Foundryup are you on?

forge Version: 1.2.2-nightly

What command(s) is the bug in?

forge test

Operating System

macOS (Apple Silicon)

Describe the bug

If I do the following, it will revert:

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;

import "forge-std/Test.sol";

interface IExample {
    function foo(uint a) external;
}

contract MyTest is Test {
    function testFoo() public {
        IExample(address(1)).foo(42);
    }
}

because address(1) is not a contract.

Nevertheless, if I use mockCall like this:

// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.28;

import "forge-std/Test.sol";

interface IExample {
    function foo(uint a) external;
}

contract MyTest is Test {
    function testFoo() public {
        vm.mockCall(address(1), "randomvalue", abi.encode());
        IExample(address(1)).foo(42); // passes, but foo is not mocked
    }
}

it will pass and I do not understand why. This behavior is pretty obscure and makes tests pass when they shouldn't.

NOTE: this only happens when methods does not return a value. It works as expected in the method return some value

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions