hifi-finance/hifi

[flash-swap] Increase test coverage by testing both token orderings

PaulRBerg opened this issue · 0 comments

@scorpion9979's #39 made the HifiFlashSwapUniswapV2 contract more general purpose, but it came at a cost of reducing test coverage.

Capture d’écran 2021-09-15 à 20 37 19

Prior to the PR, we had a GodModeUniswapV2Pair contract that we were deploying via waffle.deployContract. Now we're using the original UniswapV2Pair contracts and we're deploying them via UniswapV2Factory. This makes it hard to know the order of the two pool tokens in advance (read about how ordering works here).

Two potential solutions, ordered by how good they would be:

  1. Use the hardhat_setCode JSON-RPC method to deploy the tokens at known addresses.
  2. Run a while loop and make new GodModeErc20 deployments until a new token ordering is found.

The 1st solution would be ideal, but hardhat_setCode has bugs: NomicFoundation/hardhat#1883. The 2nd is not nice because it involves non-determinism.