forked from balancer/balancer-core
-
Notifications
You must be signed in to change notification settings - Fork 0
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 for isValidSignature (#161)
* 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 bcowpool.isValidSignature * chore: remove preexisting unit tests replaced by ones in this pr * fix: more descriptive tree
- Loading branch information
1 parent
eef9f2a
commit 4b5fab7
Showing
3 changed files
with
66 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.25; | ||
|
||
import {IERC20} from '@cowprotocol/interfaces/IERC20.sol'; | ||
|
||
import {GPv2Order} from '@cowprotocol/libraries/GPv2Order.sol'; | ||
import {IERC1271} from '@openzeppelin/contracts/interfaces/IERC1271.sol'; | ||
|
||
import {BCoWPoolBase} from './BCoWPoolBase.sol'; | ||
import {IBCoWPool} from 'interfaces/IBCoWPool.sol'; | ||
|
||
contract BCoWPoolIsValidSignature is BCoWPoolBase { | ||
GPv2Order.Data validOrder; | ||
bytes32 validHash; | ||
|
||
function setUp() public virtual override { | ||
super.setUp(); | ||
// only set up the values that are checked in this method | ||
validOrder.appData = appData; | ||
validHash = GPv2Order.hash(validOrder, domainSeparator); | ||
|
||
bCoWPool.mock_call_verify(validOrder); | ||
} | ||
|
||
function test_RevertWhen_OrdersAppdataIsDifferentThanOneSetAtConstruction(bytes32 appData_) external { | ||
vm.assume(appData != appData_); | ||
validOrder.appData = appData_; | ||
// it should revert | ||
vm.expectRevert(IBCoWPool.AppDataDoesNotMatch.selector); | ||
bCoWPool.isValidSignature(validHash, abi.encode(validOrder)); | ||
} | ||
|
||
function test_RevertWhen_OrderHashDoesNotMatchHashedOrder(bytes32 orderHash) external { | ||
vm.assume(orderHash != validHash); | ||
// it should revert | ||
vm.expectRevert(IBCoWPool.OrderDoesNotMatchMessageHash.selector); | ||
bCoWPool.isValidSignature(orderHash, abi.encode(validOrder)); | ||
} | ||
|
||
function test_RevertWhen_HashedOrderDoesNotMatchCommitment(bytes32 commitment) external { | ||
vm.assume(validHash != commitment); | ||
bCoWPool.call__setLock(commitment); | ||
// it should revert | ||
vm.expectRevert(IBCoWPool.OrderDoesNotMatchCommitmentHash.selector); | ||
bCoWPool.isValidSignature(validHash, abi.encode(validOrder)); | ||
} | ||
|
||
function test_WhenPreconditionsAreMet() external { | ||
// can't do it in setUp because transient storage is wiped in between | ||
bCoWPool.call__setLock(validHash); | ||
// it calls verify | ||
bCoWPool.expectCall_verify(validOrder); | ||
// it returns EIP-1271 magic value | ||
assertEq(bCoWPool.isValidSignature(validHash, abi.encode(validOrder)), IERC1271.isValidSignature.selector); | ||
} | ||
} |
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,10 @@ | ||
BCoWPool::IsValidSignature | ||
├── when orders appdata is different than one set at construction | ||
│ └── it should revert | ||
├── when orderHash does not match hashed order | ||
│ └── it should revert | ||
├── when hashed order does not match commitment | ||
│ └── it should revert | ||
└── when preconditions are met | ||
├── it calls verify | ||
└── it returns EIP-1271 magic value |