Allow function to be passed to MockContract#mock.<contractFunction>.returns
#545
Labels
waffle-mock-contract
Anything related to the mocking package
If we were to allow an (optionally async) function to be passed to
MockContract#mock.<contractFunction>.returns
andMockContract#mock.<contractFunction>.withArgs(...).returns
, then we could mock any side-effects that calling that contract function would normally cause. My proposed signature would be:where
contract
is the mocked contract, and the returned (promise-resolved) value is passed as the contract function's mocked value.My use-case: I'm testing a contract that interacts with a Compound ERC20 (CERC20). When my contract calls
redeemUnderlying
on this CERC20, I have to separately update the mocked value ofbalanceOf
and also call the underlying mocked ERC20 to send tokens to my contract. It would be nice to be able to define these actions this way, as it wouldTo show an example of what this would look like (using Hardhat + Typescript):
I am able and willing to contribute to writing this feature if maintainers would be open to its inclusion.
The text was updated successfully, but these errors were encountered: