Waffle icon indicating copy to clipboard operation
Waffle copied to clipboard

mockContract doesn't seem to work

Open novaknole opened this issue 5 years ago • 1 comments

const [sender, receiver] = await provider.getWallets();
const mockContract = await deployMockContract(sender, abi);

Problem 1:

Before, I even mock return values for the mockContract, I want to call function as normal. FYI, abi is ERC20 contract. So I do this:

await mockContract.approve(address, 20);

This fails.

cannot estimate gas; transaction may fail or may require manual gas limit

If I first call this await mockContract.mock.approve.returns(false); and then call await mockContract.approve(address, 20);, it doesn't fail, but then the problem is that approve method wouldn't work. So the idea is that approve should work at first, then I should mock the method with returned value false.

Any idea ?

novaknole avatar Mar 02 '21 09:03 novaknole

You should only mock interfaces for contracts, not actual contracts. This way, it is more clear that before you can use a function, you must set a mocked behavior for that function.

I believe that's the intended behavior.

levelboy avatar Mar 26 '21 00:03 levelboy