Skip to content

Commit

Permalink
test: adding e2e extremeCase and improving boundries
Browse files Browse the repository at this point in the history
  • Loading branch information
wei3erHase committed Jul 26, 2024
1 parent 05f4488 commit e39d8f4
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 6 deletions.
55 changes: 55 additions & 0 deletions test/integration/BPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,61 @@ abstract contract BPoolIntegrationTest is Test, GasSnapshot {
whitnessPool.finalize();
}

function test_extremeCase() public virtual {
uint256 _DAI_WEIGHT = 21095347289582322017;

Check warning on line 117 in test/integration/BPool.t.sol

View workflow job for this annotation

GitHub Actions / Static Analysis

Variable name must be in mixedCase
uint256 _WETH_WEIGHT = 14053292305279328903;

Check warning on line 118 in test/integration/BPool.t.sol

View workflow job for this annotation

GitHub Actions / Static Analysis

Variable name must be in mixedCase
uint256 _DAI_BALANCE = 1000000000000000000;

Check warning on line 119 in test/integration/BPool.t.sol

View workflow job for this annotation

GitHub Actions / Static Analysis

Variable name must be in mixedCase
uint256 _WETH_BALANCE = 839390325460697805479509969833437577;

Check warning on line 120 in test/integration/BPool.t.sol

View workflow job for this annotation

GitHub Actions / Static Analysis

Variable name must be in mixedCase
uint256 _DAI_AMOUNT_OUT = 1000000000000000000;

Check warning on line 121 in test/integration/BPool.t.sol

View workflow job for this annotation

GitHub Actions / Static Analysis

Variable name must be in mixedCase
uint256 _FEE = 1e18 / 10 ** 6;

Check warning on line 122 in test/integration/BPool.t.sol

View workflow job for this annotation

GitHub Actions / Static Analysis

Variable name must be in mixedCase
uint256 _WHITNESS_FEE = 0.999999e18;

Check warning on line 123 in test/integration/BPool.t.sol

View workflow job for this annotation

GitHub Actions / Static Analysis

Variable name must be in mixedCase

vm.startPrank(lp);
pool = factory.newBPool();
whitnessPool = factory.newBPool();

deal(address(dai), lp, type(uint248).max);
deal(address(weth), lp, type(uint248).max);

deal(address(dai), swapper.addr, type(uint248).max);
deal(address(weth), swapperInverse.addr, type(uint248).max);

dai.approve(address(pool), type(uint256).max);
weth.approve(address(pool), type(uint256).max);

pool.bind(address(dai), _DAI_BALANCE, _DAI_WEIGHT);
pool.bind(address(weth), _WETH_BALANCE, _WETH_WEIGHT);

dai.approve(address(whitnessPool), type(uint256).max);
weth.approve(address(whitnessPool), type(uint256).max);

whitnessPool.bind(address(dai), _DAI_BALANCE, _DAI_WEIGHT);
whitnessPool.bind(address(weth), _WETH_BALANCE, _WETH_WEIGHT);

// set swap fee
// NOTE: original pool keeps min swap fee
pool.setSwapFee(_FEE);
whitnessPool.setSwapFee(_WHITNESS_FEE);

// finalize
pool.finalize();
whitnessPool.finalize();


vm.startPrank(swapper.addr);
dai.approve(address(pool), type(uint256).max);
dai.approve(address(whitnessPool), type(uint256).max);

(uint256 amountIn,) =
pool.swapExactAmountOut(address(dai), type(uint256).max, address(weth), _DAI_AMOUNT_OUT, type(uint256).max);

// NOTE: fails with BPool_TokenAmountInAboveMaxRatio()
uint256 whitnessBPT = whitnessPool.joinswapExternAmountIn(address(dai), amountIn, 0);
uint256 whitnessAmountOut = whitnessPool.exitswapPoolAmountIn(address(weth), whitnessBPT, 0);

assertGt(_DAI_AMOUNT_OUT, whitnessAmountOut);
}

function testIndirectSwap_ExactIn() public {
// checks that pool.swapExactAmountIn >= whitnesPool.joinswapExternAmountIn + whitnesPool.exitswapPoolAmountIn

Expand Down
12 changes: 6 additions & 6 deletions test/invariants/fuzz/BMath.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ contract FuzzBMath is EchidnaTest {
tokenWeightOut = clamp(tokenWeightOut, MIN_WEIGHT, MAX_TOTAL_WEIGHT - tokenWeightIn);
totalWeight = clamp(totalWeight, tokenWeightIn + tokenWeightOut, MAX_TOTAL_WEIGHT);
totalWeight = tokenWeightIn + tokenWeightOut;
tokenBalanceIn = clamp(tokenBalanceIn, BONE, type(uint256).max);
tokenBalanceOut = clamp(tokenBalanceOut, BONE, type(uint256).max);
tokenAmountIn = clamp(tokenAmountIn, BONE, type(uint256).max);
tokenBalanceIn = clamp(tokenBalanceIn, 1e6, type(uint256).max);
tokenBalanceOut = clamp(tokenBalanceOut, 1e6, type(uint256).max);
tokenAmountIn = clamp(tokenAmountIn, 1, type(uint256).max);
poolSupply = clamp(poolSupply, 100 * BONE, type(uint256).max);
swapFee = clamp(swapFee, MIN_FEE, MAX_FEE);

Expand Down Expand Up @@ -210,10 +210,10 @@ contract FuzzBMath is EchidnaTest {
tokenWeightOut = clamp(tokenWeightOut, MIN_WEIGHT, MAX_TOTAL_WEIGHT - tokenWeightIn);
totalWeight = clamp(totalWeight, tokenWeightIn + tokenWeightOut, MAX_TOTAL_WEIGHT);
totalWeight = tokenWeightIn + tokenWeightOut;
tokenBalanceIn = clamp(tokenBalanceIn, BONE, type(uint256).max);
tokenBalanceOut = clamp(tokenBalanceOut, BONE, type(uint256).max);
tokenBalanceIn = clamp(tokenBalanceIn, 1e6, type(uint256).max);
tokenBalanceOut = clamp(tokenBalanceOut, 1e6, type(uint256).max);
poolSupply = clamp(poolSupply, 100 * BONE, type(uint256).max);
tokenAmountOut = clamp(tokenAmountOut, BONE, type(uint256).max);
tokenAmountOut = clamp(tokenAmountOut, 1, type(uint256).max);
swapFee = clamp(swapFee, MIN_FEE, MAX_FEE);

emit Log('tokenWeightIn', tokenWeightIn);
Expand Down

0 comments on commit e39d8f4

Please sign in to comment.