Fix some assertions in integration test
The foundation is: marginal price > executed price > price after swap. And this check is verified for multiple amounts
This commit is contained in:
@@ -83,6 +83,8 @@ contract AdapterTest is Test, ISwapAdapterTypes {
|
|||||||
console2.log("TEST: Testing behavior for price at 0");
|
console2.log("TEST: Testing behavior for price at 0");
|
||||||
assertGt(prices[0].numerator, 0, "Nominator shouldn't be 0");
|
assertGt(prices[0].numerator, 0, "Nominator shouldn't be 0");
|
||||||
assertGt(prices[0].denominator, 0, "Denominator shouldn't be 0");
|
assertGt(prices[0].denominator, 0, "Denominator shouldn't be 0");
|
||||||
|
uint256 priceAtZero = fractionToInt(prices[0]);
|
||||||
|
console2.log("TEST: Price at 0: %d", priceAtZero);
|
||||||
|
|
||||||
Trade memory trade;
|
Trade memory trade;
|
||||||
deal(tokenIn, address(this), 5 * amounts[amounts.length - 1]);
|
deal(tokenIn, address(this), 5 * amounts[amounts.length - 1]);
|
||||||
@@ -104,14 +106,14 @@ contract AdapterTest is Test, ISwapAdapterTypes {
|
|||||||
uint256 executedPrice =
|
uint256 executedPrice =
|
||||||
trade.calculatedAmount * pricePrecision / amounts[j];
|
trade.calculatedAmount * pricePrecision / amounts[j];
|
||||||
uint256 priceAfterSwap = fractionToInt(trade.price);
|
uint256 priceAfterSwap = fractionToInt(trade.price);
|
||||||
console2.log("TEST: - Pool price: %d", priceAtAmount);
|
|
||||||
console2.log("TEST: - Executed price: %d", executedPrice);
|
console2.log("TEST: - Executed price: %d", executedPrice);
|
||||||
|
console2.log("TEST: - Price at amount: %d", priceAtAmount);
|
||||||
console2.log("TEST: - Price after swap: %d", priceAfterSwap);
|
console2.log("TEST: - Price after swap: %d", priceAfterSwap);
|
||||||
|
|
||||||
if (hasPriceImpact) {
|
if (hasPriceImpact) {
|
||||||
assertGe(
|
assertGe(
|
||||||
priceAtAmount,
|
|
||||||
executedPrice,
|
executedPrice,
|
||||||
|
priceAtAmount,
|
||||||
"Price should be greated than executed price."
|
"Price should be greated than executed price."
|
||||||
);
|
);
|
||||||
assertGt(
|
assertGt(
|
||||||
@@ -120,24 +122,24 @@ contract AdapterTest is Test, ISwapAdapterTypes {
|
|||||||
"Executed price should be greater than price after swap."
|
"Executed price should be greater than price after swap."
|
||||||
);
|
);
|
||||||
assertGt(
|
assertGt(
|
||||||
priceAtAmount,
|
priceAtZero,
|
||||||
priceAfterSwap,
|
executedPrice,
|
||||||
"Price should be greated than price after swap."
|
"Price should be greated than price after swap."
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
assertGe(
|
assertGe(
|
||||||
priceAtAmount,
|
priceAtZero,
|
||||||
executedPrice,
|
|
||||||
"Price should be greater or equal to executed price."
|
|
||||||
);
|
|
||||||
assertGe(
|
|
||||||
executedPrice,
|
|
||||||
priceAfterSwap,
|
priceAfterSwap,
|
||||||
"Executed price should be or equal to price after swap."
|
"Executed price should be or equal to price after swap."
|
||||||
);
|
);
|
||||||
assertGe(
|
assertGe(
|
||||||
|
priceAtZero,
|
||||||
priceAtAmount,
|
priceAtAmount,
|
||||||
priceAfterSwap,
|
"Executed price should be or equal to price after swap."
|
||||||
|
);
|
||||||
|
assertGe(
|
||||||
|
priceAtZero,
|
||||||
|
executedPrice,
|
||||||
"Price should be or equal to price after swap."
|
"Price should be or equal to price after swap."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user