Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding btt tests for bPool setters #166

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions test/unit/BPool/BPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {MockBPool} from 'test/smock/MockBPool.sol';

contract BPool is BPoolBase {
address controller = makeAddr('controller');
address randomCaller = makeAddr('random caller');
address unknownToken = makeAddr('unknown token');
uint256 swapFee = 0.1e18;

Expand Down Expand Up @@ -38,6 +39,95 @@ contract BPool is BPoolBase {
assertEq(_newBPool.call__finalized(), false);
}

function test_SetSwapFeeRevertWhen_ReentrancyLockIsSet() external {
bPool.call__setLock(_MUTEX_TAKEN);
// it should revert
vm.expectRevert(IBPool.BPool_Reentrancy.selector);
bPool.setSwapFee(0);
}

function test_SetSwapFeeRevertWhen_CallerIsNotController() external {
vm.prank(randomCaller);
// it should revert
vm.expectRevert(IBPool.BPool_CallerIsNotController.selector);
bPool.setSwapFee(0);
}

function test_SetSwapFeeRevertWhen_PoolIsFinalized() external {
vm.prank(controller);
// it should revert
vm.expectRevert(IBPool.BPool_PoolIsFinalized.selector);
bPool.setSwapFee(0);
}

function test_SetSwapFeeRevertWhen_SwapFeeIsBelowMIN_FEE() external {
bPool.set__finalized(false);
vm.prank(controller);
// it should revert
vm.expectRevert(IBPool.BPool_FeeBelowMinimum.selector);
bPool.setSwapFee(MIN_FEE - 1);
}

function test_SetSwapFeeRevertWhen_SwapFeeIsAboveMAX_FEE() external {
bPool.set__finalized(false);
vm.prank(controller);
// it should revert
vm.expectRevert(IBPool.BPool_FeeAboveMaximum.selector);
bPool.setSwapFee(MAX_FEE + 1);
}

function test_SetSwapFeeWhenPreconditionsAreMet(uint256 _swapFee) external {
bPool.set__finalized(false);
vm.prank(controller);
_swapFee = bound(_swapFee, MIN_FEE, MAX_FEE);

// it emits LOG_CALL event
vm.expectEmit();
bytes memory _data = abi.encodeWithSelector(IBPool.setSwapFee.selector, _swapFee);
emit IBPool.LOG_CALL(IBPool.setSwapFee.selector, controller, _data);

bPool.setSwapFee(_swapFee);

// it sets swap fee
assertEq(bPool.getSwapFee(), _swapFee);
}

function test_SetControllerRevertWhen_ReentrancyLockIsSet() external {
bPool.call__setLock(_MUTEX_TAKEN);
// it should revert
vm.expectRevert(IBPool.BPool_Reentrancy.selector);
bPool.setController(controller);
}

function test_SetControllerRevertWhen_CallerIsNotController() external {
vm.prank(randomCaller);
// it should revert
vm.expectRevert(IBPool.BPool_CallerIsNotController.selector);
bPool.setController(controller);
}

function test_SetControllerRevertWhen_NewControllerIsZeroAddress() external {
vm.prank(controller);
// it should revert
vm.expectRevert(IBPool.BPool_AddressZero.selector);
bPool.setController(address(0));
}

function test_SetControllerWhenPreconditionsAreMet(address _controller) external {
vm.prank(controller);
vm.assume(_controller != address(0));

// it emits LOG_CALL event
vm.expectEmit();
bytes memory _data = abi.encodeWithSelector(IBPool.setController.selector, _controller);
emit IBPool.LOG_CALL(IBPool.setController.selector, controller, _data);

bPool.setController(_controller);

// it sets new controller
assertEq(bPool.getController(), _controller);
}

function test_IsFinalizedWhenPoolIsFinalized() external view {
// it returns true
assertTrue(bPool.isFinalized());
Expand Down
26 changes: 26 additions & 0 deletions test/unit/BPool/BPool.tree
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,32 @@ BPool::constructor
├── it sets swap fee to MIN_FEE
└── it does NOT finalize the pool

BPool::setSwapFee
├── when reentrancy lock is set
│ └── it should revert
├── when caller is not controller
│ └── it should revert
├── when pool is finalized
│ └── it should revert
├── when swap fee is below MIN_FEE
│ └── it should revert
├── when swap fee is above MAX_FEE
│ └── it should revert
└── when preconditions are met
├── it emits LOG_CALL event
└── it sets swap fee

BPool::setController
├── when reentrancy lock is set
│ └── it should revert
├── when caller is not controller
│ └── it should revert
├── when new controller is zero address
│ └── it should revert
└── when preconditions are met
├── it emits LOG_CALL event
└── it sets new controller

BPool::isFinalized
├── when pool is finalized
│ └── it returns true
Expand Down
Loading