Skip to content

Commit cd543bc

Browse files
committed
refactor(target_chains/ethereum): remove duplicated tests
1 parent f134c2d commit cd543bc

File tree

1 file changed

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

1 file changed

+0
-221
lines changed

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

Lines changed: 0 additions & 221 deletions
Original file line numberDiff line numberDiff line change
@@ -133,75 +133,6 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils {
133133
}
134134
}
135135

136-
function testParsePriceFeedUpdatesWorksWithRandomDistinctUpdatesInput(
137-
uint seed
138-
) public {
139-
setRandSeed(seed);
140-
uint numMessages = 1 + (getRandUint() % 30);
141-
(
142-
bytes32[] memory priceIds,
143-
PriceFeedMessage[] memory messages
144-
) = generateRandomPriceMessages(numMessages);
145-
146-
(
147-
bytes[] memory updateData,
148-
uint updateFee
149-
) = createBatchedUpdateDataFromMessages(messages);
150-
151-
// Shuffle the messages
152-
for (uint i = 1; i < numMessages; i++) {
153-
uint swapWith = getRandUint() % (i + 1);
154-
(messages[i], messages[swapWith]) = (
155-
messages[swapWith],
156-
messages[i]
157-
);
158-
(priceIds[i], priceIds[swapWith]) = (
159-
priceIds[swapWith],
160-
priceIds[i]
161-
);
162-
}
163-
164-
// Select only first numSelectedMessages. numSelectedMessages will be in [0, numMessages]
165-
uint numSelectedMessages = getRandUint() % (numMessages + 1);
166-
167-
PriceFeedMessage[] memory selectedMessages = new PriceFeedMessage[](
168-
numSelectedMessages
169-
);
170-
bytes32[] memory selectedPriceIds = new bytes32[](numSelectedMessages);
171-
172-
for (uint i = 0; i < numSelectedMessages; i++) {
173-
selectedMessages[i] = messages[i];
174-
selectedPriceIds[i] = priceIds[i];
175-
}
176-
177-
// Only parse selected messages
178-
PythStructs.PriceFeed[] memory priceFeeds = pyth.parsePriceFeedUpdates{
179-
value: updateFee
180-
}(updateData, selectedPriceIds, 0, MAX_UINT64);
181-
182-
for (uint i = 0; i < numSelectedMessages; i++) {
183-
assertEq(priceFeeds[i].id, selectedPriceIds[i]);
184-
assertEq(priceFeeds[i].price.expo, selectedMessages[i].expo);
185-
assertEq(
186-
priceFeeds[i].emaPrice.price,
187-
selectedMessages[i].emaPrice
188-
);
189-
assertEq(priceFeeds[i].emaPrice.conf, selectedMessages[i].emaConf);
190-
assertEq(priceFeeds[i].emaPrice.expo, selectedMessages[i].expo);
191-
192-
assertEq(priceFeeds[i].price.price, selectedMessages[i].price);
193-
assertEq(priceFeeds[i].price.conf, selectedMessages[i].conf);
194-
assertEq(
195-
priceFeeds[i].price.publishTime,
196-
selectedMessages[i].publishTime
197-
);
198-
assertEq(
199-
priceFeeds[i].emaPrice.publishTime,
200-
selectedMessages[i].publishTime
201-
);
202-
}
203-
}
204-
205136
function testParsePriceFeedUpdatesWorksWithOverlappingWithinTimeRangeUpdates()
206137
public
207138
{
@@ -281,31 +212,6 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils {
281212
assertEq(priceFeeds[0].price.publishTime, 20);
282213
}
283214

284-
function testParsePriceFeedUpdatesRevertsIfUpdateFeeIsNotPaid() public {
285-
uint numMessages = 10;
286-
(
287-
bytes32[] memory priceIds,
288-
PriceFeedMessage[] memory messages
289-
) = generateRandomPriceMessages(numMessages);
290-
291-
(
292-
bytes[] memory updateData,
293-
uint updateFee
294-
) = createBatchedUpdateDataFromMessages(messages);
295-
296-
// Since messages are not empty the fee should be at least 1
297-
assertGe(updateFee, 1);
298-
299-
vm.expectRevert(PythErrors.InsufficientFee.selector);
300-
301-
pyth.parsePriceFeedUpdates{value: updateFee - 1}(
302-
updateData,
303-
priceIds,
304-
0,
305-
MAX_UINT64
306-
);
307-
}
308-
309215
function testParsePriceFeedUpdatesRevertsIfUpdateVAAIsInvalid(
310216
uint seed
311217
) public {
@@ -400,131 +306,4 @@ contract PythTest is Test, WormholeTestUtils, PythTestUtils {
400306
MAX_UINT64
401307
);
402308
}
403-
404-
function testParsePriceFeedUpdatesRevertsIfPriceIdNotIncluded() public {
405-
PriceFeedMessage[] memory messages = new PriceFeedMessage[](1);
406-
407-
messages[0].priceId = bytes32(uint(1));
408-
messages[0].price = 1000;
409-
messages[0].publishTime = 10;
410-
411-
(
412-
bytes[] memory updateData,
413-
uint updateFee
414-
) = createBatchedUpdateDataFromMessages(messages);
415-
416-
bytes32[] memory priceIds = new bytes32[](1);
417-
priceIds[0] = bytes32(uint(2));
418-
419-
vm.expectRevert(PythErrors.PriceFeedNotFoundWithinRange.selector);
420-
pyth.parsePriceFeedUpdates{value: updateFee}(
421-
updateData,
422-
priceIds,
423-
0,
424-
MAX_UINT64
425-
);
426-
}
427-
428-
function testParsePriceFeedUpdateRevertsIfPricesOutOfTimeRange() public {
429-
uint numMessages = 10;
430-
(
431-
bytes32[] memory priceIds,
432-
PriceFeedMessage[] memory messages
433-
) = generateRandomPriceMessages(numMessages);
434-
435-
for (uint i = 0; i < numMessages; i++) {
436-
messages[i].publishTime = uint64(100 + (getRandUint() % 101)); // All between [100, 200]
437-
}
438-
439-
(
440-
bytes[] memory updateData,
441-
uint updateFee
442-
) = createBatchedUpdateDataFromMessages(messages);
443-
444-
// Request for parse within the given time range should work
445-
pyth.parsePriceFeedUpdates{value: updateFee}(
446-
updateData,
447-
priceIds,
448-
100,
449-
200
450-
);
451-
452-
// Request for parse after the time range should revert.
453-
vm.expectRevert(PythErrors.PriceFeedNotFoundWithinRange.selector);
454-
pyth.parsePriceFeedUpdates{value: updateFee}(
455-
updateData,
456-
priceIds,
457-
300,
458-
MAX_UINT64
459-
);
460-
}
461-
462-
function testParsePriceFeedUpdatesLatestPriceIfNecessary() public {
463-
uint numMessages = 10;
464-
(
465-
bytes32[] memory priceIds,
466-
PriceFeedMessage[] memory messages
467-
) = generateRandomPriceMessages(numMessages);
468-
469-
for (uint i = 0; i < numMessages; i++) {
470-
messages[i].publishTime = uint64((getRandUint() % 101)); // All between [0, 100]
471-
}
472-
473-
(
474-
bytes[] memory updateData,
475-
uint updateFee
476-
) = createBatchedUpdateDataFromMessages(messages);
477-
478-
// Request for parse within the given time range should work and update the latest price
479-
pyth.parsePriceFeedUpdates{value: updateFee}(
480-
updateData,
481-
priceIds,
482-
0,
483-
100
484-
);
485-
486-
// Check if the latest price is updated
487-
for (uint i = 0; i < numMessages; i++) {
488-
assertEq(
489-
pyth.getPriceUnsafe(priceIds[i]).publishTime,
490-
messages[i].publishTime
491-
);
492-
}
493-
494-
for (uint i = 0; i < numMessages; i++) {
495-
messages[i].publishTime = uint64(100 + (getRandUint() % 101)); // All between [100, 200]
496-
}
497-
498-
(updateData, updateFee) = createBatchedUpdateDataFromMessages(messages);
499-
500-
// Request for parse after the time range should revert.
501-
vm.expectRevert(PythErrors.PriceFeedNotFoundWithinRange.selector);
502-
pyth.parsePriceFeedUpdates{value: updateFee}(
503-
updateData,
504-
priceIds,
505-
300,
506-
400
507-
);
508-
509-
// parse function reverted so publishTimes should remain less than or equal to 100
510-
for (uint i = 0; i < numMessages; i++) {
511-
assertGe(100, pyth.getPriceUnsafe(priceIds[i]).publishTime);
512-
}
513-
514-
// Time range is now fixed, so parse should work and update the latest price
515-
pyth.parsePriceFeedUpdates{value: updateFee}(
516-
updateData,
517-
priceIds,
518-
100,
519-
200
520-
);
521-
522-
// Check if the latest price is updated
523-
for (uint i = 0; i < numMessages; i++) {
524-
assertEq(
525-
pyth.getPriceUnsafe(priceIds[i]).publishTime,
526-
messages[i].publishTime
527-
);
528-
}
529-
}
530309
}

0 commit comments

Comments
 (0)