Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
xdev10 committed Jul 11, 2024
1 parent 626093e commit 94f7089
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 23 deletions.
3 changes: 2 additions & 1 deletion contracts/oracle/FastPriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ contract FastPriceFeed is ISecondaryPriceFeed, IFastPriceFeed, Governable {
uint256 _maxPriceUpdateDelay,
uint256 _minBlockInterval,
uint256 _maxDeviationBasisPoints,
address _fastPriceEvents,
address _vaultPriceFeed,
address _fastPriceEvents,
address _tokenManager
) public {
require(_priceDuration <= MAX_PRICE_DURATION, "FastPriceFeed: invalid _priceDuration");
Expand Down Expand Up @@ -340,6 +340,7 @@ contract FastPriceFeed is ISecondaryPriceFeed, IFastPriceFeed, Governable {
_setLastUpdatedValues();

uint256 fee = pyth.getUpdateFee(priceUpdateData);
require(msg.value >= fee, "insufficient value");
pyth.updatePriceFeeds{ value: fee }(priceUpdateData);

uint256 tokenCount = tokens.length;
Expand Down
46 changes: 34 additions & 12 deletions test/core/PositionRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ describe("PositionRouter", function () {
const [wallet, positionKeeper, minter, user0, user1, user2, user3, user4, tokenManager, mintReceiver, signer0, signer1, updater0, updater1] = provider.getWallets()
const depositFee = 50
const minExecutionFee = 4000
const updateFee = "1000000000000"

let bnbFeedId = ethers.utils.keccak256("0x01")
let btcFeedId = ethers.utils.keccak256("0x02")
let ethFeedId = ethers.utils.keccak256("0x03")

let vault
let timelock
let usdg
Expand All @@ -31,6 +37,7 @@ describe("PositionRouter", function () {
let daiPriceFeed
let distributor0
let yieldTracker0
let mockPyth
let fastPriceFeed
let fastPriceEvents
let shortsTracker
Expand Down Expand Up @@ -117,18 +124,26 @@ describe("PositionRouter", function () {
await vault.setGov(timelock.address)

fastPriceEvents = await deployContract("FastPriceEvents", [])
mockPyth = await deployContract("MockPyth", [])
fastPriceFeed = await deployContract("FastPriceFeed", [
mockPyth.address, // _pyth
5 * 60, // _priceDuration
120 * 60, // _maxPriceUpdateDelay
2, // _minBlockInterval
250, // _maxDeviationBasisPoints
vaultPriceFeed.address, // _vaultPriceFeed
fastPriceEvents.address, // _fastPriceEvents
tokenManager.address // _tokenManager
])
await fastPriceFeed.initialize(2, [signer0.address, signer1.address], [updater0.address, updater1.address])
await fastPriceEvents.setIsPriceFeed(fastPriceFeed.address, true)
await fastPriceFeed.initialize(
2,
[signer0.address, signer1.address],
[updater0.address, updater1.address],
[bnb.address, btc.address, eth.address],
[bnbFeedId, btcFeedId, ethFeedId]
)

await fastPriceFeed.setVaultPriceFeed(vaultPriceFeed.address)
await fastPriceEvents.setIsPriceFeed(fastPriceFeed.address, true)
await vaultPriceFeed.setSecondaryPriceFeed(fastPriceFeed.address)
})

Expand Down Expand Up @@ -2339,29 +2354,36 @@ describe("PositionRouter", function () {
expect(queueLengths[2]).eq(7) // decreasePositionRequestKeysStart
expect(queueLengths[3]).eq(12) // decreasePositionRequestKeys.length

await fastPriceFeed.setMaxTimeDeviation(1000)
await positionRouter.setPositionKeeper(fastPriceFeed.address, true)

const blockTime = await getBlockTime(provider)

await expect(fastPriceFeed.connect(user0).setPricesWithBitsAndExecute(
bnbPriceFeed.setLatestAnswer(expandDecimals(801, 30))
btcPriceFeed.setLatestAnswer(expandDecimals(80_000, 30))
ethPriceFeed.setLatestAnswer(expandDecimals(5000, 30))

await mockPyth.setPrice(bnbFeedId, 801, 0, blockTime)
await mockPyth.setPrice(btcFeedId, 80_000, 0, blockTime)
await mockPyth.setPrice(ethFeedId, 5000, 0, blockTime)

await expect(fastPriceFeed.connect(user0).setPricesWithDataAndExecute(
positionRouter.address,
0, // _priceBits
blockTime, // _timestamp
["0x"], // priceUpdateData
9, // _endIndexForIncreasePositions
10, // _endIndexForDecreasePositions
1, // _maxIncreasePositions
2 // _maxDecreasePositions
2, // _maxDecreasePositions
{ value: updateFee }
)).to.be.revertedWith("FastPriceFeed: forbidden")

await fastPriceFeed.connect(updater0).setPricesWithBitsAndExecute(
await fastPriceFeed.connect(updater0).setPricesWithDataAndExecute(
positionRouter.address,
0, // _priceBits
blockTime, // _timestamp
["0x"], // priceUpdateData
9, // _endIndexForIncreasePositions
10, // _endIndexForDecreasePositions
1, // _maxIncreasePositions
2 // _maxDecreasePositions
2, // _maxDecreasePositions
{ value: updateFee }
)

queueLengths = await positionRouter.getRequestQueueLengths()
Expand Down
2 changes: 1 addition & 1 deletion test/oracles/FastPriceFeed.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ describe("FastPriceFeed", function () {
120 * 60, // _maxPriceUpdateDelay
2, // _minBlockInterval
250, // _maxDeviationBasisPoints
fastPriceEvents.address, // _fastPriceEvents
vaultPriceFeed.address, // _vaultPriceFeed
fastPriceEvents.address, // _fastPriceEvents
tokenManager.address // _tokenManager
])
await fastPriceFeed.initialize(
Expand Down
13 changes: 4 additions & 9 deletions test/peripherals/PriceFeedTimelock.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ describe("PriceFeedTimelock", function () {
let timelock
let vaultTimelock
let fastPriceEvents
let mockPyth
let fastPriceFeed

beforeEach(async () => {
Expand Down Expand Up @@ -92,11 +93,14 @@ describe("PriceFeedTimelock", function () {
await router.setGov(timelock.address)

fastPriceEvents = await deployContract("FastPriceEvents", [])
mockPyth = await deployContract("MockPyth", [])
fastPriceFeed = await deployContract("FastPriceFeed", [
mockPyth.address, // _pyth
5 * 60, // _priceDuration
60 * 60, // _maxPriceUpdateDelay
2, // _minBlockInterval
250, // _allowedDeviationBasisPoints
vaultPriceFeed.address, // _vaultPriceFeed
fastPriceEvents.address, // _fastPriceEvents
tokenManager.address // _tokenManager
])
Expand Down Expand Up @@ -204,15 +208,6 @@ describe("PriceFeedTimelock", function () {
expect(await vaultPriceFeed.priceSampleSpace()).eq(1)
})

it("setVaultPriceFeed", async () => {
await expect(timelock.connect(user0).setVaultPriceFeed(fastPriceFeed.address, vaultPriceFeed.address))
.to.be.revertedWith("Timelock: forbidden")

expect(await fastPriceFeed.vaultPriceFeed()).eq(AddressZero)
await timelock.connect(wallet).setVaultPriceFeed(fastPriceFeed.address, vaultPriceFeed.address)
expect(await fastPriceFeed.vaultPriceFeed()).eq(vaultPriceFeed.address)
})

it("setPriceDuration", async () => {
await expect(timelock.connect(user0).setPriceDuration(fastPriceFeed.address, 1000))
.to.be.revertedWith("Timelock: forbidden")
Expand Down

0 comments on commit 94f7089

Please sign in to comment.