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