defi-wonderland / smock

The Solidity mocking library
MIT License
319 stars 40 forks source link

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

Open sebasgoldberg opened 1 year ago

sebasgoldberg commented 1 year ago

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:

Additional context NA

nstylo commented 1 year ago

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

okwme commented 3 months ago

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