Waffle icon indicating copy to clipboard operation
Waffle copied to clipboard

Mocking method with bytes type

Open pbuda opened this issue 4 years ago • 3 comments

Hi, I'm trying to mock swap method on Uniswap V2 pair contract. The method has the following signature:

function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data);

I have no idea how to mock it properly, because whatever I input as the data parameter I always get a revert with error that method on mock has not been set up. I don't see anything in the docs about that.

I tried using this method as simply as

swap(0, 0, address(this), '')

in Solidity but mocking it with either of

await mockPair.mock.swap.withArgs(0, 0, myContract.address, '')
await mockPair.mock.swap.withArgs(0, 0, myContract.address, '0x')

still failed.

Is there a way to do this?

pbuda avatar Mar 24 '21 12:03 pbuda

still failed.

Could you provide the error msg or more context?

wachulski avatar Mar 25 '21 12:03 wachulski

For example see it in action: https://github.com/EthWorks/Waffle/compare/master...wachulski:issue/477/mocking-calldata-example

wachulski avatar Mar 25 '21 12:03 wachulski

Maybe you just need utils.toUtf8Bytes('') or your contract definitions do sth suspicious with addresses. I simplified my example and moved out addresses.

wachulski avatar Mar 25 '21 12:03 wachulski