Skip to content

Commit

Permalink
test: yield repo and updated heart
Browse files Browse the repository at this point in the history
  • Loading branch information
Oighty committed Sep 18, 2024
1 parent c6d8c15 commit 0f5ba5d
Show file tree
Hide file tree
Showing 6 changed files with 890 additions and 50 deletions.
30 changes: 30 additions & 0 deletions src/test/mocks/MockClearinghouse.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;

import {ERC20} from "solmate/tokens/ERC20.sol";
import {ERC4626} from "solmate/mixins/ERC4626.sol";

// mock clearinghouse to use with testing the yieldRepo contract
// most functions / variables are omitted
contract MockClearinghouse {
ERC20 public reserve;
ERC4626 public wrappedReserve;
uint256 public principalReceivables;

constructor(address _reserve, address _wrappedReserve) {
reserve = ERC20(_reserve);
wrappedReserve = ERC4626(_wrappedReserve);
}

function setPrincipalReceivables(uint256 _principalReceivables) external {
principalReceivables = _principalReceivables;
}

function withdrawReserve(uint256 _amount) external {
reserve.transfer(msg.sender, _amount);
}

function withdrawWrappedReserve(uint256 _amount) external {
wrappedReserve.transfer(msg.sender, _amount);
}
}
4 changes: 4 additions & 0 deletions src/test/mocks/MockOhm.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ contract MockOhm is ERC20 {
_mint(to, value);
}

function burn(uint256 value) public virtual {
_burn(msg.sender, value);
}

function burnFrom(address from, uint256 value) public virtual {
uint256 currentAllowance = allowance[from][msg.sender];
require(currentAllowance >= value, "ERC20: burn amount exceeds allowance");
Expand Down
29 changes: 29 additions & 0 deletions src/test/mocks/MockYieldRepo.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;

import {IYieldRepo} from "../../policies/interfaces/IYieldRepo.sol";

contract MockYieldRepo is IYieldRepo {
uint48 public epoch;
bool public isShutdown;

function endEpoch() external override {
// do nothing
}

function shutdown() external {
isShutdown = true;
}

function getReserveBalance() external pure override returns (uint256) {
return 0;
}

function getNextYield() external pure override returns (uint256) {
return 0;
}

function getOhmBalanceAndBacking() external pure override returns (uint256, uint256) {
return (0, 0);
}
}
37 changes: 36 additions & 1 deletion src/test/policies/Heart.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ import {ROLESv1} from "modules/ROLES/ROLES.v1.sol";
import {RolesAdmin} from "policies/RolesAdmin.sol";
import {ZeroDistributor} from "policies/Distributor/ZeroDistributor.sol";
import {MockStakingZD} from "test/mocks/MockStakingForZD.sol";
import {MockYieldRepo} from "test/mocks/MockYieldRepo.sol";

import {FullMath} from "libraries/FullMath.sol";

import "src/Kernel.sol";

import {OlympusHeart} from "policies/Heart.sol";
import {OlympusHeart, IHeart} from "policies/Heart.sol";

import {IOperator} from "policies/interfaces/IOperator.sol";
import {IDistributor} from "policies/interfaces/IDistributor.sol";
import {IYieldRepo} from "policies/interfaces/IYieldRepo.sol";

/**
* @notice Mock Operator to test Heart
Expand Down Expand Up @@ -73,6 +75,8 @@ contract HeartTest is Test {
MockStakingZD internal staking;
ZeroDistributor internal distributor;

MockYieldRepo internal yieldRepo;

uint48 internal constant PRICE_FREQUENCY = uint48(8 hours);

// MINTR
Expand Down Expand Up @@ -121,11 +125,15 @@ contract HeartTest is Test {
distributor = new ZeroDistributor(address(staking));
staking.setDistributor(address(distributor));

// Deploy mock yieldRepo
yieldRepo = new MockYieldRepo();

// Deploy heart
heart = new OlympusHeart(
kernel,
IOperator(address(operator)),
IDistributor(address(distributor)),
IYieldRepo(address(yieldRepo)),
uint256(10e9), // max reward = 10 reward tokens
uint48(12 * 50) // auction duration = 5 minutes (50 blocks on ETH mainnet)
);
Expand All @@ -151,6 +159,9 @@ contract HeartTest is Test {
// Heart ROLES
rolesAdmin.grantRole("heart_admin", policy);
}

// Do initial beat
heart.beat();
}

// ======== SETUP DEPENDENCIES ======= //
Expand All @@ -169,6 +180,30 @@ contract HeartTest is Test {
assertEq(fromKeycode(deps[2]), fromKeycode(expectedDeps[2]));
}

function testRevert_configureDependencies_invalidFrequency() public {
// Deploy mock staking with different frequency
staking = new MockStakingZD(7 hours, 0, block.timestamp);
distributor = new ZeroDistributor(address(staking));
staking.setDistributor(address(distributor));

// Deploy heart
heart = new OlympusHeart(
kernel,
IOperator(address(operator)),
IDistributor(address(distributor)),
IYieldRepo(address(yieldRepo)),
uint256(10e9), // max reward = 10 reward tokens
uint48(12 * 50) // auction duration = 5 minutes (50 blocks on ETH mainnet)
);

vm.startPrank(address(kernel));
// Since the staking frequency is different, the call to configureDependencies reverts
bytes memory err = abi.encodeWithSelector(IHeart.Heart_InvalidFrequency.selector);
vm.expectRevert(err);
heart.configureDependencies();
vm.stopPrank();
}

function test_requestPermissions() public {
Permissions[] memory expectedPerms = new Permissions[](3);

Expand Down
Loading

0 comments on commit 0f5ba5d

Please sign in to comment.