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

fix: test small fixes #176

Merged
merged 4 commits into from
Jul 25, 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
2 changes: 1 addition & 1 deletion test/unit/BCoWPool/BCoWPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.25;

import {IERC20} from '@cowprotocol/interfaces/IERC20.sol';

import {BCoWPoolBase} from './BCoWPoolBase.sol';
import {BCoWPoolBase} from './BCoWPoolBase.t.sol';

import {IBCoWFactory} from 'interfaces/IBCoWFactory.sol';

Expand Down
28 changes: 0 additions & 28 deletions test/unit/BCoWPool/BCoWPoolBase.sol

This file was deleted.

6 changes: 1 addition & 5 deletions test/unit/BCoWPool/BCoWPoolBase.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {BPoolBase} from '../BPool/BPoolBase.sol';
import {BPoolBase} from '../BPool/BPoolBase.t.sol';
import {BCoWConst} from 'contracts/BCoWConst.sol';
import {BNum} from 'contracts/BNum.sol';

Expand All @@ -13,14 +13,10 @@ contract BCoWPoolBase is BPoolBase, BCoWConst, BNum {
address public cowSolutionSettler = makeAddr('cowSolutionSettler');
bytes32 public domainSeparator = bytes32(bytes2(0xf00b));
address public vaultRelayer = makeAddr('vaultRelayer');
address public tokenIn;
address public tokenOut;
MockBCoWPool bCoWPool;

function setUp() public virtual override {
super.setUp();
tokenIn = tokens[0];
tokenOut = tokens[1];
vm.mockCall(cowSolutionSettler, abi.encodePacked(ISettlement.domainSeparator.selector), abi.encode(domainSeparator));
vm.mockCall(cowSolutionSettler, abi.encodePacked(ISettlement.vaultRelayer.selector), abi.encode(vaultRelayer));
bCoWPool = new MockBCoWPool(cowSolutionSettler, appData);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/BCoWPool/BCoWPool_IsValidSignature.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {IERC20} from '@cowprotocol/interfaces/IERC20.sol';
import {GPv2Order} from '@cowprotocol/libraries/GPv2Order.sol';
import {IERC1271} from '@openzeppelin/contracts/interfaces/IERC1271.sol';

import {BCoWPoolBase} from './BCoWPoolBase.sol';
import {BCoWPoolBase} from './BCoWPoolBase.t.sol';
import {IBCoWPool} from 'interfaces/IBCoWPool.sol';

contract BCoWPoolIsValidSignature is BCoWPoolBase {
Expand Down
4 changes: 4 additions & 0 deletions test/unit/BCoWPool/BCoWPool_Verify.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {IBPool} from 'interfaces/IBPool.sol';

contract BCoWPoolVerify is BCoWPoolBase {
// Valid scenario:
address public tokenIn;
address public tokenOut;
uint256 public tokenAmountIn = 1e18;
uint256 public tokenInBalance = 100e18;
uint256 public tokenOutBalance = 80e18;
Expand All @@ -22,6 +24,8 @@ contract BCoWPoolVerify is BCoWPoolBase {

function setUp() public virtual override {
super.setUp();
tokenIn = tokens[0];
tokenOut = tokens[1];
bCoWPool.set__tokens(tokens);
bCoWPool.set__records(tokenIn, IBPool.Record({bound: true, index: 0, denorm: tokenInWeight}));
bCoWPool.set__records(tokenOut, IBPool.Record({bound: true, index: 1, denorm: tokenOutWeight}));
Expand Down
2 changes: 1 addition & 1 deletion test/unit/BPool/BPool.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {BPoolBase} from './BPoolBase.sol';
import {BPoolBase} from './BPoolBase.t.sol';

import {IERC20Errors} from '@openzeppelin/contracts/interfaces/draft-IERC6093.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
Expand Down
File renamed without changes.
42 changes: 22 additions & 20 deletions test/unit/BPool/BPool_Bind.t.sol
Original file line number Diff line number Diff line change
@@ -1,81 +1,83 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {BPoolBase} from './BPoolBase.sol';
import {BPoolBase} from './BPoolBase.t.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {IBPool} from 'interfaces/IBPool.sol';

contract BPoolBind is BPoolBase {
address public token;
uint256 public tokenBindBalance = 100e18;
uint256 public tokenWeight = 1e18;
uint256 public totalWeight = 10e18;

function setUp() public virtual override {
super.setUp();
token = tokens[0];

vm.mockCall(tokens[0], abi.encodePacked(IERC20.transferFrom.selector), abi.encode());
vm.mockCall(tokens[0], abi.encodePacked(IERC20.transfer.selector), abi.encode());
vm.mockCall(token, abi.encodePacked(IERC20.transferFrom.selector), abi.encode());
vm.mockCall(token, abi.encodePacked(IERC20.transfer.selector), abi.encode());
}

function test_RevertWhen_ReentrancyLockIsSet() external {
bPool.call__setLock(_MUTEX_TAKEN);
vm.expectRevert(IBPool.BPool_Reentrancy.selector);
// it should revert
bPool.bind(tokens[0], tokenBindBalance, tokenWeight);
bPool.bind(token, tokenBindBalance, tokenWeight);
}

function test_RevertWhen_CallerIsNOTController(address _caller) external {
// it should revert
vm.assume(_caller != address(this));
vm.prank(_caller);
vm.expectRevert(IBPool.BPool_CallerIsNotController.selector);
bPool.bind(tokens[0], tokenBindBalance, tokenWeight);
bPool.bind(token, tokenBindBalance, tokenWeight);
}

function test_RevertWhen_TokenIsAlreadyBound() external {
bPool.set__records(tokens[0], IBPool.Record({bound: true, index: 0, denorm: tokenWeight}));
bPool.set__records(token, IBPool.Record({bound: true, index: 0, denorm: tokenWeight}));
// it should revert
vm.expectRevert(IBPool.BPool_TokenAlreadyBound.selector);
bPool.bind(tokens[0], tokenBindBalance, tokenWeight);
bPool.bind(token, tokenBindBalance, tokenWeight);
}

function test_RevertWhen_PoolIsFinalized() external {
bPool.set__finalized(true);
// it should revert
vm.expectRevert(IBPool.BPool_PoolIsFinalized.selector);
bPool.bind(tokens[0], tokenBindBalance, tokenWeight);
bPool.bind(token, tokenBindBalance, tokenWeight);
}

function test_RevertWhen_MAX_BOUND_TOKENSTokensAreAlreadyBound() external {
_setRandomTokens(MAX_BOUND_TOKENS);
// it should revert
vm.expectRevert(IBPool.BPool_TokensAboveMaximum.selector);
bPool.bind(tokens[0], tokenBindBalance, tokenWeight);
bPool.bind(token, tokenBindBalance, tokenWeight);
}

function test_RevertWhen_TokenWeightIsTooLow() external {
// it should revert
vm.expectRevert(IBPool.BPool_WeightBelowMinimum.selector);
bPool.bind(tokens[0], tokenBindBalance, MIN_WEIGHT - 1);
bPool.bind(token, tokenBindBalance, MIN_WEIGHT - 1);
}

function test_RevertWhen_TokenWeightIsTooHigh() external {
// it should revert
vm.expectRevert(IBPool.BPool_WeightAboveMaximum.selector);
bPool.bind(tokens[0], tokenBindBalance, MAX_WEIGHT + 1);
bPool.bind(token, tokenBindBalance, MAX_WEIGHT + 1);
}

function test_RevertWhen_TooLittleBalanceIsProvided() external {
// it should revert
vm.expectRevert(IBPool.BPool_BalanceBelowMinimum.selector);
bPool.bind(tokens[0], MIN_BALANCE - 1, tokenWeight);
bPool.bind(token, MIN_BALANCE - 1, tokenWeight);
}

function test_RevertWhen_WeightSumExceedsMAX_TOTAL_WEIGHT() external {
bPool.set__totalWeight(2 * MAX_TOTAL_WEIGHT / 3);
// it should revert
vm.expectRevert(IBPool.BPool_TotalWeightAboveMaximum.selector);
bPool.bind(tokens[0], tokenBindBalance, MAX_TOTAL_WEIGHT / 2);
bPool.bind(token, tokenBindBalance, MAX_TOTAL_WEIGHT / 2);
}

function test_WhenTokenCanBeBound(uint256 _existingTokens) external {
Expand All @@ -84,24 +86,24 @@ contract BPoolBind is BPoolBase {

bPool.set__totalWeight(totalWeight);
// it calls _pullUnderlying
bPool.expectCall__pullUnderlying(tokens[0], address(this), tokenBindBalance);
bPool.expectCall__pullUnderlying(token, address(this), tokenBindBalance);
// it sets the reentrancy lock
bPool.expectCall__setLock(_MUTEX_TAKEN);
// it emits LOG_CALL event
vm.expectEmit();
bytes memory _data = abi.encodeWithSelector(IBPool.bind.selector, tokens[0], tokenBindBalance, tokenWeight);
bytes memory _data = abi.encodeWithSelector(IBPool.bind.selector, token, tokenBindBalance, tokenWeight);
emit IBPool.LOG_CALL(IBPool.bind.selector, address(this), _data);

bPool.bind(tokens[0], tokenBindBalance, tokenWeight);
bPool.bind(token, tokenBindBalance, tokenWeight);

// it clears the reentrancy lock
assertEq(bPool.call__getLock(), _MUTEX_FREE);
// it adds token to the tokens array
assertEq(bPool.call__tokens()[_existingTokens], tokens[0]);
assertEq(bPool.call__tokens()[_existingTokens], token);
// it sets the token record
assertEq(bPool.call__records(tokens[0]).bound, true);
assertEq(bPool.call__records(tokens[0]).denorm, tokenWeight);
assertEq(bPool.call__records(tokens[0]).index, _existingTokens);
assertEq(bPool.call__records(token).bound, true);
assertEq(bPool.call__records(token).denorm, tokenWeight);
assertEq(bPool.call__records(token).index, _existingTokens);
// it sets total weight
assertEq(bPool.call__totalWeight(), totalWeight + tokenWeight);
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/BPool/BPool_ExitPool.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {BPoolBase} from './BPoolBase.sol';
import {BPoolBase} from './BPoolBase.t.sol';

import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';

Expand Down
2 changes: 1 addition & 1 deletion test/unit/BPool/BPool_ExitswapExternAmountOut.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {BPoolBase} from './BPoolBase.sol';
import {BPoolBase} from './BPoolBase.t.sol';

import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';

Expand Down
2 changes: 1 addition & 1 deletion test/unit/BPool/BPool_ExitswapPoolAmountIn.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {BPoolBase} from './BPoolBase.sol';
import {BPoolBase} from './BPoolBase.t.sol';

import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';

Expand Down
2 changes: 1 addition & 1 deletion test/unit/BPool/BPool_JoinPool.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {BPoolBase} from './BPoolBase.sol';
import {BPoolBase} from './BPoolBase.t.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';

import {BNum} from 'contracts/BNum.sol';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/BPool/BPool_JoinswapExternAmountIn.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {BPoolBase} from './BPoolBase.sol';
import {BPoolBase} from './BPoolBase.t.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';

import {BNum} from 'contracts/BNum.sol';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/BPool/BPool_JoinswapPoolAmountOut.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {BPoolBase} from './BPoolBase.sol';
import {BPoolBase} from './BPoolBase.t.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';

import {BNum} from 'contracts/BNum.sol';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/BPool/BPool_SwapExactAmountIn.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {BPoolBase} from './BPoolBase.sol';
import {BPoolBase} from './BPoolBase.t.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';

import {BNum} from 'contracts/BNum.sol';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/BPool/BPool_SwapExactAmountOut.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {BPoolBase} from './BPoolBase.sol';
import {BPoolBase} from './BPoolBase.t.sol';
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';

import {BNum} from 'contracts/BNum.sol';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/BPool/BPool_Unbind.t.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import {BPoolBase} from './BPoolBase.sol';
import {BPoolBase} from './BPoolBase.t.sol';

import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
import {IBPool} from 'interfaces/IBPool.sol';
Expand Down
Loading