Skip to content

Commit

Permalink
fix: fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
web3rover committed May 8, 2024
1 parent 6f47ec2 commit 0206218
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 15 deletions.
2 changes: 1 addition & 1 deletion contracts/oracles/SFrxETHOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ contract SFrxETHOracle is CorrelatedTokenOracle {
uint256 averagePrice = (priceLow + priceHigh) / 2;

// return (1 / averagePrice) as the average price is in sfraxETH
return EXP_SCALE * 2 / averagePrice;
return (EXP_SCALE ** 2) / averagePrice;
}
}
23 changes: 23 additions & 0 deletions contracts/oracles/mocks/MockSFrxEthFraxOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.25;

import "../../interfaces/ISfrxEthFraxOracle.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MockSfrxEthFraxOracle is ISfrxEthFraxOracle, Ownable {
bool public isBadData;
uint256 public priceLow;
uint256 public priceHigh;

constructor() Ownable() {}

function setPrices(bool _isBadData, uint256 _priceLow, uint256 _priceHigh) external onlyOwner {
isBadData = _isBadData;
priceLow = _priceLow;
priceHigh = _priceHigh;
}

function getPrices() external view override returns (bool, uint256, uint256) {
return (isBadData, priceLow, priceHigh);
}
}
1 change: 1 addition & 0 deletions helpers/deploymentConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export const ADDRESSES: PreconfiguredAddresses = {
PTOracle: "0xbbd487268A295531d299c125F3e5f749884A3e30",
EtherFiLiquidityPool: "0x308861A430be4cce5502d0A12724771Fc6DaF216",
WETH: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
SfrxEthFraxOracle: "0x3d3D868522b5a4035ADcb67BF0846D61597A6a6F"
},
opbnbtestnet: {
vBNBAddress: ethers.constants.AddressZero,
Expand Down
40 changes: 26 additions & 14 deletions test/SFrxETHOracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,61 @@ import { parseUnits } from "ethers/lib/utils";
import { ethers } from "hardhat";

import { ADDRESSES } from "../helpers/deploymentConfig";
import { BEP20Harness, ISfrxETH, ResilientOracleInterface } from "../typechain-types";
import { BEP20Harness, ISfrxEthFraxOracle, ResilientOracleInterface } from "../typechain-types";

Check failure on line 7 in test/SFrxETHOracle.ts

View workflow job for this annotation

GitHub Actions / Lint

'ISfrxEthFraxOracle' is defined but never used. Allowed unused vars must match /_/u
import { addr0000 } from "./utils/data";

const { expect } = chai;
chai.use(smock.matchers);

const { sfrxETH, frxETH } = ADDRESSES.ethereum;
const { sfrxETH, FRAX } = ADDRESSES.ethereum;
const ETH_USD_PRICE = parseUnits("3100", 18); // 3100 USD for 1 ETH

describe("SFrxETHOracle unit tests", () => {
let resilientOracleMock;
let sfrxETHMock;
let SFrxETHOracleFactory;
let SFrxETHOracle;
let frxETHMock;
let fraxMock;
let sfrxEthFraxOracleMock;
before(async () => {
// To initialize the provider we need to hit the node with any request
await ethers.getSigners();
resilientOracleMock = await smock.fake<ResilientOracleInterface>("ResilientOracleInterface");

sfrxETHMock = await smock.fake<ISfrxETH>("ISfrxETH", { address: sfrxETH });
sfrxETHMock.convertToAssets.returns(parseUnits("1.076546447254363344", 18));
sfrxETHMock.decimals.returns(18);
// deploy MockSfrxEthFraxOracle
const sfrxEthFraxOracleMockFactory = await ethers.getContractFactory("MockSfrxEthFraxOracle");
sfrxEthFraxOracleMock = await sfrxEthFraxOracleMockFactory.deploy();
await sfrxEthFraxOracleMock.deployed();
await sfrxEthFraxOracleMock.setPrices(false, parseUnits("0.000306430391670677", 18), parseUnits("0.000309520800596522", 18));

fraxMock = await smock.fake<BEP20Harness>("BEP20Harness", { address: FRAX });
fraxMock.decimals.returns(18);

frxETHMock = await smock.fake<BEP20Harness>("BEP20Harness", { address: frxETH });
frxETHMock.decimals.returns(18);
sfrxETHMock = await smock.fake<BEP20Harness>("BEP20Harness", { address: sfrxETH });
sfrxETHMock.decimals.returns(18);

SFrxETHOracleFactory = await ethers.getContractFactory("SFrxETHOracle");
});

describe("deployment", () => {
it("revert if frxETH address is 0", async () => {
await expect(SFrxETHOracleFactory.deploy(sfrxETHMock.address, addr0000, resilientOracleMock.address)).to.be
it("revert if frax address is 0", async () => {
await expect(SFrxETHOracleFactory.deploy(sfrxEthFraxOracleMock.address, sfrxETHMock.address, addr0000, resilientOracleMock.address)).to.be
.reverted;
});
it("revert if sfrxETH address is 0", async () => {
await expect(SFrxETHOracleFactory.deploy(addr0000, frxETHMock.address, resilientOracleMock.address)).to.be
await expect(SFrxETHOracleFactory.deploy(sfrxEthFraxOracleMock.address, addr0000, fraxMock.address, resilientOracleMock.address)).to.be
.reverted;
});

it("revert if sfrxEthFraxOracle address is 0", async () => {
await expect(SFrxETHOracleFactory.deploy(addr0000, sfrxETHMock.address, fraxMock.address, resilientOracleMock.address)).to.be
.reverted;
});
it("should deploy contract", async () => {
SFrxETHOracle = await SFrxETHOracleFactory.deploy(
sfrxEthFraxOracleMock.address,
sfrxETHMock.address,
frxETHMock.address,
fraxMock.address,
resilientOracleMock.address,
);
});
Expand All @@ -61,9 +73,9 @@ describe("SFrxETHOracle unit tests", () => {
});

it("should get correct price of sfrxETH", async () => {
resilientOracleMock.getPrice.returns(ETH_USD_PRICE);
resilientOracleMock.getPrice.returns(parseUnits("0.99838881", 18));
const price = await SFrxETHOracle.getPrice(sfrxETHMock.address);
expect(price).to.equal(parseUnits("3337.2939864885263664", 18));
expect(price).to.equal(parseUnits("3241.778967340326445028", 18));
});
});
});

0 comments on commit 0206218

Please sign in to comment.