You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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: UNLICENSEDpragma solidity^0.8.20;
import"forge-std/Test.sol";
contractExpected {
uint256public value;
function setValue(uint256newValue) publicreturns (uint256oldValue) {
oldValue = value;
value = newValue;
}
receive()payableexternal{}
}
contractExpectedTestisTest {
function testExpectedTransfer() public {
Expected expected =newExpected();
vm.expectCall(address(expected), 3, "", 1);
address(expected).call{value:3}("");
}
function testExpectedViewCall() public {
Expected expected =newExpected();
vm.expectCall(address(expected), abi.encodeCall(expected.value, ()), 1);
expected.value();
}
function testExpectedCall() public {
Expected expected =newExpected();
vm.expectCall(address(expected), abi.encodeCall(expected.setValue, (3)), 1);
expected.setValue(3);
}
function testExpectedViewCallTwice() public {
Expected expected =newExpected();
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)
The text was updated successfully, but these errors were encountered:
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.
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.
Component
Other (please describe)
Have you ensured that all of these are up to date?
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:These tests should all pass, but they fail with:
The text was updated successfully, but these errors were encountered: