Skip to content

Commit

Permalink
test: more progress on happyPath
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAustrian committed May 10, 2024
1 parent f4ad8d6 commit 1593613
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions test/unit/BPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,6 @@ contract BPool_Unit_SwapExactAmountIn is BasePoolTest, BMath {

struct SwapExactAmountIn_FuzzScenario {
uint256 tokenAmountIn;
uint256 minAmountOut;
uint256 tokenInBalance;
uint256 tokenInDenorm;
uint256 tokenOutBalance;
Expand Down Expand Up @@ -553,33 +552,46 @@ contract BPool_Unit_SwapExactAmountIn is BasePoolTest, BMath {
}

function _assumeHappyPath(SwapExactAmountIn_FuzzScenario memory _fuzz) internal view {
// weights
vm.assume(_fuzz.tokenInDenorm >= MIN_WEIGHT);
vm.assume(_fuzz.tokenInDenorm <= MAX_WEIGHT);
vm.assume(_fuzz.tokenOutDenorm >= MIN_WEIGHT);
vm.assume(_fuzz.tokenOutDenorm <= MAX_WEIGHT);

//
vm.assume(_fuzz.tokenInBalance >= MIN_BALANCE);
vm.assume(_fuzz.tokenOutBalance >= MIN_BALANCE);

vm.assume(_fuzz.tokenAmountIn > BONE);

// calcSpotPrice
vm.assume(_fuzz.tokenInBalance < type(uint256).max / BONE);
vm.assume(_fuzz.tokenOutBalance < type(uint256).max / BONE);

// MAX_IN_RATIO
vm.assume(_fuzz.tokenInBalance < type(uint256).max / MAX_IN_RATIO);
vm.assume(_fuzz.tokenAmountIn <= (_fuzz.tokenInBalance * MAX_IN_RATIO) / BONE);

// weights
vm.assume(_fuzz.tokenInDenorm >= MIN_WEIGHT);
vm.assume(_fuzz.tokenInDenorm <= MAX_WEIGHT);
vm.assume(_fuzz.tokenOutDenorm >= MIN_WEIGHT);
vm.assume(_fuzz.tokenOutDenorm <= MAX_WEIGHT);
// internal calculation for calcSpotPrice
uint _numer = (_fuzz.tokenInBalance * BONE) / _fuzz.tokenInDenorm;
uint _denom = (_fuzz.tokenOutBalance * BONE) / _fuzz.tokenOutDenorm;
uint _ratio = (_numer * BONE) / _denom;
uint _scale = (BONE * BONE) / (BONE - MIN_FEE);
vm.assume(_ratio < type(uint256).max / _scale);

// swap
uint256 _spotPriceBefore =
calcSpotPrice(_fuzz.tokenInBalance, _fuzz.tokenInDenorm, _fuzz.tokenOutDenorm, _fuzz.tokenOutDenorm, MIN_FEE);
uint256 _tokenAmountOut = calcOutGivenIn(
_fuzz.tokenInBalance,
_fuzz.tokenInDenorm,
_fuzz.tokenOutDenorm,
_fuzz.tokenOutBalance,
_fuzz.tokenOutDenorm,
_fuzz.tokenAmountIn,
MIN_FEE
);
vm.assume(_tokenAmountOut > 0);
vm.assume(_spotPriceBefore <= (_fuzz.tokenAmountIn * BONE) / _tokenAmountOut);
// vm.assume(_tokenAmountOut > BONE);
// vm.assume(_spotPriceBefore <= (_fuzz.tokenAmountIn * BONE) / _tokenAmountOut);
}

modifier happyPath(SwapExactAmountIn_FuzzScenario memory _fuzz) {
Expand All @@ -590,7 +602,8 @@ contract BPool_Unit_SwapExactAmountIn is BasePoolTest, BMath {

function test_HappyPath(SwapExactAmountIn_FuzzScenario memory _fuzz) public happyPath(_fuzz) {
uint256 _maxPrice = type(uint256).max;
bPool.swapExactAmountIn(tokenIn, _fuzz.tokenAmountIn, tokenOut, _fuzz.minAmountOut, _maxPrice);
uint _minAmountOut = 0;
bPool.swapExactAmountIn(tokenIn, _fuzz.tokenAmountIn, tokenOut, _minAmountOut, _maxPrice);
}

function test_Revert_NotBoundTokenIn() private view {}
Expand Down

0 comments on commit 1593613

Please sign in to comment.