Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
cctdaniel committed Nov 6, 2024
1 parent eeeaaf5 commit 8196f78
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions target_chains/ethereum/contracts/forge-test/Pulse.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,22 @@ contract PulseTest is Test {
priceIds[0] = bytes32("BTC/USD");
priceIds[1] = bytes32("ETH/USD");

bytes[] memory updateData = new bytes[](2);
updateData[0] = bytes("data1");
updateData[1] = bytes("data2");

uint256 publishTime = block.timestamp;
uint256 callbackGasLimit = 500000;

// Fund the consumer contract
vm.deal(address(consumer), 1 ether);

// Step 1: Make the request as consumer
vm.prank(address(consumer));
uint64 sequenceNumber = pulse.requestPriceUpdatesWithCallback{
value: PYTH_FEE + PROVIDER_FEE
}(provider, publishTime, priceIds, callbackGasLimit);

// Step 2: Execute callback as provider with empty updateData array
// Important: must be empty array, not array with empty elements
bytes[] memory updateData = new bytes[](0);

vm.prank(provider);
pulse.executeCallback(
sequenceNumber,
Expand All @@ -104,6 +108,7 @@ contract PulseTest is Test {
callbackGasLimit
);

// Verify callback was executed
assertEq(consumer.lastSequenceNumber(), sequenceNumber);
assertEq(consumer.lastProvider(), provider);
assertEq(consumer.lastPublishTime(), publishTime);
Expand Down Expand Up @@ -217,6 +222,7 @@ contract PulseTest is Test {
// Setup - make a request to accrue some fees
bytes32[] memory priceIds = new bytes32[](1);

vm.deal(address(consumer), 1 ether);
vm.prank(address(consumer));
pulse.requestPriceUpdatesWithCallback{value: PYTH_FEE + PROVIDER_FEE}(
provider,
Expand Down Expand Up @@ -257,6 +263,7 @@ contract PulseTest is Test {
// Setup fees
bytes32[] memory priceIds = new bytes32[](1);

vm.deal(address(consumer), 1 ether);
vm.prank(address(consumer));
pulse.requestPriceUpdatesWithCallback{value: PYTH_FEE + PROVIDER_FEE}(
provider,
Expand Down Expand Up @@ -306,6 +313,9 @@ contract PulseTest is Test {
// Setup - make a request to accrue some fees
bytes32[] memory priceIds = new bytes32[](1);

// Fund the consumer contract
vm.deal(address(consumer), 1 ether);

vm.prank(address(consumer));
pulse.requestPriceUpdatesWithCallback{value: PYTH_FEE + PROVIDER_FEE}(
provider,
Expand Down Expand Up @@ -389,13 +399,12 @@ contract PulseTest is Test {
priceIds[0] = bytes32("BTC/USD");
priceIds[1] = bytes32("ETH/USD");

bytes[] memory updateData = new bytes[](2);
updateData[0] = bytes("data1");
updateData[1] = bytes("data2");

uint256 publishTime = block.timestamp;
uint256 callbackGasLimit = 500000;

// Fund the consumer contract
vm.deal(address(consumer), 1 ether);

vm.prank(address(consumer));
uint64 sequenceNumber = pulse.requestPriceUpdatesWithCallback{
value: PYTH_FEE + PROVIDER_FEE
Expand All @@ -412,8 +421,6 @@ contract PulseTest is Test {
assertEq(req.publishTime, publishTime);
assertEq(req.priceIds[0], priceIds[0]);
assertEq(req.priceIds[1], priceIds[1]);
assertEq(string(req.updateData[0]), string(updateData[0]));
assertEq(string(req.updateData[1]), string(updateData[1]));
assertEq(req.callbackGasLimit, callbackGasLimit);
assertEq(req.requester, address(consumer));
}
Expand Down

0 comments on commit 8196f78

Please sign in to comment.