You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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'
The text was updated successfully, but these errors were encountered:
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 :(
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:
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 returntrue
. 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'
The text was updated successfully, but these errors were encountered: