TrueFiEng / Waffle

Library for writing and testing smart contracts.
https://getwaffle.io
MIT License
964 stars 164 forks source link

Mocking method with bytes type #477

Open pbuda opened 3 years ago

pbuda commented 3 years ago

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?

wachulski commented 3 years ago

still failed.

Could you provide the error msg or more context?

wachulski commented 3 years ago

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

wachulski commented 3 years ago

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