Skip to content

Commit 2e79358

Browse files
committed
working on function test case
1 parent 6b4b0c8 commit 2e79358

File tree

1 file changed

+80
-0
lines changed
  • target_chains/ethereum/contracts/forge-test

1 file changed

+80
-0
lines changed

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,86 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils {
278278
}
279279
}
280280

281+
function testParsePriceFeedUpdatesWithConfigIfStorageTrue(uint seed) public {
282+
setRandSeed(seed);
283+
uint numMessages = 1 + (getRandUint() % 10);
284+
(
285+
bytes32[] memory priceIds,
286+
PriceFeedMessage[] memory messages
287+
) = generateRandomPriceMessages(numMessages);
288+
289+
(
290+
bytes[] memory updateData,
291+
uint updateFee
292+
) = createBatchedUpdateDataFromMessages(messages);
293+
294+
(PythStructs.PriceFeed[] memory priceFeeds,) = pyth.parsePriceFeedUpdatesWithConfig{
295+
value: updateFee
296+
}(updateData, priceIds, 0, MAX_UINT64, false, true, true);
297+
298+
for (uint i = 0; i < numMessages; i++) {
299+
// Validating that returned priceIds are equal
300+
assertEq(priceFeeds[i].id, priceIds[i]);
301+
assertEq(priceFeeds[i].price.price, messages[i].price);
302+
assertEq(priceFeeds[i].price.conf, messages[i].conf);
303+
assertEq(priceFeeds[i].price.expo, messages[i].expo);
304+
assertEq(priceFeeds[i].price.publishTime, messages[i].publishTime);
305+
assertEq(priceFeeds[i].emaPrice.price, messages[i].emaPrice);
306+
assertEq(priceFeeds[i].emaPrice.conf, messages[i].emaConf);
307+
assertEq(priceFeeds[i].emaPrice.expo, messages[i].expo);
308+
assertEq(
309+
priceFeeds[i].emaPrice.publishTime,
310+
messages[i].publishTime
311+
);
312+
313+
// Validating that prices are stored on chain
314+
PythStructs.Price memory curPrice = pyth.getPriceUnsafe(
315+
messages[i].priceId
316+
);
317+
318+
assertEq(priceFeeds[i].price.price, curPrice.price);
319+
assertEq(priceFeeds[i].price.conf, curPrice.conf);
320+
assertEq(priceFeeds[i].price.expo, curPrice.expo);
321+
assertEq(priceFeeds[i].price.publishTime, curPrice.publishTime);
322+
}
323+
}
324+
325+
function testParsePriceFeedUpdatesWithConfigIfStorageFalse(uint seed) public {
326+
setRandSeed(seed);
327+
uint numMessages = 1 + (getRandUint() % 10);
328+
(
329+
bytes32[] memory priceIds,
330+
PriceFeedMessage[] memory messages
331+
) = generateRandomPriceMessages(numMessages);
332+
333+
(
334+
bytes[] memory updateData,
335+
uint updateFee
336+
) = createBatchedUpdateDataFromMessages(messages);
337+
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+
344+
pyth.parsePriceFeedUpdatesWithConfig{
345+
value: updateFee
346+
}(updateData, priceIds, 0, MAX_UINT64, false, true, true);
347+
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);
358+
}
359+
}
360+
281361
function testParsePriceFeedUpdatesWithSlotsStrictWorks(uint seed) public {
282362
setRandSeed(seed);
283363
uint numMessages = 1 + (getRandUint() % 10);

0 commit comments

Comments
 (0)