Skip to content

Commit

Permalink
test: btt tests for bcowpool constructor (#163)
Browse files Browse the repository at this point in the history
* test: btt tests for bpool.swapExactAmountIn

* chore: delete preexisting unit tests

* test: small renames from feedback

* test: be explicit about untestable code

* test: adding skipped test for unreachable condition

* test: code wasnt so unreachable after all

* refactor: get rid of _setRecord

* test: btt tests for bcowpool.verify

* chore: delete preexisting unit tests

* chore: testcase renaming from review

* chore: get rid of _setTokens altogether

* test: fuzz all possible valid order.sellAmount values

* chore: rename correctOrder -> validOrder

* test: btt tests for bpool.finalize

* test: btt tests for bcowpool.finalize

* chore: remove preexisting unit tests replaced by ones in this pr

* fix: feedback from review

* refactor: make caller==controller default scenario

* test: btt tests for bcowpool constructor

* chore: remove preexisting unit tests replaced by ones in this pr

* fix: feedback from review

* fix: make bulloak happy

* fix: mergeback mistake

---------

Co-authored-by: Weißer Hase <[email protected]>
  • Loading branch information
0xteddybear and wei3erHase authored Jul 23, 2024
1 parent 4b5fab7 commit dad92aa
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 70 deletions.
39 changes: 0 additions & 39 deletions test/manual-smock/MockBCoWPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -369,45 +369,6 @@ contract MockBCoWPool is BCoWPool, Test {
vm.expectCall(address(this), abi.encodeWithSignature('_pushUnderlying(address,address,uint256)', token, to, amount));
}

function mock_call__pushPoolShare(address to, uint256 amount) public {
vm.mockCall(address(this), abi.encodeWithSignature('_pushPoolShare(address,uint256)', to, amount), abi.encode());
}

function _pushPoolShare(address to, uint256 amount) internal override {
(bool _success, bytes memory _data) =
address(this).call(abi.encodeWithSignature('_pushPoolShare(address,uint256)', to, amount));

if (_success) return abi.decode(_data, ());
else return super._pushPoolShare(to, amount);
}

function call__pushPoolShare(address to, uint256 amount) public {
return _pushPoolShare(to, amount);
}

function expectCall__pushPoolShare(address to, uint256 amount) public {
vm.expectCall(address(this), abi.encodeWithSignature('_pushPoolShare(address,uint256)', to, amount));
}

function mock_call__mintPoolShare(uint256 amount) public {
vm.mockCall(address(this), abi.encodeWithSignature('_mintPoolShare(uint256)', amount), abi.encode());
}

function _mintPoolShare(uint256 amount) internal override {
(bool _success, bytes memory _data) = address(this).call(abi.encodeWithSignature('_mintPoolShare(uint256)', amount));

if (_success) return abi.decode(_data, ());
else return super._mintPoolShare(amount);
}

function call__mintPoolShare(uint256 amount) public {
return _mintPoolShare(amount);
}

function expectCall__mintPoolShare(uint256 amount) public {
vm.expectCall(address(this), abi.encodeWithSignature('_mintPoolShare(uint256)', amount));
}

function call__afterFinalize() public {
return _afterFinalize();
}
Expand Down
31 changes: 0 additions & 31 deletions test/unit/BCoWPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,3 @@ abstract contract BaseCoWPoolTest is BasePoolTest, BCoWConst {
});
}
}

