Skip to content

Commit

Permalink
feat: setup mock contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
sanchaymittal committed May 14, 2024
1 parent 7e9ae29 commit 46bfc75
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/smock/MockQWManager.sol
Original file line number Diff line number Diff line change
@@ -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';

Check warning on line 4 in test/smock/MockQWManager.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "IERC20" is unused

Check warning on line 4 in test/smock/MockQWManager.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "IQWChild" is unused

Check warning on line 4 in test/smock/MockQWManager.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "IQWManager" is unused

Check warning on line 4 in test/smock/MockQWManager.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "IQWRegistry" is unused

Check warning on line 4 in test/smock/MockQWManager.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "QWRegistry" is unused
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());
}
}
21 changes: 21 additions & 0 deletions test/smock/MockQWRegistry.sol
Original file line number Diff line number Diff line change
@@ -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());
}
}
20 changes: 20 additions & 0 deletions test/smock/SmockHelper.sol
Original file line number Diff line number Diff line change
@@ -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);
}
}
21 changes: 21 additions & 0 deletions test/smock/child/MockQWAave.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IERC20, IPool, IQWChild, QWAave} from '../../../src/contracts/child/QWAave.sol';

Check warning on line 4 in test/smock/child/MockQWAave.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "IERC20" is unused

Check warning on line 4 in test/smock/child/MockQWAave.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "IPool" is unused

Check warning on line 4 in test/smock/child/MockQWAave.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Variable "IQWChild" is unused
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 {

Check warning on line 10 in test/smock/child/MockQWAave.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Function name must be in mixedCase
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 {

Check warning on line 18 in test/smock/child/MockQWAave.sol

View workflow job for this annotation

GitHub Actions / Lint Commit Messages

Function name must be in mixedCase
vm.mockCall(address(this), abi.encodeWithSignature('close(bytes)', _callData), abi.encode(success));
}
}

0 comments on commit 46bfc75

Please sign in to comment.