Skip to content

Commit 717a00b

Browse files
committed
chore: add reserves assertions
1 parent 9d97da1 commit 717a00b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

test/e2e/UniswapTrade.t.sol

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ interface IUniswapV2Pair {
2525
function token0() external view returns (address);
2626
function mint(address) external;
2727
function swap(uint256, uint256, address, bytes calldata) external;
28+
function getReserves() external view returns (uint256, uint256);
2829
}
2930

3031
contract UniswapTradeTest is Helper(true) {
@@ -179,11 +180,16 @@ contract UniswapTradeTest is Helper(true) {
179180

180181
assertEq(wETH.balanceOf(trader2.addr), 0.5 ether, "weth bought not correct amount");
181182
assertEq(dai.balanceOf(trader2.addr), 300.3 ether - (uniswapDaiOutAmount + 0.3 ether));
182-
}
183183

184-
function _getCode(string memory artifactName) internal view returns (bytes memory) {
185-
string memory data =
186-
vm.readFile(string(abi.encodePacked("node_modules/@uniswap/v2-core/build/", artifactName, ".json")));
187-
return vm.parseJsonBytes(data, ".bytecode");
184+
uint256 finalWethReserve;
185+
uint256 finalDaiReserve;
186+
187+
{
188+
(uint256 token0Reserve, uint256 token1Reserve) = uniswapPair.getReserves();
189+
(finalWethReserve, finalDaiReserve) =
190+
isWethToken0 ? (token0Reserve, token1Reserve) : (token1Reserve, token0Reserve);
191+
}
192+
assertEq(finalWethReserve, wethReserve + uniswapWethInAmount, "weth reserve not as expected");
193+
assertEq(finalDaiReserve, daiReserve - uniswapDaiOutAmount, "dai reserve not as expected");
188194
}
189195
}

0 commit comments

Comments
 (0)