Skip to content

Commit f1183f1

Browse files
committed
fixed store = false test
1 parent 2e79358 commit f1183f1

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

target_chains/ethereum/contracts/contracts/pyth/Pyth.sol

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,24 @@ abstract contract Pyth is
359359
updateData[i],
360360
context
361361
);
362-
if (storeUpdatesIfFresh) {
363-
bytes32 curPriceId = context.priceIds[i];
364-
updateLatestPriceIfNecessary(curPriceId, _state.latestPriceInfo[curPriceId]);
362+
}
363+
364+
if (storeUpdatesIfFresh) {
365+
for (uint j = 0; j < priceIds.length; j++) {
366+
bytes32 curPriceId = priceIds[j];
367+
if (context.priceFeeds[j].id != 0) {
368+
// Create a new PriceInfo memory object from the context.priceFeeds data
369+
PythInternalStructs.PriceInfo memory newInfo;
370+
newInfo.publishTime = uint64(context.priceFeeds[j].price.publishTime);
371+
newInfo.expo = context.priceFeeds[j].price.expo;
372+
newInfo.price = context.priceFeeds[j].price.price;
373+
newInfo.conf = context.priceFeeds[j].price.conf;
374+
newInfo.emaPrice = context.priceFeeds[j].emaPrice.price;
375+
newInfo.emaConf = context.priceFeeds[j].emaPrice.conf;
376+
377+
// Pass the new memory object to update storage
378+
updateLatestPriceIfNecessary(curPriceId, newInfo);
379+
}
365380
}
366381
}
367382
}

target_chains/ethereum/contracts/forge-test/Pyth.t.sol

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -335,26 +335,14 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils {
335335
uint updateFee
336336
) = createBatchedUpdateDataFromMessages(messages);
337337

338-
// Store prices before update
339-
PythStructs.Price[] memory originalPrices = new PythStructs.Price[](priceIds.length);
340-
for (uint i = 0; i < priceIds.length; i++) {
341-
originalPrices[i] = pyth.getPriceUnsafe(priceIds[i]);
342-
}
343-
344338
pyth.parsePriceFeedUpdatesWithConfig{
345339
value: updateFee
346-
}(updateData, priceIds, 0, MAX_UINT64, false, true, true);
340+
}(updateData, priceIds, 0, MAX_UINT64, false, true, false);
347341

348-
// validate that stored prices of each priceId are same as before update
349-
for (uint i = 0; i < priceIds.length; i++) {
350-
PythStructs.Price memory curPrice = pyth.getPriceUnsafe(
351-
priceIds[i]
352-
);
353-
354-
assertEq(curPrice.price, originalPrices[i].price);
355-
assertEq(curPrice.conf, originalPrices[i].conf);
356-
assertEq(curPrice.expo, originalPrices[i].expo);
357-
assertEq(curPrice.publishTime, originalPrices[i].publishTime);
342+
// validate that stored prices of each priceId are still unpopulated
343+
for (uint i = 0; i < numMessages; i++) {
344+
vm.expectRevert(PythErrors.PriceFeedNotFound.selector);
345+
pyth.getPriceUnsafe(priceIds[i]);
358346
}
359347
}
360348

0 commit comments

Comments
 (0)