Skip to content

Commit

Permalink
chore: merge dev
Browse files Browse the repository at this point in the history
  • Loading branch information
0xteddybear committed Jul 22, 2024
2 parents ac4399e + 2a0b429 commit 15eac0e
Show file tree
Hide file tree
Showing 16 changed files with 353 additions and 464 deletions.
29 changes: 29 additions & 0 deletions test/unit/BCoWPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,35 @@ abstract contract BaseCoWPoolTest is BasePoolTest, BCoWConst {
}
}

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();
Expand Down
38 changes: 19 additions & 19 deletions test/unit/BCoWPool/BCoWPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,20 @@ import {ISettlement} from 'interfaces/ISettlement.sol';
import {MockBCoWPool} from 'test/manual-smock/MockBCoWPool.sol';

contract BCoWPool is BCoWPoolBase {
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}));

vm.mockCall(address(this), abi.encodeCall(IBCoWFactory.logBCoWPool, ()), abi.encode());

vm.mockCall(tokens[0], abi.encodeCall(IERC20.approve, (vaultRelayer, type(uint256).max)), abi.encode(true));
vm.mockCall(tokens[1], abi.encodeCall(IERC20.approve, (vaultRelayer, type(uint256).max)), abi.encode(true));
}

function test_ConstructorWhenCalled(
address _settler,
bytes32 _separator,
Expand All @@ -31,21 +45,7 @@ contract BCoWPool is BCoWPoolBase {
assertEq(pool.APP_DATA(), _appData);
}

modifier whenPreconditionsAreMet() {
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}));
bCoWPool.mock_call__mintPoolShare(INIT_POOL_SUPPLY);
bCoWPool.mock_call__pushPoolShare(address(this), INIT_POOL_SUPPLY);

vm.mockCall(address(this), abi.encodeCall(IBCoWFactory.logBCoWPool, ()), abi.encode());

vm.mockCall(tokens[0], abi.encodeCall(IERC20.approve, (vaultRelayer, type(uint256).max)), abi.encode(true));
vm.mockCall(tokens[1], abi.encodeCall(IERC20.approve, (vaultRelayer, type(uint256).max)), abi.encode(true));
_;
}

function test_FinalizeWhenPreconditionsAreMet() external whenPreconditionsAreMet {
function test__afterFinalize_WhenCalled() 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)));
Expand All @@ -54,16 +54,16 @@ contract BCoWPool is BCoWPoolBase {
bCoWPool.finalize();
}

function test_FinalizeWhenFactorysLogBCoWPoolDoesNotRevert() external whenPreconditionsAreMet {
function test__afterFinalize_WhenFactorysLogBCoWPoolDoesNotRevert() external {
// it returns
bCoWPool.finalize();
bCoWPool.call__afterFinalize();
}

function test_FinalizeWhenFactorysLogBCoWPoolReverts(bytes memory revertData) external whenPreconditionsAreMet {
function test__afterFinalize_WhenFactorysLogBCoWPoolReverts(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.finalize();
bCoWPool.call__afterFinalize();
}
}
16 changes: 8 additions & 8 deletions test/unit/BCoWPool/BCoWPool.tree
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ BCoWPool::Constructor
├── it should set the vault relayer
└── it should set the app data

BCoWPool::Finalize
── when preconditions are met
├── it calls approve on every bound token
── it calls logBCoWPool on the factory
├── when factorys logBCoWPool does not revert
│ └── it returns
└── when factorys logBCoWPool reverts
└── it emits a COWAMMPoolCreated event
BCoWPool::_afterFinalize
── when called
├── it calls approve on every bound token
── it calls logBCoWPool on the factory
├── when factorys logBCoWPool does not revert
│ └── it returns
└── when factorys logBCoWPool reverts
└── it emits a COWAMMPoolCreated event
28 changes: 28 additions & 0 deletions test/unit/BCoWPool/BCoWPoolBase.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

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

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

contract BCoWPoolBase is BPoolBase, BCoWConst, BNum {
bytes32 public appData = bytes32('appData');
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);
}
}
7 changes: 5 additions & 2 deletions test/unit/BCoWPool/BCoWPool_Verify.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity 0.8.25;
import {IERC20} from '@cowprotocol/interfaces/IERC20.sol';
import {GPv2Order} from '@cowprotocol/libraries/GPv2Order.sol';

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

Expand Down Expand Up @@ -123,7 +123,10 @@ contract BCoWPoolVerify is BCoWPoolBase {
function test_WhenPreconditionsAreMet(uint256 _sellAmount) external {
_sellAmount = bound(_sellAmount, 0, validOrder.sellAmount);
validOrder.sellAmount = _sellAmount;
// it should return
// it should query the balance of the buy token
vm.expectCall(tokenIn, abi.encodeCall(IERC20.balanceOf, (address(bCoWPool))));
// it should query the balance of the sell token
vm.expectCall(tokenOut, abi.encodeCall(IERC20.balanceOf, (address(bCoWPool))));
bCoWPool.verify(validOrder);
}
}
3 changes: 2 additions & 1 deletion test/unit/BCoWPool/BCoWPool_Verify.tree
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ BCoWPool::Verify
├── when calculated token amount out is less than order sell amount
│ └── it should revert
└── when preconditions are met
└── it should return
├── it should query the balance of the buy token
└── it should query the balance of the sell token
Loading

0 comments on commit 15eac0e

Please sign in to comment.