Skip to content

Commit

Permalink
fix: updating smocks
Browse files Browse the repository at this point in the history
  • Loading branch information
wei3erHase committed Jul 9, 2024
1 parent eadc1e0 commit ca413a4
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .forge-snapshots/newBFactory.snap
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4130621
4130633
60 changes: 31 additions & 29 deletions test/manual-smock/MockBCoWFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import {BCoWFactory, BCoWPool, BFactory, IBCoWFactory, IBPool} from '../../src/c
import {Test} from 'forge-std/Test.sol';

contract MockBCoWFactory is BCoWFactory, Test {
constructor(address solutionSettler, bytes32 appData) BCoWFactory(solutionSettler, appData) {}

// NOTE: manually added methods (immutable overrides not supported in smock)
function mock_call_APP_DATA(bytes32 _appData) public {
vm.mockCall(address(this), abi.encodeWithSignature('APP_DATA()'), abi.encode(_appData));
}
Expand All @@ -15,10 +14,32 @@ contract MockBCoWFactory is BCoWFactory, Test {
vm.expectCall(address(this), abi.encodeWithSignature('APP_DATA()'));
}

// BCoWFactory methods
constructor(address solutionSettler, bytes32 appData) BCoWFactory(solutionSettler, appData) {}

function mock_call_logBCoWPool() public {
vm.mockCall(address(this), abi.encodeWithSignature('logBCoWPool()'), abi.encode());
}

function mock_call__newBPool(IBPool bCoWPool) public {
vm.mockCall(address(this), abi.encodeWithSignature('_newBPool()'), abi.encode(bCoWPool));
}

function _newBPool() internal override returns (IBPool bCoWPool) {
(bool _success, bytes memory _data) = address(this).call(abi.encodeWithSignature('_newBPool()'));

if (_success) return abi.decode(_data, (IBPool));
else return super._newBPool();
}

function call__newBPool() public returns (IBPool bCoWPool) {
return _newBPool();
}

function expectCall__newBPool() public {
vm.expectCall(address(this), abi.encodeWithSignature('_newBPool()'));
}

// MockBFactory methods
function set__isBPool(address _key0, bool _value) public {
_isBPool[_key0] = _value;
Expand All @@ -28,20 +49,20 @@ contract MockBCoWFactory is BCoWFactory, Test {
return _isBPool[_key0];
}

function set__bLabs(address __bLabs) public {
_bLabs = __bLabs;
function set__bDao(address __bDao) public {
_bDao = __bDao;
}

function call__bLabs() public view returns (address) {
return _bLabs;
function call__bDao() public view returns (address) {
return _bDao;
}

function mock_call_newBPool(IBPool bPool) public {
vm.mockCall(address(this), abi.encodeWithSignature('newBPool()'), abi.encode(bPool));
}

function mock_call_setBLabs(address bLabs) public {
vm.mockCall(address(this), abi.encodeWithSignature('setBLabs(address)', bLabs), abi.encode());
function mock_call_setBDao(address bDao) public {
vm.mockCall(address(this), abi.encodeWithSignature('setBDao(address)', bDao), abi.encode());
}

function mock_call_collect(IBPool bPool) public {
Expand All @@ -52,26 +73,7 @@ contract MockBCoWFactory is BCoWFactory, Test {
vm.mockCall(address(this), abi.encodeWithSignature('isBPool(address)', bPool), abi.encode(_returnParam0));
}

function mock_call_getBLabs(address _returnParam0) public {
vm.mockCall(address(this), abi.encodeWithSignature('getBLabs()'), abi.encode(_returnParam0));
}

function mock_call__newBPool(IBPool bPool) public {
vm.mockCall(address(this), abi.encodeWithSignature('_newBPool()'), abi.encode(bPool));
}

function _newBPool() internal override returns (IBPool bPool) {
(bool _success, bytes memory _data) = address(this).call(abi.encodeWithSignature('_newBPool()'));

if (_success) return abi.decode(_data, (IBPool));
else return super._newBPool();
}

function call__newBPool() public returns (IBPool bPool) {
return _newBPool();
}

function expectCall__newBPool() public {
vm.expectCall(address(this), abi.encodeWithSignature('_newBPool()'));
function mock_call_getBDao(address _returnParam0) public {
vm.mockCall(address(this), abi.encodeWithSignature('getBDao()'), abi.encode(_returnParam0));
}
}
81 changes: 79 additions & 2 deletions test/manual-smock/MockBCoWPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ contract MockBCoWPool is BCoWPool, Test {
}

/// MockBCoWPool mock methods

constructor(address cowSolutionSettler, bytes32 appData) BCoWPool(cowSolutionSettler, appData) {}

function mock_call_commit(bytes32 orderHash) public {
Expand Down Expand Up @@ -376,6 +375,84 @@ contract MockBCoWPool is BCoWPool, Test {
vm.expectCall(address(this), abi.encodeWithSignature('_afterFinalize()'));
}

function mock_call__pullPoolShare(address from, uint256 amount) public {
vm.mockCall(address(this), abi.encodeWithSignature('_pullPoolShare(address,uint256)', from, amount), abi.encode());
}

function _pullPoolShare(address from, uint256 amount) internal override {
(bool _success, bytes memory _data) =
address(this).call(abi.encodeWithSignature('_pullPoolShare(address,uint256)', from, amount));

if (_success) return abi.decode(_data, ());
else return super._pullPoolShare(from, amount);
}

function call__pullPoolShare(address from, uint256 amount) public {
return _pullPoolShare(from, amount);
}

function expectCall__pullPoolShare(address from, uint256 amount) public {
vm.expectCall(address(this), abi.encodeWithSignature('_pullPoolShare(address,uint256)', from, amount));
}

function mock_call__pushPoolShare(address to, uint256 amount) public {
vm.mockCall(address(this), abi.encodeWithSignature('_pushPoolShare(address,uint256)', to, amount), abi.encode());
}

function _pushPoolShare(address to, uint256 amount) internal override {
(bool _success, bytes memory _data) =
address(this).call(abi.encodeWithSignature('_pushPoolShare(address,uint256)', to, amount));

if (_success) return abi.decode(_data, ());
else return super._pushPoolShare(to, amount);
}

function call__pushPoolShare(address to, uint256 amount) public {
return _pushPoolShare(to, amount);
}

function expectCall__pushPoolShare(address to, uint256 amount) public {
vm.expectCall(address(this), abi.encodeWithSignature('_pushPoolShare(address,uint256)', to, amount));
}

function mock_call__mintPoolShare(uint256 amount) public {
vm.mockCall(address(this), abi.encodeWithSignature('_mintPoolShare(uint256)', amount), abi.encode());
}

function _mintPoolShare(uint256 amount) internal override {
(bool _success, bytes memory _data) = address(this).call(abi.encodeWithSignature('_mintPoolShare(uint256)', amount));

if (_success) return abi.decode(_data, ());
else return super._mintPoolShare(amount);
}

function call__mintPoolShare(uint256 amount) public {
return _mintPoolShare(amount);
}

function expectCall__mintPoolShare(uint256 amount) public {
vm.expectCall(address(this), abi.encodeWithSignature('_mintPoolShare(uint256)', amount));
}

function mock_call__burnPoolShare(uint256 amount) public {
vm.mockCall(address(this), abi.encodeWithSignature('_burnPoolShare(uint256)', amount), abi.encode());
}

function _burnPoolShare(uint256 amount) internal override {
(bool _success, bytes memory _data) = address(this).call(abi.encodeWithSignature('_burnPoolShare(uint256)', amount));

if (_success) return abi.decode(_data, ());
else return super._burnPoolShare(amount);
}

function call__burnPoolShare(uint256 amount) public {
return _burnPoolShare(amount);
}

function expectCall__burnPoolShare(uint256 amount) public {
vm.expectCall(address(this), abi.encodeWithSignature('_burnPoolShare(uint256)', amount));
}

function mock_call__getLock(bytes32 value) public {
vm.mockCall(address(this), abi.encodeWithSignature('_getLock()'), abi.encode(value));
}
Expand All @@ -387,7 +464,7 @@ contract MockBCoWPool is BCoWPool, Test {
else return super._getLock();
}

function call__getLock() public returns (bytes32 value) {
function call__getLock() public view returns (bytes32 value) {
return _getLock();
}

Expand Down

0 comments on commit ca413a4

Please sign in to comment.