Skip to content

Commit

Permalink
test: use fullMulDiv when performing verification operations
Browse files Browse the repository at this point in the history
  • Loading branch information
xenide committed Jun 16, 2024
1 parent 2dd543e commit b74ab92
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
14 changes: 8 additions & 6 deletions test/large/ReservoirPriceOracleLarge.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ pragma solidity ^0.8.0;
import {
ReservoirPriceOracleTest,
EnumerableSetLib,
FixedPointMathLib,
MintableERC20,
ReservoirPair,
IERC20
} from "test/unit/ReservoirPriceOracle.t.sol";

contract ReservoirPriceOracleLargeTest is ReservoirPriceOracleTest {
using EnumerableSetLib for EnumerableSetLib.AddressSet;
using FixedPointMathLib for uint256;

function testGetQuote_RandomizeAllParam_3HopRoute(
uint256 aPrice1,
Expand Down Expand Up @@ -97,14 +99,14 @@ contract ReservoirPriceOracleLargeTest is ReservoirPriceOracleTest {

// assert
uint256 lExpectedAmtBOut = lTokenA < lTokenB
? lAmtIn * 10 ** lTokenADecimal * lPrice1 * 10 ** lTokenBDecimal / 10 ** lTokenADecimal / WAD
: lAmtIn * 10 ** lTokenADecimal * WAD * 10 ** lTokenBDecimal / lPrice1 / 10 ** lTokenADecimal;
? (lAmtIn * 10 ** lTokenADecimal).fullMulDiv(lPrice1 * 10 ** lTokenBDecimal, 10 ** lTokenADecimal * WAD)
: (lAmtIn * 10 ** lTokenADecimal).fullMulDiv(WAD * 10 ** lTokenBDecimal, lPrice1 * 10 ** lTokenADecimal);
uint256 lExpectedAmtCOut = lTokenB < lTokenC
? lExpectedAmtBOut * lPrice2 * 10 ** lTokenCDecimal / 10 ** lTokenBDecimal / WAD
: lExpectedAmtBOut * WAD * 10 ** lTokenCDecimal / lPrice2 / 10 ** lTokenBDecimal;
? lExpectedAmtBOut.fullMulDiv(lPrice2 * 10 ** lTokenCDecimal, 10 ** lTokenBDecimal * WAD)
: lExpectedAmtBOut.fullMulDiv(WAD * 10 ** lTokenCDecimal, lPrice2 * 10 ** lTokenBDecimal);
uint256 lExpectedAmtDOut = lTokenC < lTokenD
? lExpectedAmtCOut * lPrice3 * 10 ** lTokenDDecimal / 10 ** lTokenCDecimal / WAD
: lExpectedAmtCOut * WAD * 10 ** lTokenDDecimal / lPrice3 / 10 ** lTokenCDecimal;
? lExpectedAmtCOut.fullMulDiv(lPrice3 * 10 ** lTokenDDecimal, 10 ** lTokenCDecimal * WAD)
: lExpectedAmtCOut.fullMulDiv(WAD * 10 ** lTokenDDecimal, lPrice3 * 10 ** lTokenCDecimal);

assertEq(lAmtDOut, lExpectedAmtDOut);
}
Expand Down
14 changes: 8 additions & 6 deletions test/unit/ReservoirPriceOracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BaseTest, console2, ReservoirPair, MintableERC20 } from "test/__fixture
import { Utils } from "src/libraries/Utils.sol";
import {
Buffer,
FixedPointMathLib,
PriceType,
OracleErrors,
OracleLatestQuery,
Expand All @@ -27,6 +28,7 @@ contract ReservoirPriceOracleTest is BaseTest {
using FlagsLib for *;
using Bytes32Lib for *;
using EnumerableSetLib for EnumerableSetLib.AddressSet;
using FixedPointMathLib for uint256;

event DesignatePair(address token0, address token1, ReservoirPair pair);
event Oracle(address newOracle);
Expand Down Expand Up @@ -282,8 +284,8 @@ contract ReservoirPriceOracleTest is BaseTest {

// assert
uint256 lExpectedAmt = lTokenA < lTokenB
? lAmtIn * 10 ** lTokenADecimal * lPrice * 10 ** lTokenBDecimal / 10 ** lTokenADecimal / WAD
: lAmtIn * 10 ** lTokenADecimal * WAD * 10 ** lTokenBDecimal / lPrice / 10 ** lTokenADecimal;
? (lAmtIn * 10 ** lTokenADecimal).fullMulDiv(lPrice * 10 ** lTokenBDecimal, 10 ** lTokenADecimal * WAD)
: (lAmtIn * 10 ** lTokenADecimal).fullMulDiv(WAD * 10 ** lTokenBDecimal, lPrice * 10 ** lTokenADecimal);

assertEq(lAmtBOut, lExpectedAmt);
}
Expand Down Expand Up @@ -349,11 +351,11 @@ contract ReservoirPriceOracleTest is BaseTest {

// assert
uint256 lExpectedAmtBOut = lTokenA < lTokenB
? lAmtIn * 10 ** lTokenADecimal * lPrice1 * 10 ** lTokenBDecimal / 10 ** lTokenADecimal / WAD
: lAmtIn * 10 ** lTokenADecimal * WAD * 10 ** lTokenBDecimal / lPrice1 / 10 ** lTokenADecimal;
? (lAmtIn * 10 ** lTokenADecimal).fullMulDiv(lPrice1 * 10 ** lTokenBDecimal, 10 ** lTokenADecimal * WAD)
: (lAmtIn * 10 ** lTokenADecimal).fullMulDiv(WAD * 10 ** lTokenBDecimal, lPrice1 * 10 ** lTokenADecimal);
uint256 lExpectedAmtCOut = lTokenB < lTokenC
? lExpectedAmtBOut * lPrice2 * 10 ** lTokenCDecimal / 10 ** lTokenBDecimal / WAD
: lExpectedAmtBOut * WAD * 10 ** lTokenCDecimal / lPrice2 / 10 ** lTokenBDecimal;
? (lExpectedAmtBOut).fullMulDiv(lPrice2 * 10 ** lTokenCDecimal, 10 ** lTokenBDecimal * WAD)
: (lExpectedAmtBOut).fullMulDiv(WAD * 10 ** lTokenCDecimal, lPrice2 * 10 ** lTokenBDecimal);

assertEq(lAmtCOut, lExpectedAmtCOut);
}
Expand Down

0 comments on commit b74ab92

Please sign in to comment.