defi-wonderland / smock

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

bug: Call count of function called internally in another function is not counted #113

Closed superical closed 2 years ago

superical commented 2 years ago

Describe the bug When a function is called internally by another function, the call count of that function called internally isn't reflected correctly.

Reproduction steps

Here's an example of a contract:

contract MyContract {

   function walk(uint speed) public { ... }

   function run() public {
      walk(20);
   }
}

Now, when I call the run() function and test if walk was called:

await myMockContract.run();

// Pass:
expect(myMockContract.run).to.have.been.calledOnce;

// Fail because the call count of walk is zero:
expect(myMockContract.walk).to.have.been.calledOnce;

The expect will fail because the call count of the walk function is 0. smock doesn't count the walk function which was called internally in run, but why doesn't it?

Expected behavior The call count of walk should have been 1 with the args 20. Shouldn't this be the expected behaviour?

Additional context Smock version 2.0.7

hickscorp commented 2 years ago

This is expected behaviour IMO. If you're mocking your Token contract, it has no internal implementation - that's what a mock should be.

wei3erHase commented 2 years ago

Agree with @hickscorp, i believe there's no function call to walk because it's called internally. We should think of a way of getting the internal calls and making expectations on them, i believe is very far reach from what smock actually touches tho. I'm closing the issue and adding the handling of internal variables to the list of possible features.