contract BCoWPool_Unit_Constructor is BaseCoWPoolTest {
function test_Set_SolutionSettler(address _settler) public {
assumeNotForgeAddress(_settler);
vm.mockCall(_settler, abi.encodePacked(ISettlement.domainSeparator.selector), abi.encode(domainSeparator));
vm.mockCall(_settler, abi.encodePacked(ISettlement.vaultRelayer.selector), abi.encode(vaultRelayer));
MockBCoWPool pool = new MockBCoWPool(_settler, appData);
assertEq(address(pool.SOLUTION_SETTLER()), _settler);
}

function test_Set_DomainSeparator(address _settler, bytes32 _separator) public {
assumeNotForgeAddress(_settler);
vm.mockCall(_settler, abi.encodePacked(ISettlement.domainSeparator.selector), abi.encode(_separator));
vm.mockCall(_settler, abi.encodePacked(ISettlement.vaultRelayer.selector), abi.encode(vaultRelayer));
MockBCoWPool pool = new MockBCoWPool(_settler, appData);
assertEq(pool.SOLUTION_SETTLER_DOMAIN_SEPARATOR(), _separator);
}

function test_Set_VaultRelayer(address _settler, address _relayer) public {
assumeNotForgeAddress(_settler);
vm.mockCall(_settler, abi.encodePacked(ISettlement.domainSeparator.selector), abi.encode(domainSeparator));
vm.mockCall(_settler, abi.encodePacked(ISettlement.vaultRelayer.selector), abi.encode(_relayer));
MockBCoWPool pool = new MockBCoWPool(_settler, appData);
assertEq(pool.VAULT_RELAYER(), _relayer);
}

function test_Set_AppData(bytes32 _appData) public {
MockBCoWPool pool = new MockBCoWPool(cowSolutionSettler, _appData);
assertEq(pool.APP_DATA(), _appData);
}
}
26 changes: 26 additions & 0 deletions test/unit/BCoWPool/BCoWPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {IBCoWFactory} from 'interfaces/IBCoWFactory.sol';

import {IBCoWPool} from 'interfaces/IBCoWPool.sol';
import {IBPool} from 'interfaces/IBPool.sol';
import {ISettlement} from 'interfaces/ISettlement.sol';
import {MockBCoWPool} from 'test/manual-smock/MockBCoWPool.sol';

contract BCoWPool is BCoWPoolBase {
bytes32 public commitmentValue = bytes32(uint256(0xf00ba5));
Expand All @@ -27,6 +29,30 @@ contract BCoWPool is BCoWPoolBase {
vm.mockCall(tokens[1], abi.encodeCall(IERC20.approve, (vaultRelayer, type(uint256).max)), abi.encode(true));
}

function test_ConstructorWhenCalled(
address _settler,
bytes32 _separator,
address _relayer,
bytes32 _appData
) external {
assumeNotForgeAddress(_settler);
vm.mockCall(_settler, abi.encodePacked(ISettlement.domainSeparator.selector), abi.encode(_separator));
vm.mockCall(_settler, abi.encodePacked(ISettlement.vaultRelayer.selector), abi.encode(_relayer));
// it should query the solution settler for the domain separator
vm.expectCall(_settler, abi.encodePacked(ISettlement.domainSeparator.selector));
// it should query the solution settler for the vault relayer
vm.expectCall(_settler, abi.encodePacked(ISettlement.vaultRelayer.selector));
MockBCoWPool pool = new MockBCoWPool(_settler, _appData);
// it should set the solution settler
assertEq(address(pool.SOLUTION_SETTLER()), _settler);
// it should set the domain separator
assertEq(pool.SOLUTION_SETTLER_DOMAIN_SEPARATOR(), _separator);
// it should set the vault relayer
assertEq(pool.VAULT_RELAYER(), _relayer);
// it should set the app data
assertEq(pool.APP_DATA(), _appData);
}

function test__afterFinalizeWhenCalled() external {
// it calls approve on every bound token
vm.expectCall(tokens[0], abi.encodeCall(IERC20.approve, (vaultRelayer, type(uint256).max)));
Expand Down
9 changes: 9 additions & 0 deletions test/unit/BCoWPool/BCoWPool.tree
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
BCoWPool::Constructor
└── when called
├── it should set the solution settler
├── it should query the solution settler for the domain separator
├── it should set the domain separator
├── it should query the solution settler for the vault relayer
├── it should set the vault relayer
└── it should set the app data

BCoWPool::_afterFinalize
├── when called
│ ├── it calls approve on every bound token
Expand Down

0 comments on commit dad92aa

Please sign in to comment.