From 46bfc75dd3824e8c32f55dc96eb7f5dcc6d87cf0 Mon Sep 17 00:00:00 2001 From: sanchaymittal Date: Wed, 15 May 2024 02:02:34 +0400 Subject: [PATCH] feat: setup mock contracts --- test/smock/MockQWManager.sol | 34 +++++++++++++++++++++++++++++++++ test/smock/MockQWRegistry.sol | 21 ++++++++++++++++++++ test/smock/SmockHelper.sol | 20 +++++++++++++++++++ test/smock/child/MockQWAave.sol | 21 ++++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 test/smock/MockQWManager.sol create mode 100644 test/smock/MockQWRegistry.sol create mode 100644 test/smock/SmockHelper.sol create mode 100644 test/smock/child/MockQWAave.sol diff --git a/test/smock/MockQWManager.sol b/test/smock/MockQWManager.sol new file mode 100644 index 0000000..f4a4217 --- /dev/null +++ b/test/smock/MockQWManager.sol @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: APACHE +pragma solidity ^0.8.0; + +import {IERC20, IQWChild, IQWManager, IQWRegistry, QWManager, QWRegistry} from '../../src/contracts/QWManager.sol'; +import {Test} from 'forge-std/Test.sol'; + +contract MockQWManager is QWManager, Test { + constructor() QWManager() {} + + function mock_call_execute( + address[] memory _targetQwChild, + bytes[] memory _callData, + address _tokenAddress, + uint256 _amount + ) public { + vm.mockCall( + address(this), + abi.encodeWithSignature( + 'execute(address[],bytes[],address,uint256)', _targetQwChild, _callData, _tokenAddress, _amount + ), + abi.encode() + ); + } + + function mock_call_close(address[] memory _targetQwChild, bytes[] memory _callData) public { + vm.mockCall( + address(this), abi.encodeWithSignature('close(address[],bytes[])', _targetQwChild, _callData), abi.encode() + ); + } + + function mock_call_withdraw(address user, uint256 amount) public { + vm.mockCall(address(this), abi.encodeWithSignature('withdraw(address,uint256)', user, amount), abi.encode()); + } +} diff --git a/test/smock/MockQWRegistry.sol b/test/smock/MockQWRegistry.sol new file mode 100644 index 0000000..f44d318 --- /dev/null +++ b/test/smock/MockQWRegistry.sol @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import {IQWChild, IQWRegistry, QWRegistry} from '../../src/contracts/QWRegistry.sol'; +import {Test} from 'forge-std/Test.sol'; + +contract MockQWRegistry is QWRegistry, Test { + function set_whitelist(address _key0, bool _value) public { + whitelist[_key0] = _value; + } + + function mock_call_whitelist(address _key0, bool _value) public { + vm.mockCall(address(this), abi.encodeWithSignature('whitelist(address)', _key0), abi.encode(_value)); + } + + constructor(address _qwManager) QWRegistry(_qwManager) {} + + function mock_call_registerChild(address _child) public { + vm.mockCall(address(this), abi.encodeWithSignature('registerChild(address)', _child), abi.encode()); + } +} diff --git a/test/smock/SmockHelper.sol b/test/smock/SmockHelper.sol new file mode 100644 index 0000000..442961e --- /dev/null +++ b/test/smock/SmockHelper.sol @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import {Test} from 'forge-std/Test.sol'; + +contract SmockHelper is Test { + function deployMock( + string memory _label, + bytes memory _creationCode, + bytes memory _encodedArgs + ) internal returns (address _deployed) { + bytes memory _bytecode = abi.encodePacked(_creationCode, _encodedArgs); + assembly { + mstore(0x0, _creationCode) + _deployed := create2(0, add(_bytecode, 0x20), mload(_bytecode), 'Wonderland') + } + vm.label(_deployed, _label); + vm.allowCheatcodes(_deployed); + } +} diff --git a/test/smock/child/MockQWAave.sol b/test/smock/child/MockQWAave.sol new file mode 100644 index 0000000..a16800d --- /dev/null +++ b/test/smock/child/MockQWAave.sol @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import {IERC20, IPool, IQWChild, QWAave} from '../../../src/contracts/child/QWAave.sol'; +import {Test} from 'forge-std/Test.sol'; + +contract MockQWAave is QWAave, Test { + constructor(address _qwManager, address _pool) QWAave(_qwManager, _pool) {} + + function mock_call_create(bytes memory _callData, address _tokenAddress, uint256 _amount, bool success) public { + vm.mockCall( + address(this), + abi.encodeWithSignature('create(bytes,address,uint256)', _callData, _tokenAddress, _amount), + abi.encode(success) + ); + } + + function mock_call_close(bytes memory _callData, bool success) public { + vm.mockCall(address(this), abi.encodeWithSignature('close(bytes)', _callData), abi.encode(success)); + } +}