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

vm.expectCall doubles the number of registered calls #795

Open
2 tasks done
CodeSandwich opened this issue Dec 19, 2024 · 2 comments
Open
2 tasks done

vm.expectCall doubles the number of registered calls #795

CodeSandwich opened this issue Dec 19, 2024 · 2 comments
Labels
bug 🐛 Something isn't working p2 🟡 Indicates moderately high priority item

Comments

@CodeSandwich
Copy link
Contributor

CodeSandwich commented Dec 19, 2024

Component

Other (please describe)

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

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.0.2 (1781234 2024-12-19T00:26:29.308590729Z)

What command(s) is the bug in?

No response

Operating System

Linux

Describe the bug

vm.expectCall doubles the number of registered calls leading to failing tests. It's independent of the properties of the call like being view, non-view, transfer, returning data, or being called multiple times. Example:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;

import "forge-std/Test.sol";

contract Expected {
    uint256 public value;

    function setValue(uint256 newValue) public returns (uint256 oldValue) {
        oldValue = value;
        value = newValue;
    }

    receive()payable external{}
}

contract ExpectedTest is Test {
    function testExpectedTransfer() public {
        Expected expected = new Expected();
        vm.expectCall(address(expected), 3, "", 1);
        address(expected).call{value:3}("");
    }

    function testExpectedViewCall() public {
        Expected expected = new Expected();
        vm.expectCall(address(expected), abi.encodeCall(expected.value, ()), 1);
        expected.value();
    }

    function testExpectedCall() public {
        Expected expected = new Expected();
        vm.expectCall(address(expected), abi.encodeCall(expected.setValue, (3)), 1);
        expected.setValue(3);
    }

    function testExpectedViewCallTwice() public {
        Expected expected = new Expected();
        vm.expectCall(address(expected), abi.encodeCall(expected.value, ()), 2);
        expected.value();
        expected.value();
    }
}

These tests should all pass, but they fail with:

[FAIL: expected call to 0xF9E9ba9Ed9B96AB918c74B21dD0f1D5f2ac38a30 with data 0x552410770000000000000000000000000000000000000000000000000000000000000003 to be called 1 time, but was called 2 times] testExpectedCall() (gas: 1166895)
[FAIL: expected call to 0xF9E9ba9Ed9B96AB918c74B21dD0f1D5f2ac38a30 with data 0x, value 3 to be called 1 time, but was called 2 times] testExpectedTransfer() (gas: 1187789)
[FAIL: expected call to 0xF9E9ba9Ed9B96AB918c74B21dD0f1D5f2ac38a30 with data 0x3fa4f245 to be called 1 time, but was called 2 times] testExpectedViewCall() (gas: 1157125)
[FAIL: expected call to 0xF9E9ba9Ed9B96AB918c74B21dD0f1D5f2ac38a30 with data 0x3fa4f245 to be called 2 times, but was called 4 times] testExpectedViewCallTwice() (gas: 1267729)
@CodeSandwich CodeSandwich added bug 🐛 Something isn't working needs triage ♟️ Issue needs to be picked up or assigned labels Dec 19, 2024
@CodeSandwich
Copy link
Contributor Author

The behavior isn't consistent, some tests double the number of registered calls, others don't. They are very similar and I can't put my finger on the root cause of the issue.

@Jrigada
Copy link
Contributor

Jrigada commented Dec 26, 2024

Hello @CodeSandwich,

Thank you for bringing this to our attention. I have confirmed that the issue is occurring on my end as well; the process is being executed twice. I will discuss this with the team to address it. Currently, we are implementing changes to accommodate zkSync behavior using a strategy pattern, and this matter may be incorporated into that effort as well.

@Jrigada Jrigada added p2 🟡 Indicates moderately high priority item and removed needs triage ♟️ Issue needs to be picked up or assigned labels Dec 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working p2 🟡 Indicates moderately high priority item
Projects
None yet
Development

No branches or pull requests

2 participants