forked from balancer/balancer-core
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add btt tests for finalize methods (#159)
* 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 * fix: reorganize .tree * fix: feedback from review * fix: feedback from review, calling internal method directly
- Loading branch information
1 parent
6c13de8
commit 2a0b429
Showing
14 changed files
with
246 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import {IERC20} from '@cowprotocol/interfaces/IERC20.sol'; | ||
|
||
import {BCoWPoolBase} from './BCoWPoolBase.sol'; | ||
|
||
import {IBCoWFactory} from 'interfaces/IBCoWFactory.sol'; | ||
import {IBPool} from 'interfaces/IBPool.sol'; | ||
|
||
contract BCoWPool_afterFinalize 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_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))); | ||
// it calls logBCoWPool on the factory | ||
vm.expectCall(address(this), abi.encodeCall(IBCoWFactory.logBCoWPool, ())); | ||
bCoWPool.call__afterFinalize(); | ||
} | ||
|
||
function test_WhenFactorysLogBCoWPoolDoesNotRevert() external { | ||
// it returns | ||
bCoWPool.call__afterFinalize(); | ||
} | ||
|
||
function test_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.call__afterFinalize(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.