I'm trying to write unit tests in Foundry and I've quite enjoyed the ability to mock external calls using function mockCall(address where, uint256 value, bytes calldata data, bytes calldata retdata) external
.
However, I can't figure out if there's any way to mock an external call that returns two different results when gets called twice in a function (similar to sideEffect
in sinon).
Example:
function getDelta(address calculatorAddress) external returns (int256 delta) {
ICalculator calculator = ICalculator(calculatorAddress);
int256 preUpdateValue = calculator.getValue();
calculator.update();
int256 postUpdateValue = calculator.getValue();
delta = postUpdateValue - preUpdateValue;
}
}
If I use mockCall for calculator.getValue()
, it will return the same result for both calls and I'll get 0. Hence, I'd like to be able to mock this call such that it returns different results.