Skip to content

Commit

Permalink
test: create mock file for smock, fix TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
0xAustrian committed Aug 27, 2024
1 parent 9a4d408 commit b97cbd3
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"/////// deploy-test ///////": "echo 'deploy test scripts'",
"create-profile": "npx hardhat run scripts/test/createProfile.ts --network",
"create-pool": "npx hardhat run scripts/test/createPool.ts --network",
"smock": "smock-foundry --contracts contracts/core"
"smock": "smock-foundry --contracts contracts/core --contracts test/utils/mocks/"
},
"devDependencies": {
"@matterlabs/hardhat-zksync-deploy": "^1.2.1",
Expand Down
34 changes: 19 additions & 15 deletions test/foundry/core/AlloUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
pragma solidity ^0.8.19;

import {Test} from "forge-std/Test.sol";
import {MockAllo} from "smock/MockAllo.sol";
import {MockMockAllo} from "test/smock/MockMockAllo.sol";
import {Errors} from "contracts/core/libraries/Errors.sol";
import {Metadata} from "contracts/core/libraries/Metadata.sol";
import {IBaseStrategy} from "contracts/core/interfaces/IBaseStrategy.sol";
import {ClonesUpgradeable} from "openzeppelin-contracts-upgradeable/contracts/proxy/ClonesUpgradeable.sol";
import {Ownable} from "solady/auth/Ownable.sol";

contract Allo is Test {
MockAllo allo;
MockMockAllo allo;

event PoolMetadataUpdated(uint256 indexed poolId, Metadata metadata);

function setUp() public virtual {
allo = new MockAllo();
allo = new MockMockAllo();
}

function test_InitializeGivenUpgradeVersionIsCorrect(
Expand All @@ -33,7 +33,7 @@ contract Allo is Test {
allo.mock_call__updateTrustedForwarder(_trustedForwarder);

// it should call _initializeOwner
// TODO: expect _initializeOwner
allo.expectCall__initializeOwner(_owner);

// it should call _updateRegistry
allo.expectCall__updateRegistry(_registry);
Expand Down Expand Up @@ -193,8 +193,8 @@ contract Allo is Test {
allo.updatePoolMetadata(_poolId, _metadata);

// it should update metadata
assertEq(allo.call_pools(_poolId).metadata.pointer, _metadata.pointer);
assertEq(allo.call_pools(_poolId).metadata.protocol, _metadata.protocol);
assertEq(allo.getPool(_poolId).metadata.pointer, _metadata.pointer);
assertEq(allo.getPool(_poolId).metadata.protocol, _metadata.protocol);
}

function test_UpdateRegistryRevertWhen_SenderIsNotOwner(address _caller, address _registry) external {
Expand Down Expand Up @@ -347,8 +347,12 @@ contract Allo is Test {
// it should call _checkOnlyPoolAdmin
allo.expectCall__checkOnlyPoolAdmin(_poolId, address(this));

bytes32 _role = allo.getPool(_poolId).managerRole;

// it should call _revokeRole
// TODO: expect _revokeRole
for (uint256 i = 0; i < _managers.length; i++) {
allo.expectCall__revokeRole(_role, _managers[i]);
}

allo.removePoolManagers(_poolId, _managers);
}
Expand All @@ -358,29 +362,29 @@ contract Allo is Test {
address[] memory _managers
) external {
vm.skip(true);
for (uint256 i = 0; i < _poolIds.length; i++) {
allo.mock_call_addPoolManagers(_poolIds[0], _managers);
}
// for (uint256 i = 0; i < _poolIds.length; i++) {
// allo.mock_call_addPoolManagers(_poolIds[0], _managers);
// }

// it should call addPoolManagers
// TODO: expect addPoolManagers

allo.addPoolManagersInMultiplePools(_poolIds, _managers);
// allo.addPoolManagersInMultiplePools(_poolIds, _managers);
}

function test_RemovePoolManagersInMultiplePoolsGivenSenderIsAdminOfAllPoolIds(
uint256[] memory _poolIds,
address[] memory _managers
) external {
vm.skip(true);
for (uint256 i = 0; i < _poolIds.length; i++) {
allo.mock_call_removePoolManagers(_poolIds[0], _managers);
}
// for (uint256 i = 0; i < _poolIds.length; i++) {
// allo.mock_call_removePoolManagers(_poolIds[0], _managers);
// }

// it should call removePoolManagers
// TODO: expect removePoolManagers

allo.removePoolManagersInMultiplePools(_poolIds, _managers);
// allo.removePoolManagersInMultiplePools(_poolIds, _managers);
}

function test_RecoverFundsRevertWhen_SenderIsNotOwner() external {
Expand Down
101 changes: 101 additions & 0 deletions test/utils/mocks/MockAllo.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;

import {Allo} from "contracts/core/Allo.sol";
import {IBaseStrategy} from "contracts/core/interfaces/IBaseStrategy.sol";
import {Metadata} from "contracts/core/libraries/Metadata.sol";

contract MockAllo is Allo {
constructor() Allo() {}

function _initializeOwner(address newOwner) internal override virtual {
super._initializeOwner(newOwner);
}

function _revokeRole(bytes32 role, address account) internal override virtual {
super._revokeRole(role, account);
}

function _checkOnlyPoolManager(uint256 _poolId, address _address) internal view override virtual {
super._checkOnlyPoolManager(_poolId, _address);
}

function _checkOnlyPoolAdmin(uint256 _poolId, address _address) internal view override virtual {
super._checkOnlyPoolAdmin(_poolId, _address);
}

function _createPool(
address _creator,
uint256 _msgValue,
bytes32 _profileId,
IBaseStrategy _strategy,
bytes memory _initStrategyData,
address _token,
uint256 _amount,
Metadata memory _metadata,
address[] memory _managers
) internal override virtual returns (uint256 poolId) {
return super._createPool(
_creator,
_msgValue,
_profileId,
_strategy,
_initStrategyData,
_token,
_amount,
_metadata,
_managers
);
}

function _allocate(
uint256 _poolId,
address[] memory _recipients,
uint256[] memory _amounts,
bytes memory _data,
uint256 _value,
address _allocator
) internal virtual override {
super._allocate(_poolId, _recipients, _amounts, _data, _value, _allocator);
}

function _fundPool(uint256 _amount, address _funder, uint256 _poolId, IBaseStrategy _strategy) internal virtual override {
super._fundPool(_amount, _funder, _poolId, _strategy);
}

function _isPoolAdmin(uint256 _poolId, address _address) internal view virtual override returns (bool) {
return super._isPoolAdmin(_poolId, _address);
}

function _isPoolManager(uint256 _poolId, address _address) internal view virtual override returns (bool) {
return super._isPoolManager(_poolId, _address);
}

function _updateRegistry(address _registry) internal virtual override {
super._updateRegistry(_registry);
}

function _updateTreasury(address payable _treasury) internal virtual override {
super._updateTreasury(_treasury);
}

function _updatePercentFee(uint256 _percentFee) internal virtual override {
super._updatePercentFee(_percentFee);
}

function _updateBaseFee(uint256 _baseFee) internal virtual override {
super._updateBaseFee(_baseFee);
}

function _updateTrustedForwarder(address __trustedForwarder) internal virtual override {
super._updateTrustedForwarder(__trustedForwarder);
}

function _addPoolManager(uint256 _poolId, address _manager) internal virtual override {
super._addPoolManager(_poolId, _manager);
}

function _msgSender() internal view virtual override returns (address) {
return super._msgSender();
}
}

0 comments on commit b97cbd3

Please sign in to comment.