Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (e807429 2023-05-04T00:03:45.171389475Z)
What command(s) is the bug in?
forge test
Operating System
Linux
Describe the bug
vm.expectCall is giving contradictory errors when used within a helper function and a loop.
To reproduce:
git clone git@github.com:ScopeLift/umbra-protocol.git
git checkout expect-call-issue
cd contracts-periphery/ && cp .env.example .env and fill in ETH_RPC_URL in .env
forge test --mc UniswapWithdrawHookTest
Relevant lines of codes are at 71-83 and 151-153.
In this case:
vm.expectCall( address(withdrawHook), abi.encodeWithSelector(withdrawHook.tokensWithdrawn.selector) );
When you run the test command at step 4. You'll see this error:
Failing tests:
Encountered 2 failing tests in test/UniswapWithdrawHook.fork.1.t.sol:UniswapWithdrawHookTest
[FAIL. Reason: Expected at least one call to 0x5991a2df15a8f6a256d3ec51e99254cd3fb576a9 with data 0x579073de, but got **none** Counterexample: calldata=0x3d93c91a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, args=[0, 0, 0, 0]] testFuzz_HookTest_withdrawTokenAndCall(uint256,uint256,uint256,uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: Expected at least one call to 0x5991a2df15a8f6a256d3ec51e99254cd3fb576a9 with data 0x579073de, but got **none** Counterexample: calldata=0xc410223f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, args=[0, 0, 0, 0]] testFuzz_HookTest_withdrawTokenAndCallOnBehalf(uint256,uint256,uint256,uint256) (runs: 0, μ: 0, ~: 0)
If you change the code to:
vm.expectCall( address(withdrawHook), abi.encodeWithSelector(withdrawHook.tokensWithdrawn.selector), **0** );
and then run the test, you'll see:
Failing tests:
Encountered 2 failing tests in test/UniswapWithdrawHook.fork.1.t.sol:UniswapWithdrawHookTest
[FAIL. Reason: Expected call to 0x5991a2df15a8f6a256d3ec51e99254cd3fb576a9 with data 0x579073de to be made 0 time(s), but was called 10 time(s) Counterexample: calldata=0x3d93c91a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, args=[0, 0, 0, 0]] testFuzz_HookTest_withdrawTokenAndCall(uint256,uint256,uint256,uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: Expected call to 0x5991a2df15a8f6a256d3ec51e99254cd3fb576a9 with data 0x579073de to be made 0 time(s), but was called 10 time(s) Counterexample: calldata=0xc410223f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, args=[0, 0, 0, 0]] testFuzz_HookTest_withdrawTokenAndCallOnBehalf(uint256,uint256,uint256,uint256) (runs: 0, μ: 0, ~: 0)
If you change the code to:
vm.expectCall( address(withdrawHook), abi.encodeWithSelector(withdrawHook.tokensWithdrawn.selector), **10** );
and then run the test, you'll see:
Failing tests:
Encountered 2 failing tests in test/UniswapWithdrawHook.fork.1.t.sol:UniswapWithdrawHookTest
[FAIL. Reason: Expected call to 0x5991a2df15a8f6a256d3ec51e99254cd3fb576a9 with data 0x579073de to be made 10 time(s), but was called 0 time(s) Counterexample: calldata=0x3d93c91a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, args=[0, 0, 0, 0]] testFuzz_HookTest_withdrawTokenAndCall(uint256,uint256,uint256,uint256) (runs: 0, μ: 0, ~: 0)
[FAIL. Reason: Expected call to 0x5991a2df15a8f6a256d3ec51e99254cd3fb576a9 with data 0x579073de to be made 10 time(s), but was called 0 time(s) Counterexample: calldata=0xc410223f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, args=[0, 0, 0, 0]] testFuzz_HookTest_withdrawTokenAndCallOnBehalf(uint256,uint256,uint256,uint256) (runs: 0, μ: 0, ~: 0)
The expected number of calls should actually be 1:
vm.expectCall( address(withdrawHook), abi.encodeWithSelector(withdrawHook.tokensWithdrawn.selector), **1**);
But this also fails with the error saying it was called 10 times.
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (e807429 2023-05-04T00:03:45.171389475Z)
What command(s) is the bug in?
forge test
Operating System
Linux
Describe the bug
vm.expectCallis giving contradictory errors when used within a helper function and a loop.To reproduce:
git clone git@github.com:ScopeLift/umbra-protocol.gitgit checkout expect-call-issuecd contracts-periphery/ && cp .env.example .envand fill inETH_RPC_URLin.envforge test --mc UniswapWithdrawHookTestRelevant lines of codes are at 71-83 and 151-153.
In this case:
vm.expectCall( address(withdrawHook), abi.encodeWithSelector(withdrawHook.tokensWithdrawn.selector) );When you run the test command at step 4. You'll see this error:
If you change the code to:
vm.expectCall( address(withdrawHook), abi.encodeWithSelector(withdrawHook.tokensWithdrawn.selector), **0** );and then run the test, you'll see:
If you change the code to:
vm.expectCall( address(withdrawHook), abi.encodeWithSelector(withdrawHook.tokensWithdrawn.selector), **10** );and then run the test, you'll see:
The expected number of calls should actually be 1:
vm.expectCall( address(withdrawHook), abi.encodeWithSelector(withdrawHook.tokensWithdrawn.selector), **1**);But this also fails with the error saying it was called 10 times.