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

Returning array of values #24

Open
Juan-cc opened this issue Aug 20, 2020 · 2 comments
Open

Returning array of values #24

Juan-cc opened this issue Aug 20, 2020 · 2 comments

Comments

@Juan-cc
Copy link

Juan-cc commented Aug 20, 2020

Hi, I am trying to simulate a call to UniswapV2Router02.swapExactETHForTokens() (link)

That method returns a uint[], so I tried mocking that using: abi.rawEncode([ "uint[]" ], [ [1] ])

Here is the complete method mock definition:

await uniswapV2Router02.givenMethodReturn(
      uniswapEncorder.encodeRouterETHForTokens(),
      abi.rawEncode([ "uint[]" ], [ [1] ])
    );

Is it possible to encode an array of values?

Thanks!

@fleupold
Copy link
Contributor

Yes, this is possible. The way to do it should be:

const method = await mockedUniswap.contract.methods.swapExactETHForTokens(0, [], 0x00...00, 0).encodeABI();
const result = web3.eth.abi.encodeParameter("uint[]", [1,2,3])
await mock.givenMethonReturn(method, result)

@Juan-cc
Copy link
Author

Juan-cc commented Aug 20, 2020

It worked! Thanks @fleupold

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants