Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cctdaniel committed Nov 13, 2024
1 parent 0e5e328 commit 6702d2f
Showing 1 changed file with 68 additions and 8 deletions.
76 changes: 68 additions & 8 deletions target_chains/ethereum/contracts/forge-test/Pulse.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ contract PulseTest is Test, PulseEvents {
}

// Helper function to mock Pyth response
function mockPythResponse(
function mockParsePriceFeedUpdates(
PythStructs.PriceFeed[] memory priceFeeds
) internal {
vm.mockCall(
Expand Down Expand Up @@ -261,7 +261,7 @@ contract PulseTest is Test, PulseEvents {
PythStructs.PriceFeed[] memory priceFeeds = createMockPriceFeeds(
publishTime
);
mockPythResponse(priceFeeds);
mockParsePriceFeedUpdates(priceFeeds);

// Create arrays for expected event data
int64[] memory expectedPrices = new int64[](2);
Expand Down Expand Up @@ -323,7 +323,7 @@ contract PulseTest is Test, PulseEvents {
PythStructs.PriceFeed[] memory priceFeeds = createMockPriceFeeds(
publishTime
);
mockPythResponse(priceFeeds);
mockParsePriceFeedUpdates(priceFeeds);
bytes[] memory updateData = createMockUpdateData(priceFeeds);

vm.expectEmit(true, true, true, true);
Expand Down Expand Up @@ -358,7 +358,7 @@ contract PulseTest is Test, PulseEvents {
PythStructs.PriceFeed[] memory priceFeeds = createMockPriceFeeds(
publishTime
);
mockPythResponse(priceFeeds);
mockParsePriceFeedUpdates(priceFeeds);
bytes[] memory updateData = createMockUpdateData(priceFeeds);

vm.expectEmit(true, true, true, true);
Expand Down Expand Up @@ -396,7 +396,7 @@ contract PulseTest is Test, PulseEvents {
PythStructs.PriceFeed[] memory priceFeeds = createMockPriceFeeds(
publishTime
);
mockPythResponse(priceFeeds);
mockParsePriceFeedUpdates(priceFeeds);
bytes[] memory updateData = createMockUpdateData(priceFeeds);

vm.prank(provider);
Expand Down Expand Up @@ -426,7 +426,7 @@ contract PulseTest is Test, PulseEvents {
PythStructs.PriceFeed[] memory priceFeeds = createMockPriceFeeds(
publishTime
);
mockPythResponse(priceFeeds);
mockParsePriceFeedUpdates(priceFeeds);
bytes[] memory updateData = createMockUpdateData(priceFeeds);

vm.prank(provider);
Expand All @@ -450,7 +450,7 @@ contract PulseTest is Test, PulseEvents {
PythStructs.PriceFeed[] memory priceFeeds = createMockPriceFeeds(
publishTime
);
mockPythResponse(priceFeeds);
mockParsePriceFeedUpdates(priceFeeds);
bytes[] memory updateData = createMockUpdateData(priceFeeds);

// Try to execute with different gas limit than what was requested
Expand Down Expand Up @@ -487,7 +487,7 @@ contract PulseTest is Test, PulseEvents {
PythStructs.PriceFeed[] memory priceFeeds = createMockPriceFeeds(
futureTime // Mock price feeds with future timestamp
);
mockPythResponse(priceFeeds); // This will make parsePriceFeedUpdates return future-dated prices
mockParsePriceFeedUpdates(priceFeeds); // This will make parsePriceFeedUpdates return future-dated prices
bytes[] memory updateData = createMockUpdateData(priceFeeds);

vm.prank(provider);
Expand All @@ -504,6 +504,66 @@ contract PulseTest is Test, PulseEvents {
assertEq(consumer.lastPublishTime(), futureTime);
}

function testExecuteCallbackWithWrongProvider() public {
(
uint64 sequenceNumber,
bytes32[] memory priceIds,
uint256 publishTime
) = setupConsumerRequest(address(consumer));

PythStructs.PriceFeed[] memory priceFeeds = createMockPriceFeeds(
publishTime
);
mockParsePriceFeedUpdates(priceFeeds);
bytes[] memory updateData = createMockUpdateData(priceFeeds);

address wrongProvider = address(0x999);
vm.prank(wrongProvider);
vm.expectRevert(NoSuchRequest.selector);
pulse.executeCallback(
wrongProvider,
sequenceNumber,
priceIds,
updateData,
CALLBACK_GAS_LIMIT
);
}

function testDoubleExecuteCallback() public {
(
uint64 sequenceNumber,
bytes32[] memory priceIds,
uint256 publishTime
) = setupConsumerRequest(address(consumer));

PythStructs.PriceFeed[] memory priceFeeds = createMockPriceFeeds(
publishTime
);
mockParsePriceFeedUpdates(priceFeeds);
bytes[] memory updateData = createMockUpdateData(priceFeeds);

// First execution
vm.prank(provider);
pulse.executeCallback(
provider,
sequenceNumber,
priceIds,
updateData,
CALLBACK_GAS_LIMIT
);

// Second execution should fail
vm.prank(provider);
vm.expectRevert(NoSuchRequest.selector);
pulse.executeCallback(
provider,
sequenceNumber,
priceIds,
updateData,
CALLBACK_GAS_LIMIT
);
}

function testGetFee() public {
// Test with different gas limits to verify fee calculation
uint256[] memory gasLimits = new uint256[](3);
Expand Down

0 comments on commit 6702d2f

Please sign in to comment.