Skip to content

Commit

Permalink
feat: adding call tokens expectation
Browse files Browse the repository at this point in the history
  • Loading branch information
wei3erHase committed Jul 18, 2024
1 parent b2056be commit ffb1bc0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/contracts/BCoWHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ contract BCoWHelper is ICOWAMMPoolHelper, BMath {
}

/// @inheritdoc ICOWAMMPoolHelper
function tokens(address pool) public view returns (address[] memory tokens_) {
function tokens(address pool) public view virtual returns (address[] memory tokens_) {
// reverts in case pool is not deployed by the helper's factory
if (!IBCoWFactory(factory).isBPool(pool)) {
revert PoolDoesNotExist();
Expand Down
13 changes: 13 additions & 0 deletions test/manual-smock/MockBCoWHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ contract MockBCoWHelper is BCoWHelper, Test {
return _APP_DATA;
}

// NOTE: manually added method (public overrides not supported in smock)
function tokens(address pool) public view override returns (address[] memory tokens_) {
(bool _success, bytes memory _data) = address(this).staticcall(abi.encodeWithSignature('tokens(address)', pool));

if (_success) return abi.decode(_data, (address[]));
else return super.tokens(pool);
}

// NOTE: manually added method (public overrides not supported in smock)
function expectCall_tokens(address pool) public {
vm.expectCall(address(this), abi.encodeWithSignature('tokens(address)', pool));
}

// BCoWHelper methods
constructor(address factory_) BCoWHelper(factory_) {}

Expand Down
4 changes: 4 additions & 0 deletions test/unit/BCoWHelper.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ contract BCoWHelperTest is Test {
}

function test_OrderWhenThePoolIsSupported(bytes32 domainSeparator) external {
// it should call tokens
helper.mock_call_tokens(address(pool), tokens);
helper.expectCall_tokens(address(pool));

// it should query the domain separator from the pool
pool.expectCall_SOLUTION_SETTLER_DOMAIN_SEPARATOR();
pool.mock_call_SOLUTION_SETTLER_DOMAIN_SEPARATOR(domainSeparator);
Expand Down
1 change: 1 addition & 0 deletions test/unit/BCoWHelper.tree
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ BCoWHelperTest::order
├── when the pool is not supported
│ └── it should revert
├── when the pool is supported
│ ├── it should call tokens
│ ├── it should query the domain separator from the pool
│ ├── it should return a valid pool order
│ ├── it should return a commit pre-interaction
Expand Down

0 comments on commit ffb1bc0

Please sign in to comment.