33pragma solidity ^ 0.8.0 ;
44
55import "forge-std/Test.sol " ;
6+ import "@pythnetwork/pyth-sdk-solidity/IPyth.sol " ;
67import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol " ;
78import "../contracts/pulse/PulseUpgradeable.sol " ;
89import "../contracts/pulse/IPulse.sol " ;
@@ -13,28 +14,34 @@ import "../contracts/pulse/PulseErrors.sol";
1314contract MockPulseConsumer is IPulseConsumer {
1415 uint64 public lastSequenceNumber;
1516 address public lastUpdater;
16- uint256 public lastPublishTime;
17- bytes32 [] public lastPriceIds;
17+ PythStructs.PriceFeed[] private _lastPriceFeeds;
1818
1919 function pulseCallback (
2020 uint64 sequenceNumber ,
2121 address updater ,
22- uint256 publishTime ,
23- bytes32 [] calldata priceIds
22+ PythStructs.PriceFeed[] memory priceFeeds
2423 ) external override {
2524 lastSequenceNumber = sequenceNumber;
2625 lastUpdater = updater;
27- lastPublishTime = publishTime;
28- lastPriceIds = priceIds;
26+ for (uint i = 0 ; i < priceFeeds.length ; i++ ) {
27+ _lastPriceFeeds.push (priceFeeds[i]);
28+ }
29+ }
30+
31+ function lastPriceFeeds ()
32+ external
33+ view
34+ returns (PythStructs.PriceFeed[] memory )
35+ {
36+ return _lastPriceFeeds;
2937 }
3038}
3139
3240contract FailingPulseConsumer is IPulseConsumer {
3341 function pulseCallback (
3442 uint64 ,
3543 address ,
36- uint256 ,
37- bytes32 [] calldata
44+ PythStructs.PriceFeed[] memory
3845 ) external pure override {
3946 revert ("callback failed " );
4047 }
@@ -46,8 +53,7 @@ contract CustomErrorPulseConsumer is IPulseConsumer {
4653 function pulseCallback (
4754 uint64 ,
4855 address ,
49- uint256 ,
50- bytes32 [] calldata
56+ PythStructs.PriceFeed[] memory
5157 ) external pure override {
5258 revert CustomError ("callback failed " );
5359 }
@@ -278,7 +284,6 @@ contract PulseTest is Test, PulseEvents {
278284 emit PriceUpdateExecuted (
279285 sequenceNumber,
280286 updater,
281- publishTime,
282287 priceIds,
283288 expectedPrices,
284289 expectedConf,
@@ -294,7 +299,22 @@ contract PulseTest is Test, PulseEvents {
294299
295300 // Verify callback was executed
296301 assertEq (consumer.lastSequenceNumber (), sequenceNumber);
297- assertEq (consumer.lastPublishTime (), publishTime);
302+
303+ // Compare price feeds array length
304+ PythStructs.PriceFeed[] memory lastFeeds = consumer.lastPriceFeeds ();
305+ assertEq (lastFeeds.length , priceFeeds.length );
306+
307+ // Compare each price feed
308+ for (uint i = 0 ; i < priceFeeds.length ; i++ ) {
309+ assertEq (lastFeeds[i].id, priceFeeds[i].id);
310+ assertEq (lastFeeds[i].price.price, priceFeeds[i].price.price);
311+ assertEq (lastFeeds[i].price.conf, priceFeeds[i].price.conf);
312+ assertEq (lastFeeds[i].price.expo, priceFeeds[i].price.expo);
313+ assertEq (
314+ lastFeeds[i].price.publishTime,
315+ priceFeeds[i].price.publishTime
316+ );
317+ }
298318 }
299319
300320 function testExecuteCallbackFailure () public {
@@ -316,7 +336,6 @@ contract PulseTest is Test, PulseEvents {
316336 emit PriceUpdateCallbackFailed (
317337 sequenceNumber,
318338 updater,
319- publishTime,
320339 priceIds,
321340 address (failingConsumer),
322341 "callback failed "
@@ -345,7 +364,6 @@ contract PulseTest is Test, PulseEvents {
345364 emit PriceUpdateCallbackFailed (
346365 sequenceNumber,
347366 updater,
348- publishTime,
349367 priceIds,
350368 address (failingConsumer),
351369 "low-level error (possibly out of gas) "
@@ -370,10 +388,14 @@ contract PulseTest is Test, PulseEvents {
370388 mockParsePriceFeedUpdates (priceFeeds);
371389 bytes [] memory updateData = createMockUpdateData (priceFeeds);
372390
373- // Try executing with only 10K gas when 1M is required
391+ // Try executing with only 100K gas when 1M is required
374392 vm.prank (updater);
375393 vm.expectRevert (InsufficientGas.selector );
376- pulse.executeCallback {gas: 10000 }(sequenceNumber, updateData, priceIds); // Will fail because gasleft() < callbackGasLimit
394+ pulse.executeCallback {gas: 100000 }(
395+ sequenceNumber,
396+ updateData,
397+ priceIds
398+ ); // Will fail because gasleft() < callbackGasLimit
377399 }
378400
379401 function testExecuteCallbackWithFutureTimestamp () public {
@@ -399,8 +421,17 @@ contract PulseTest is Test, PulseEvents {
399421 // Should succeed because we're simulating receiving future-dated price updates
400422 pulse.executeCallback (sequenceNumber, updateData, priceIds);
401423
402- // Verify the callback was executed with future timestamp
403- assertEq (consumer.lastPublishTime (), futureTime);
424+ // Compare price feeds array length
425+ PythStructs.PriceFeed[] memory lastFeeds = consumer.lastPriceFeeds ();
426+ assertEq (lastFeeds.length , priceFeeds.length );
427+
428+ // Compare each price feed publish time
429+ for (uint i = 0 ; i < priceFeeds.length ; i++ ) {
430+ assertEq (
431+ lastFeeds[i].price.publishTime,
432+ priceFeeds[i].price.publishTime
433+ );
434+ }
404435 }
405436
406437 function testDoubleExecuteCallback () public {
0 commit comments