From 4865e044e730879cb90929066de394f28558bad6 Mon Sep 17 00:00:00 2001 From: teddy Date: Wed, 17 Jul 2024 19:52:38 -0300 Subject: [PATCH] test: reorganize commit tree --- test/unit/BCoWPool/BCoWPool.t.sol | 24 ++++++++++-------------- test/unit/BCoWPool/BCoWPool.tree | 9 ++++----- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/test/unit/BCoWPool/BCoWPool.t.sol b/test/unit/BCoWPool/BCoWPool.t.sol index 4181439d..74dd75ce 100644 --- a/test/unit/BCoWPool/BCoWPool.t.sol +++ b/test/unit/BCoWPool/BCoWPool.t.sol @@ -49,28 +49,24 @@ contract BCoWPool is BCoWPoolBase { bCoWPool.call__afterFinalize(); } - function test_CommitRevertWhen_SenderIsNotSolutionSettler(address caller) external { - vm.assume(caller != cowSolutionSettler); - vm.prank(caller); + function test_CommitRevertWhen_ReentrancyLockIsSet(bytes32 lockValue) external { + vm.assume(lockValue != _MUTEX_FREE); + bCoWPool.call__setLock(lockValue); // it should revert - vm.expectRevert(abi.encodeWithSelector(IBCoWPool.CommitOutsideOfSettlement.selector)); + vm.expectRevert(IBPool.BPool_Reentrancy.selector); bCoWPool.commit(commitmentValue); } - modifier whenSenderIsSolutionSettler() { - vm.startPrank(cowSolutionSettler); - _; - } - - function test_CommitRevertWhen_ReentrancyLockIsSet(bytes32 lockValue) external whenSenderIsSolutionSettler { - vm.assume(lockValue != _MUTEX_FREE); - bCoWPool.call__setLock(lockValue); + function test_CommitRevertWhen_SenderIsNotSolutionSettler(address caller) external { + vm.assume(caller != cowSolutionSettler); + vm.prank(caller); // it should revert - vm.expectRevert(IBPool.BPool_Reentrancy.selector); + vm.expectRevert(abi.encodeWithSelector(IBCoWPool.CommitOutsideOfSettlement.selector)); bCoWPool.commit(commitmentValue); } - function test_CommitWhenCalled(bytes32 commitmentValue_) external whenSenderIsSolutionSettler { + 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 383127d6..abf9b3bb 100644 --- a/test/unit/BCoWPool/BCoWPool.tree +++ b/test/unit/BCoWPool/BCoWPool.tree @@ -8,10 +8,9 @@ BCoWPool::_afterFinalize └── 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 sender is solution settler - ├── when reentrancy lock is set - │ └──it should revert - └── when called - └── it should set the transient reentrancy lock +└── when preconditions are met + └── it should set the transient reentrancy lock