I'm trying to create unit tests for a token using Hardhat and run them locally. The token uses Uniswap to swap for ETH.
Before each unit test, I...
- Deploy
WETH
,UniswapV2Factory
, andUniswapV2Router02
. - Deploy my token
- The token's constructor calls
uniswapFactory.createPair(this, weth)
- The token's constructor calls
This all works properly and I'm able to run tests with my token.
However, one of my unit tests calls a function that ends up calling:
***Stack Trace***
UniswapV2Router02._swapSupportingFeeOnTransferTokens
UniswapV2Router02.swapExactTokensForEthSupportingFeeOnTransferTokens
https://github.com/Uniswap/v2-periphery/blob/master/contracts/UniswapV2Router02.sol#L321
When it gets to line 329
, it errors out with Transaction reverted: function call to a non-contract account
Reference:
Create Pair code:
https://github.com/Uniswap/v2-core/blob/master/contracts/UniswapV2Factory.sol#L23
I assume this means that the pair's address is not a contract that deployed locally.
What else do I need to do in order to get my pair to be a working contract?
I thought createPair()
would be enough.
Factory.createPair()
) is different than the pair address that gets created fromswapExactTokensForEthSupportingFeeOnTransferTokens
(which callsUniswapLibrary.pairFor()
)ethers.utils.keccak256(UniswapV2Pair.bytecode);
. If you want to add your comment as an answer, then I can mark it if you'd like.