Skip to content

Commit

Permalink
fix: Fix as per SECFIN1-7
Browse files Browse the repository at this point in the history
  • Loading branch information
biga816 committed Jan 21, 2025
1 parent ac6704d commit 22f9ac5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
5 changes: 5 additions & 0 deletions contracts/PriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ contract PriceFeed is OwnableUpgradeable, CheckContract, BaseMath, IPriceFeed {
// Get an initial price from Chainlink to serve as first reference for lastGoodPrice
ChainlinkResponse memory chainlinkResponse = _getCurrentChainlinkResponse();

require(
!_chainlinkIsBroken(chainlinkResponse) && !_chainlinkIsFrozen(chainlinkResponse),
"PriceFeed: Chainlink must be working and current"
);

_storeChainlinkPrice(chainlinkResponse);
}

Expand Down
40 changes: 20 additions & 20 deletions test/PriceFeedTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,28 @@ const deploymentHelper = require("../utils/testDeploymentHelpers.js");
const testHelpers = require("../utils/testHelpers.js");
const th = testHelpers.TestHelper;

const { dec, toBN } = th;
const { dec, toBN, assertRevert } = th;

contract("PriceFeed", async () => {
let priceFeedTestnet;
let priceFeed;
let invalidAddressPriceFeed;
let mockChainlink;

let mockTellor;
let tellorCaller;

beforeEach(async () => {
const nonPayableFactory = await deploymentHelper.getFactory("NonPayable");
const priceFeedTestnetFactory = await deploymentHelper.getFactory("PriceFeedTestnet");
const priceFeedTesterFactory = await deploymentHelper.getFactory("PriceFeedTester");
const mockChainlinkFactory = await deploymentHelper.getFactory("MockAggregator");
const mockTellorFactory = await deploymentHelper.getFactory("MockTellor");
const tellorCallerFactory = await deploymentHelper.getFactory("TellorCaller");

const dumbContract = await nonPayableFactory.deploy();
priceFeedTestnet = await priceFeedTestnetFactory.deploy();
mockChainlink = await mockChainlinkFactory.deploy();
mockTellor = await mockTellorFactory.deploy();
tellorCaller = await tellorCallerFactory.deploy(mockTellor.address);

priceFeed = await deploymentHelper.deployProxy(
priceFeedTesterFactory,
[mockChainlink.address, tellorCaller.address],
[th.PRICE_FEED_TIMEOUT],
);
invalidAddressPriceFeed = await deploymentHelper.deployProxy(
priceFeedTesterFactory,
[dumbContract.address, dumbContract.address],
[th.PRICE_FEED_TIMEOUT],
);

// Set Chainlink latest and prev round Id's to non-zero
await mockChainlink.setLatestRoundId(3);
await mockChainlink.setPrevRoundId(2);
Expand All @@ -50,6 +36,12 @@ contract("PriceFeed", async () => {
const now = await th.getLatestBlockTimestamp(web3);
await mockChainlink.setUpdateTime(now);
await mockTellor.setUpdateTime(now);

priceFeed = await deploymentHelper.deployProxy(
priceFeedTesterFactory,
[mockChainlink.address, tellorCaller.address],
[th.PRICE_FEED_TIMEOUT],
);
});

describe("PriceFeed internal testing contract", async (accounts) => {
Expand All @@ -65,11 +57,19 @@ contract("PriceFeed", async () => {
});

describe("Mainnet PriceFeed setup", async (accounts) => {
it("status should be bothOraclesUntrusted on contract with wrong chainlink address set", async () => {
await invalidAddressPriceFeed.fetchPrice();
const status = await invalidAddressPriceFeed.status();

assert.equal(status.toString(), "2");
it("PriceFeed deployment should fail with wrong chainlink address set", async () => {
const nonPayableFactory = await deploymentHelper.getFactory("NonPayable");
const priceFeedTesterFactory = await deploymentHelper.getFactory("PriceFeedTester");

const dumbContract = await nonPayableFactory.deploy();

await assertRevert(
deploymentHelper.deployProxy(
priceFeedTesterFactory,
[dumbContract.address, dumbContract.address],
[th.PRICE_FEED_TIMEOUT],
),
);
});
});

Expand Down

0 comments on commit 22f9ac5

Please sign in to comment.