Skip to content

Commit

Permalink
test: finish happyPath for joinPool
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAustrian committed May 8, 2024
1 parent bfbb34b commit 8d467dd
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions test/unit/BPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import {LibString} from 'solmate/utils/LibString.sol';
abstract contract Base is Test, BConst {
using LibString for *;

uint256 public constant TOKENS_AMOUNT = 5;

BPool public bPool;
address[8] public tokens;
address[TOKENS_AMOUNT] public tokens;

function setUp() public {
bPool = new BPool();
Expand Down Expand Up @@ -268,10 +270,10 @@ contract BPool_Unit_GetSpotPriceSansFee is Base {
}

contract BPool_Unit_JoinPool is Base {

struct FuzzScenario {
uint256 poolAmountOut;
uint256[8] balance;
uint256 initPoolSupply;
uint256[TOKENS_AMOUNT] balance;
}

function _setValues(FuzzScenario memory _fuzz) internal {
Expand Down Expand Up @@ -305,22 +307,21 @@ contract BPool_Unit_JoinPool is Base {
// Set finalize
vm.store(address(bPool), bytes32(uint256(8)), bytes32(uint256(1)));
// Set totalSupply
vm.store(address(bPool), bytes32(uint256(2)), bytes32(INIT_POOL_SUPPLY));
vm.store(address(bPool), bytes32(uint256(2)), bytes32(_fuzz.initPoolSupply));
}

function _assumeHappyPath(FuzzScenario memory _fuzz) internal view {
vm.assume(_fuzz.poolAmountOut > INIT_POOL_SUPPLY);
vm.assume(_fuzz.initPoolSupply >= INIT_POOL_SUPPLY);
vm.assume(_fuzz.poolAmountOut >= _fuzz.initPoolSupply);
vm.assume(_fuzz.poolAmountOut < type(uint256).max / BONE);

uint _poolAmountOutTimesBONE = _fuzz.poolAmountOut * BONE; // bdiv uses '* BONE'

uint _ratio = _poolAmountOutTimesBONE / INIT_POOL_SUPPLY;
uint256 _poolAmountOutTimesBONE = _fuzz.poolAmountOut * BONE; // bdiv uses '* BONE'
uint256 _ratio = _poolAmountOutTimesBONE / _fuzz.initPoolSupply;
uint _maxTokenAmountIn = type(uint256).max / _ratio;

Check warning on line 320 in test/unit/BPool.t.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

prefer use of explicit type uint256 over uint

for (uint256 i = 0; i < _fuzz.balance.length; i++) {
vm.assume(_fuzz.balance[i] > MIN_BALANCE);

uint _maxTokenAmountIn = type(uint256).max / _ratio;
vm.assume(_fuzz.balance[i] < _maxTokenAmountIn); // L272
vm.assume(_fuzz.balance[i] >= MIN_BALANCE);
vm.assume(_fuzz.balance[i] <= _maxTokenAmountIn); // L272
}
}

Expand All @@ -332,7 +333,9 @@ contract BPool_Unit_JoinPool is Base {

function test_HappyPath(FuzzScenario memory _fuzz) public happyPath(_fuzz) {
uint256[] memory maxAmountsIn = new uint256[](tokens.length);
for (uint256 i = 0; i < tokens.length; i++) { maxAmountsIn[i] = type(uint256).max; } // Using max possible amounts
for (uint256 i = 0; i < tokens.length; i++) {
maxAmountsIn[i] = type(uint256).max;
} // Using max possible amounts

bPool.joinPool(_fuzz.poolAmountOut, maxAmountsIn);
}
Expand Down

0 comments on commit 8d467dd

Please sign in to comment.