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

Faked function of mocked contract not working when called by other function #175

Open
sebasgoldberg opened this issue Nov 21, 2022 · 2 comments

Comments

@sebasgoldberg
Copy link

Describe the bug
Faked function of mocked contract not working when called by other function

Reproduction steps

Let suppose we have a contract C, which has two functions, F1 and F2, where F1 returns the value of the passed parameter, and F2 calls to F1 and returns the corresponding result:

contract C{
  function F1(uint 256 x) public pure returns (uint256 r){
    r = x;
  }
  function F2(uint 256 x) public pure returns (uint256 r){
    r = F1(x);
  }
}

Then we create a mocked instance cM of contract C, and we set F1 to return always 0:

const C = await smock.mock('C');
const cM= await C.deploy();
cM.F1.returns(0)

Then if we call function F2 with any x value, it should return 0:

assert(await cm.F2(10)).eq(0)

But the test above fails and it is returned 10 instead of 0.

Note that the following works as expected:

assert(await cm.F1(10)).eq(0)

Expected behavior
In the explained scenario above: the call to the function F2 with any value as a parameter, should return 0.

Screenshots
NA

System Specs:

  • OS: Ubuntu 20.04
  • Package Version (or commit hash): 2.2.0

Additional context
NA

@nstylo
Copy link

nstylo commented Jun 12, 2023

I am facing the same issue, can we expect a fix? This has been open for a long time now.

@okwme
Copy link

okwme commented Jun 17, 2024

This is the primary reason I'd use mocks, really important feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants