Skip to content

Commit

Permalink
test: improving unit tests assumptions (#52)
Browse files Browse the repository at this point in the history
* test: replacing some assumptions for bounds

* fix: failing test

* test: optimize BPool_Unit_SwapExactAmountIn

* test: add more improvements

* test: create helper to test reentrancy

* test: add small improvements

* test: add assumeNotForgeAddress

* test: move helper functions to Utils

* test: optimize assumeHappyPath for specific edge cases

* chore: empty commit

* fix: exitswap max weight bounds

* feat: removing max fron fuzzed structs

* feat: rm maxAmounts from join test

* feat: removing exitpool fuzzed limits

* fix: final tweaks

---------

Co-authored-by: 0xAustrian <[email protected]>
  • Loading branch information
wei3erHase and 0xAustrian authored Jun 4, 2024
1 parent 6c85298 commit 3a6c086
Show file tree
Hide file tree
Showing 3 changed files with 344 additions and 530 deletions.
15 changes: 10 additions & 5 deletions test/unit/BFactory.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ contract BFactory_Unit_NewBPool is Base {
* @notice Test that event is emitted
*/
function test_Emit_Log(address _randomCaller) public {
vm.assume(_randomCaller != VM_ADDRESS);
assumeNotForgeAddress(_randomCaller);

vm.expectEmit();
address _expectedPoolAddress = vm.computeCreateAddress(address(bFactory), 1);
emit BFactory.LOG_NEW_POOL(_randomCaller, _expectedPoolAddress);
Expand All @@ -69,7 +70,8 @@ contract BFactory_Unit_NewBPool is Base {
* @notice Test that msg.sender is set as the controller
*/
function test_Set_Controller(address _randomCaller) public {
vm.assume(_randomCaller != VM_ADDRESS);
assumeNotForgeAddress(_randomCaller);

vm.prank(_randomCaller);
BPool _pool = bFactory.newBPool();
assertEq(_randomCaller, _pool.getController());
Expand Down Expand Up @@ -142,7 +144,8 @@ contract BFactory_Unit_Collect is Base {
* @notice Test that LP token `balanceOf` function is called
*/
function test_Call_BalanceOf(address _lpToken, uint256 _toCollect) public {
vm.assume(_lpToken != address(VM_ADDRESS));
assumeNotForgeAddress(_lpToken);

vm.mockCall(_lpToken, abi.encodeWithSelector(IERC20.balanceOf.selector, address(bFactory)), abi.encode(_toCollect));
vm.mockCall(_lpToken, abi.encodeWithSelector(IERC20.transfer.selector, owner, _toCollect), abi.encode(true));

Expand All @@ -155,7 +158,8 @@ contract BFactory_Unit_Collect is Base {
* @notice Test that LP token `transfer` function is called
*/
function test_Call_Transfer(address _lpToken, uint256 _toCollect) public {
vm.assume(_lpToken != address(VM_ADDRESS));
assumeNotForgeAddress(_lpToken);

vm.mockCall(_lpToken, abi.encodeWithSelector(IERC20.balanceOf.selector, address(bFactory)), abi.encode(_toCollect));
vm.mockCall(_lpToken, abi.encodeWithSelector(IERC20.transfer.selector, owner, _toCollect), abi.encode(true));

Expand All @@ -168,7 +172,8 @@ contract BFactory_Unit_Collect is Base {
* @notice Test that the function fail if the transfer failed
*/
function test_Revert_TransferFailed(address _lpToken, uint256 _toCollect) public {
vm.assume(_lpToken != address(VM_ADDRESS));
assumeNotForgeAddress(_lpToken);

vm.mockCall(_lpToken, abi.encodeWithSelector(IERC20.balanceOf.selector, address(bFactory)), abi.encode(_toCollect));
vm.mockCall(_lpToken, abi.encodeWithSelector(IERC20.transfer.selector, owner, _toCollect), abi.encode(false));

Expand Down
Loading

0 comments on commit 3a6c086

Please sign in to comment.