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 unexpected behavior #4879

Closed
2 tasks done
garyghayrat opened this issue May 4, 2023 · 0 comments · Fixed by #4912
Closed
2 tasks done

vm.expectCall unexpected behavior #4879

garyghayrat opened this issue May 4, 2023 · 0 comments · Fixed by #4912
Assignees
Labels
A-cheatcodes Area: cheatcodes C-forge Command: forge T-bug Type: bug

Comments

@garyghayrat
Copy link

Component

Forge

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

  • Foundry
  • Foundryup

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:

  1. git clone git@github.com:ScopeLift/umbra-protocol.git
  2. git checkout expect-call-issue
  3. cd contracts-periphery/ && cp .env.example .env and fill in ETH_RPC_URL in .env
  4. 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.

@garyghayrat garyghayrat added the T-bug Type: bug label May 4, 2023
@gakonst gakonst added this to Foundry May 4, 2023
@github-project-automation github-project-automation bot moved this to Todo in Foundry May 4, 2023
@mds1 mds1 added C-forge Command: forge A-cheatcodes Area: cheatcodes labels May 4, 2023
@Evalir Evalir self-assigned this May 5, 2023
@github-project-automation github-project-automation bot moved this from Todo to Done in Foundry May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cheatcodes Area: cheatcodes C-forge Command: forge T-bug Type: bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants