-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
bug: mockCall
not working as expected
#432
Comments
Maybe the documentation was a bit confusing - |
Ah that makes sense. Changing However as a user I'd expect (and personally would like) the above usage to pass, even though we're jumping to |
Hmm, this is going to be pretty difficult. We can get the locations of different calls in the bytecode using I definitely agree that it makes sense, though. Just noting here for the future (I don't have much bandwidth currently):
I'm also not sure if some of these functions are inlined if they are internal(?) |
Very briefly skimming it looks like it would be a lot easier if we used revm, but I'm not sure what the drawbacks are |
We intend to switch over to Revm eventually, is the problem that hooking so deeply into sputnik can be hard, whereas revm's inspectors are cleaner? |
Yeah, it's pretty much impossible for us (as far as I can tell) to hook into the actual stepping of the EVM itself with Sputnik, but revm inspectors solve this by giving us full control |
Going to close this feature request, and we can always re-open if needed. IME I have not had the need to do this recently, so closing |
@mds1 Would you mind sharing how can one achieve stateless unit tests with this |
@avniculae Can you expand on what you’re trying to do? I don’t understand exactly what you’re looking for :) |
@mds1 Building on your example above, I was wondering how to best test the |
It depends on the specifics of your use case. Some ideas include:
|
Thanks @mds1, this is helpful! The |
Yep exactly, if the contract is one local to your project it's easy to make a patched version. If it's someone else's, e.g. uniswap, typically you'd clone their repo, patch the code, compile, and copy out the resulting bytecode into your project. I don't know of any examples offhand to link to, but if you search the foundry issues or telegram channels you might find some |
@avniculae We did something similar to fuzz the state of Liquidity Positions of Uniswap V3. Might help you as an example: Only for constants in the contract this is annoying, since you can't simply override them. |
FYI for anyone looking trying to use this, mocking pragma solidity ^0.8.13;
interface WithInner {
function inner() external view returns(uint256);
}
contract MyContract {
function inner() public view returns (uint256) {
return 1;
}
/// @dev returns real value, vm.mockCall does not work
function outer1() public view returns (uint256) {
return inner();
}
/// @dev returns vm.mockCall value
function outer2() public view returns (uint256) {
return this.inner();
}
/// @dev returns vm.mockCall value
function outer3() public view returns (uint256) {
return WithInner(address(this)).inner();
}
} |
Ending here after going over the expectCall foundry's doc and seeing this note:
While this issue doesn't seem to be specifically about |
The tests in
CheatCodes.sol
passed, however the test below fails. Tagging @onbjerg here since you implemented this feature originally in #403The text was updated successfully, but these errors were encountered: