Skip to content

Commit

Permalink
fix: sfe-03
Browse files Browse the repository at this point in the history
  • Loading branch information
web3rover committed May 16, 2024
1 parent 6130942 commit b24ef72
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
2 changes: 2 additions & 0 deletions contracts/oracles/SFrxETHOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ contract SFrxETHOracle is AccessControlledV8 {
ensureNonzeroAddress(_sfrxETH);
SFRXETH_FRAX_ORACLE = ISfrxEthFraxOracle(_sfrxEthFraxOracle);
SFRXETH = _sfrxETH;

_disableInitializers();
}

/**
Expand Down
42 changes: 27 additions & 15 deletions test/SFrxETHOracle.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { smock } from "@defi-wonderland/smock";
import chai from "chai";
import { parseUnits } from "ethers/lib/utils";
import { ethers } from "hardhat";
import { ethers, upgrades } from "hardhat";

import { ADDRESSES } from "../helpers/deploymentConfig";
import { AccessControlManager, BEP20Harness } from "../typechain-types";
import { AccessControlManager, BEP20Harness, SFrxETHOracle } from "../typechain-types";
import { addr0000 } from "./utils/data";

const { expect } = chai;
Expand All @@ -15,7 +15,7 @@ const { sfrxETH } = ADDRESSES.ethereum;
describe("SFrxETHOracle unit tests", () => {
let sfrxETHMock;
let SFrxETHOracleFactory;
let SFrxETHOracle;
let SFrxETHOracleContract;
let sfrxEthFraxOracleMock;
let fakeAccessControlManager;
before(async () => {
Expand Down Expand Up @@ -43,37 +43,49 @@ describe("SFrxETHOracle unit tests", () => {

describe("deployment", () => {
it("revert if SfrxEthFraxOracle address is 0", async () => {
await expect(SFrxETHOracleFactory.deploy(addr0000, sfrxETHMock.address)).to.be.reverted;
await expect(
upgrades.deployProxy(SFrxETHOracleFactory, [fakeAccessControlManager.address], {
constructorArgs: [addr0000, sfrxETHMock.address],
}),
).to.be.reverted;
});
it("revert if sfrxETH address is 0", async () => {
await expect(SFrxETHOracleFactory.deploy(sfrxEthFraxOracleMock.address, addr0000)).to.be.reverted;
await expect(
upgrades.deployProxy(SFrxETHOracleFactory, [fakeAccessControlManager.address], {
constructorArgs: [sfrxEthFraxOracleMock.address, addr0000],
}),
).to.be.reverted;
});
it("should deploy contract", async () => {
SFrxETHOracle = await SFrxETHOracleFactory.deploy(sfrxEthFraxOracleMock.address, sfrxETHMock.address);

await SFrxETHOracle.initialize(fakeAccessControlManager.address);
SFrxETHOracleContract = <SFrxETHOracle>await upgrades.deployProxy(
SFrxETHOracleFactory,
[fakeAccessControlManager.address],
{
constructorArgs: [sfrxEthFraxOracleMock.address, sfrxETHMock.address],
},
);
});
});

describe("getPrice", () => {
it("revert if address is not valid sfrxETH address", async () => {
await expect(SFrxETHOracle.getPrice(addr0000)).to.be.revertedWithCustomError(
SFrxETHOracle,
await expect(SFrxETHOracleContract.getPrice(addr0000)).to.be.revertedWithCustomError(
SFrxETHOracleContract,
"InvalidTokenAddress",
);
});

it("revert if price difference is more than allowed", async () => {
await SFrxETHOracle.setMaxAllowedPriceDifference(parseUnits("1", 18));
await expect(SFrxETHOracle.getPrice(sfrxETHMock.address)).to.be.revertedWithCustomError(
SFrxETHOracle,
await SFrxETHOracleContract.setMaxAllowedPriceDifference(parseUnits("1", 18));
await expect(SFrxETHOracleContract.getPrice(sfrxETHMock.address)).to.be.revertedWithCustomError(
SFrxETHOracleContract,
"PriceDifferenceExceeded",
);
});

it("should get correct price of sfrxETH", async () => {
await SFrxETHOracle.setMaxAllowedPriceDifference(parseUnits("300", 18));
const price = await SFrxETHOracle.getPrice(sfrxETHMock.address);
await SFrxETHOracleContract.setMaxAllowedPriceDifference(parseUnits("300", 18));
const price = await SFrxETHOracleContract.getPrice(sfrxETHMock.address);
expect(price).to.equal(parseUnits("3247.092258084175122617", 18));
});
});
Expand Down

0 comments on commit b24ef72

Please sign in to comment.