Skip to content

Commit

Permalink
fix: test issues on merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
wei3erHase committed Jul 22, 2024
1 parent c18e34f commit 9853016
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 84 deletions.
77 changes: 0 additions & 77 deletions test/unit/BPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -245,83 +245,6 @@ abstract contract BasePoolTest is Test, BConst, Utils, BMath {
}
}

contract BPool_Unit_Finalize is BasePoolTest {
modifier happyPath(uint256 _tokensLength) {
_tokensLength = bound(_tokensLength, MIN_BOUND_TOKENS, MAX_BOUND_TOKENS);
_setRandomTokens(_tokensLength);
_;
}

function test_Revert_NotController(
address _controller,
address _caller,
uint256 _tokensLength
) public happyPath(_tokensLength) {
vm.assume(_controller != _caller);
bPool.set__controller(_controller);

vm.prank(_caller);
vm.expectRevert(IBPool.BPool_CallerIsNotController.selector);
bPool.finalize();
}

function test_Revert_Finalized(uint256 _tokensLength) public happyPath(_tokensLength) {
_setFinalize(true);

vm.expectRevert(IBPool.BPool_PoolIsFinalized.selector);
bPool.finalize();
}

function test_Revert_MinTokens(uint256 _tokensLength) public {
_tokensLength = bound(_tokensLength, 0, MIN_BOUND_TOKENS - 1);
_setRandomTokens(_tokensLength);

vm.expectRevert(IBPool.BPool_TokensBelowMinimum.selector);
bPool.finalize();
}

function test_Revert_Reentrancy(uint256 _tokensLength) public happyPath(_tokensLength) {
_expectRevertByReentrancy();
bPool.finalize();
}

function test_Set_Finalize(uint256 _tokensLength) public happyPath(_tokensLength) {
bPool.finalize();

assertEq(bPool.call__finalized(), true);
}

function test_Set_ReentrancyLock(uint256 _tokensLength) public happyPath(_tokensLength) {
_expectSetReentrancyLock();
bPool.finalize();
}

function test_Call_AfterFinalizeHook(uint256 _tokensLength) public happyPath(_tokensLength) {
bPool.expectCall__afterFinalize();
bPool.finalize();
}

function test_Mint_InitPoolSupply(uint256 _tokensLength) public happyPath(_tokensLength) {
bPool.finalize();

assertEq(bPool.totalSupply(), INIT_POOL_SUPPLY);
}

function test_Push_InitPoolSupply(uint256 _tokensLength) public happyPath(_tokensLength) {
bPool.finalize();

assertEq(bPool.balanceOf(address(this)), INIT_POOL_SUPPLY);
}

function test_Emit_LogCall(uint256 _tokensLength) public happyPath(_tokensLength) {
vm.expectEmit();
bytes memory _data = abi.encodeWithSelector(BPool.finalize.selector);
emit IBPool.LOG_CALL(BPool.finalize.selector, address(this), _data);

bPool.finalize();
}
}

contract BPool_Unit_JoinswapPoolAmountOut is BasePoolTest {
address tokenIn;

Expand Down
18 changes: 11 additions & 7 deletions test/unit/BPool/BPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ contract BPool is BPoolBase, BMath {
uint256 swapFee = 0.1e18;

uint256 public tokenWeight = 1e18;
uint256 public totalWeight = 2e18;
uint256 public totalWeight = 10e18;
uint256 public balanceTokenIn = 10e18;
uint256 public balanceTokenOut = 20e18;

Expand All @@ -40,7 +40,7 @@ contract BPool is BPoolBase, BMath {
}

function test_ConstructorWhenCalled(address _deployer) external {
vm.prank(_deployer);
vm.startPrank(_deployer);
MockBPool _newBPool = new MockBPool();

// it sets caller as controller
Expand Down Expand Up @@ -373,20 +373,22 @@ contract BPool is BPoolBase, BMath {

function test_FinalizeRevertWhen_CallerIsNotController(address _caller) external {
vm.assume(_caller != address(this));
vm.prank(_caller);
vm.startPrank(_caller);
// it should revert
vm.expectRevert(IBPool.BPool_CallerIsNotController.selector);
bPool.finalize();
}

function test_FinalizeRevertWhen_PoolIsFinalized() external {
bPool.set__finalized(true);
vm.startPrank(controller);
// it should revert
vm.expectRevert(IBPool.BPool_PoolIsFinalized.selector);
bPool.finalize();
}

function test_FinalizeRevertWhen_ThereAreTooFewTokensBound() external {
vm.startPrank(controller);
bPool.set__finalized(false);
address[] memory tokens_ = new address[](1);
tokens_[0] = tokens[0];
bPool.set__tokens(tokens_);
Expand All @@ -396,22 +398,24 @@ contract BPool is BPoolBase, BMath {
}

function test_FinalizeWhenPreconditionsAreMet() external {
vm.startPrank(controller);
bPool.set__finalized(false);
bPool.set__tokens(tokens);
bPool.set__records(tokens[0], IBPool.Record({bound: true, index: 0, denorm: tokenWeight}));
bPool.set__records(tokens[1], IBPool.Record({bound: true, index: 1, denorm: tokenWeight}));
bPool.mock_call__mintPoolShare(INIT_POOL_SUPPLY);
bPool.mock_call__pushPoolShare(address(this), INIT_POOL_SUPPLY);
bPool.mock_call__pushPoolShare(controller, INIT_POOL_SUPPLY);

// it calls _afterFinalize hook
bPool.expectCall__afterFinalize();
// it mints initial pool shares
bPool.expectCall__mintPoolShare(INIT_POOL_SUPPLY);
// it sends initial pool shares to controller
bPool.expectCall__pushPoolShare(address(this), INIT_POOL_SUPPLY);
bPool.expectCall__pushPoolShare(controller, INIT_POOL_SUPPLY);
// it emits a LOG_CALL event
bytes memory data = abi.encodeCall(IBPool.finalize, ());
vm.expectEmit(address(bPool));
emit IBPool.LOG_CALL(IBPool.finalize.selector, address(this), data);
emit IBPool.LOG_CALL(IBPool.finalize.selector, controller, data);

bPool.finalize();
// it finalizes the pool
Expand Down

0 comments on commit 9853016

Please sign in to comment.