This repository has been archived by the owner on Aug 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d978fb0
commit 2e02584
Showing
2 changed files
with
160 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
contracts/test/oracles/default/MasterPriceOracleTest.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity >=0.8.0; | ||
|
||
import { BaseTest } from "../../config/BaseTest.t.sol"; | ||
import { MasterPriceOracle } from "../../../oracles/MasterPriceOracle.sol"; | ||
import { BasePriceOracle } from "../../../oracles/BasePriceOracle.sol"; | ||
import { ICErc20 } from "../../../compound/CTokenInterfaces.sol"; | ||
import { SimplePriceOracle } from "../../../oracles/default/SimplePriceOracle.sol"; | ||
import { TransparentUpgradeableProxy } from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol"; | ||
|
||
contract MasterPriceOracleTest is BaseTest { | ||
MasterPriceOracle mpo; | ||
SimplePriceOracle mainOracle; | ||
SimplePriceOracle fallbackOracle; | ||
ICErc20 mockCToken; | ||
address someAdminAccount = address(94949); | ||
address ezETH = 0x2416092f143378750bb29b79eD961ab195CcEea5; | ||
address ionezETH = 0x59e710215d45F584f44c0FEe83DA6d43D762D857; | ||
|
||
function afterForkSetUp() internal override { | ||
MasterPriceOracle newMpo = new MasterPriceOracle(); | ||
SimplePriceOracle defaultOracle = new SimplePriceOracle(); | ||
|
||
address[] memory underlyings = new address[](0); | ||
BasePriceOracle[] memory oracles = new BasePriceOracle[](0); | ||
|
||
vm.prank(someAdminAccount); | ||
newMpo.initialize(underlyings, oracles, defaultOracle, someAdminAccount, true, address(0)); | ||
|
||
mpo = newMpo; | ||
|
||
SimplePriceOracle impl = new SimplePriceOracle(); | ||
vm.prank(address(someAdminAccount)); | ||
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy( | ||
address(impl), | ||
address(dpa), | ||
abi.encodePacked(impl.initialize.selector) | ||
); | ||
mainOracle = SimplePriceOracle(address(proxy)); | ||
|
||
SimplePriceOracle fallbackImpl = new SimplePriceOracle(); | ||
vm.prank(address(someAdminAccount)); | ||
TransparentUpgradeableProxy fallbackProxy = new TransparentUpgradeableProxy( | ||
address(fallbackImpl), | ||
address(dpa), | ||
abi.encodePacked(impl.initialize.selector) | ||
); | ||
fallbackOracle = SimplePriceOracle(address(fallbackProxy)); | ||
|
||
vm.startPrank(someAdminAccount); | ||
mainOracle.setDirectPrice(ezETH, 2000); | ||
fallbackOracle.setDirectPrice(ezETH, 2000); | ||
vm.stopPrank(); | ||
|
||
address[] memory tokens = new address[](1); | ||
tokens[0] = ezETH; | ||
|
||
BasePriceOracle[] memory oraclesToAdd = new BasePriceOracle[](1); | ||
oraclesToAdd[0] = BasePriceOracle(mainOracle); | ||
BasePriceOracle[] memory fallbackOraclesToAdd = new BasePriceOracle[](1); | ||
fallbackOraclesToAdd[0] = BasePriceOracle(fallbackOracle); | ||
|
||
vm.startPrank(someAdminAccount); | ||
mpo.add(tokens, oraclesToAdd); | ||
mpo.addFallbacks(tokens, fallbackOraclesToAdd); | ||
vm.stopPrank(); | ||
} | ||
|
||
function testGetUnderlyingPrice() public fork(MODE_MAINNET) { | ||
vm.prank(someAdminAccount); | ||
uint256 price = mpo.getUnderlyingPrice(ICErc20(ionezETH)); | ||
assertEq(price, 2000, "Price should match the mock price"); | ||
} | ||
|
||
function testGetUnderlyingPriceZero() public fork(MODE_MAINNET) { | ||
vm.prank(someAdminAccount); | ||
mainOracle.setDirectPrice(ezETH, 0); | ||
uint256 price = mpo.getUnderlyingPrice(ICErc20(ionezETH)); | ||
assertEq(price, 2000, "Price should match the mock price"); | ||
} | ||
|
||
function testGetUnderlyingPriceZeroAddressOracle() public fork(MODE_MAINNET) { | ||
address[] memory tokens = new address[](1); | ||
tokens[0] = ezETH; | ||
|
||
BasePriceOracle[] memory oraclesToAdd = new BasePriceOracle[](1); | ||
oraclesToAdd[0] = BasePriceOracle(0x0000000000000000000000000000000000000000); | ||
|
||
vm.prank(someAdminAccount); | ||
mpo.add(tokens, oraclesToAdd); | ||
|
||
uint256 price = mpo.getUnderlyingPrice(ICErc20(ionezETH)); | ||
assertEq(price, 2000, "Price should match the mock price"); | ||
} | ||
|
||
function testGetUnderlyingPriceOracleReverts() public fork(MODE_MAINNET) { | ||
revert("TODO"); | ||
} | ||
|
||
function testPrice() public fork(MODE_MAINNET) { | ||
revert("TODO"); | ||
} | ||
|
||
function testPriceZero() public fork(MODE_MAINNET) { | ||
revert("TODO"); | ||
} | ||
|
||
function testPriceZeroAddressOracle() public fork(MODE_MAINNET) { | ||
revert("TODO"); | ||
} | ||
|
||
function testPriceOracleReverts() public fork(MODE_MAINNET) { | ||
revert("TODO"); | ||
} | ||
} |