diff --git a/test/unit/BCoWPool.t.sol b/test/unit/BCoWPool.t.sol index 08b6673b..722780ce 100644 --- a/test/unit/BCoWPool.t.sol +++ b/test/unit/BCoWPool.t.sol @@ -78,35 +78,6 @@ contract BCoWPool_Unit_Constructor is BaseCoWPoolTest { } } -contract BCoWPool_Unit_Commit is BaseCoWPoolTest { - function test_Revert_NonSolutionSettler(address sender, bytes32 orderHash) public { - vm.assume(sender != cowSolutionSettler); - vm.prank(sender); - vm.expectRevert(IBCoWPool.CommitOutsideOfSettlement.selector); - bCoWPool.commit(orderHash); - } - - function test_Revert_CommitmentAlreadySet(bytes32 _existingCommitment, bytes32 _newCommitment) public { - vm.assume(_existingCommitment != bytes32(0)); - bCoWPool.call__setLock(_existingCommitment); - vm.prank(cowSolutionSettler); - vm.expectRevert(IBPool.BPool_Reentrancy.selector); - bCoWPool.commit(_newCommitment); - } - - function test_Call_SetLock(bytes32 orderHash) public { - bCoWPool.expectCall__setLock(orderHash); - vm.prank(cowSolutionSettler); - bCoWPool.commit(orderHash); - } - - function test_Set_ReentrancyLock(bytes32 orderHash) public { - vm.prank(cowSolutionSettler); - bCoWPool.commit(orderHash); - assertEq(bCoWPool.call__getLock(), orderHash); - } -} - contract BCoWPool_Unit_IsValidSignature is BaseCoWPoolTest { function setUp() public virtual override { super.setUp(); diff --git a/test/unit/BCoWPool/BCoWPool.t.sol b/test/unit/BCoWPool/BCoWPool.t.sol index b596a622..2318bd16 100644 --- a/test/unit/BCoWPool/BCoWPool.t.sol +++ b/test/unit/BCoWPool/BCoWPool.t.sol @@ -6,13 +6,17 @@ import {IERC20} from '@cowprotocol/interfaces/IERC20.sol'; import {BCoWPoolBase} from './BCoWPoolBase.sol'; import {IBCoWFactory} from 'interfaces/IBCoWFactory.sol'; + +import {IBCoWPool} from 'interfaces/IBCoWPool.sol'; import {IBPool} from 'interfaces/IBPool.sol'; -contract BCoWPool_afterFinalize is BCoWPoolBase { +contract BCoWPool is BCoWPoolBase { + bytes32 public commitmentValue = bytes32(uint256(0xf00ba5)); uint256 public tokenWeight = 1e18; function setUp() public virtual override { super.setUp(); + bCoWPool.set__tokens(tokens); bCoWPool.set__records(tokens[0], IBPool.Record({bound: true, index: 0, denorm: tokenWeight})); bCoWPool.set__records(tokens[1], IBPool.Record({bound: true, index: 1, denorm: tokenWeight})); @@ -23,7 +27,7 @@ contract BCoWPool_afterFinalize is BCoWPoolBase { vm.mockCall(tokens[1], abi.encodeCall(IERC20.approve, (vaultRelayer, type(uint256).max)), abi.encode(true)); } - function test_WhenCalled() external { + function test__afterFinalizeWhenCalled() external { // it calls approve on every bound token vm.expectCall(tokens[0], abi.encodeCall(IERC20.approve, (vaultRelayer, type(uint256).max))); vm.expectCall(tokens[1], abi.encodeCall(IERC20.approve, (vaultRelayer, type(uint256).max))); @@ -32,16 +36,39 @@ contract BCoWPool_afterFinalize is BCoWPoolBase { bCoWPool.call__afterFinalize(); } - function test_WhenFactorysLogBCoWPoolDoesNotRevert() external { + function test__afterFinalizeWhenFactorysLogBCoWPoolDoesNotRevert() external { // it returns bCoWPool.call__afterFinalize(); } - function test_WhenFactorysLogBCoWPoolReverts(bytes memory revertData) external { + function test__afterFinalizeWhenFactorysLogBCoWPoolReverts(bytes memory revertData) external { vm.mockCallRevert(address(this), abi.encodeCall(IBCoWFactory.logBCoWPool, ()), revertData); // it emits a COWAMMPoolCreated event vm.expectEmit(address(bCoWPool)); emit IBCoWFactory.COWAMMPoolCreated(address(bCoWPool)); bCoWPool.call__afterFinalize(); } + + function test_CommitRevertWhen_ReentrancyLockIsSet(bytes32 lockValue) external { + vm.assume(lockValue != _MUTEX_FREE); + bCoWPool.call__setLock(lockValue); + // it should revert + vm.expectRevert(IBPool.BPool_Reentrancy.selector); + bCoWPool.commit(commitmentValue); + } + + function test_CommitRevertWhen_SenderIsNotSolutionSettler(address caller) external { + vm.assume(caller != cowSolutionSettler); + vm.prank(caller); + // it should revert + vm.expectRevert(abi.encodeWithSelector(IBCoWPool.CommitOutsideOfSettlement.selector)); + bCoWPool.commit(commitmentValue); + } + + function test_CommitWhenPreconditionsAreMet(bytes32 commitmentValue_) external { + vm.prank(cowSolutionSettler); + bCoWPool.commit(commitmentValue_); + // it should set the transient reentrancy lock + assertEq(bCoWPool.call__getLock(), commitmentValue_); + } } diff --git a/test/unit/BCoWPool/BCoWPool.tree b/test/unit/BCoWPool/BCoWPool.tree index 0dbbd1f0..abf9b3bb 100644 --- a/test/unit/BCoWPool/BCoWPool.tree +++ b/test/unit/BCoWPool/BCoWPool.tree @@ -6,3 +6,11 @@ BCoWPool::_afterFinalize │ └── it returns └── when factorys logBCoWPool reverts └── it emits a COWAMMPoolCreated event + +BCoWPool::Commit +├── when reentrancy lock is set +│ └──it should revert +├── when sender is not solution settler +│ └──it should revert +└── when preconditions are met + └── it should set the transient reentrancy lock