Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock success of calling another contract's function using .call(abi.encode(...)) #582

Open
AboldUSER opened this issue Oct 3, 2021 · 2 comments
Labels
waffle-mock-contract Anything related to the mocking package

Comments

@AboldUSER
Copy link

Setup:
waffle/ethers/hardhat

Issue:
I am testing a contract that has a function which calls another contract's function using abi.encodeWithSignature. Below is example code based on the contract I am testing:

(bool success, ) = address(otherContract).call(
      abi.encodeWithSignature("otherContractFunction(address,uint256)", msg.sender, amount)
    );

When testing, how can I mock otherContract to have the called function pass (i.e., return a bool success of true)? The called upon function in otherContract doesn't return anything, and I don't know how to mock a call(abi.encodeWithSignature(...)) to return true. The Waffle mock documentation doesn't really give insights into this either.

So far, if I mock the otherContract in testing with await otherContract.mock.otherContractFunction.returns(true), then I get the following error:
Error: types/values length mismatch (count={"types":0,"values":1}, value={"types":[],"values":[true]}, code=INVALID_ARGUMENT, version=abi/5.4.1)

If I mock the otherContract in testing with await otherContract.mock.otherContractFunction.returns(), then I get the following error:
Error: VM Exception while processing transaction: reverted with reason string 'Mock on the method is not initialized'

@mister36
Copy link

@AboldUSER did you ever solve this issue?

@rzadp rzadp added the waffle-mock-contract Anything related to the mocking package label Jul 29, 2022
@AboldUSER
Copy link
Author

I actually don't remember exactly which project or smart contract I was having this issue with, though I believe I ended up just using a interface to call the contract method and having the test pass :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waffle-mock-contract Anything related to the mocking package
Projects
None yet
Development

No branches or pull requests

3 participants