|
@@ -3,6 +3,7 @@
|
|
|
pragma solidity ^0.8.0;
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
|
|
|
import "forge-std/Test.sol";
|
|
import "forge-std/Test.sol";
|
|
|
|
|
+import "forge-std/console.sol";
|
|
|
import "@pythnetwork/pyth-sdk-solidity/IPyth.sol";
|
|
import "@pythnetwork/pyth-sdk-solidity/IPyth.sol";
|
|
|
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
|
|
import "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
|
|
|
import "./utils/PulseTestUtils.t.sol";
|
|
import "./utils/PulseTestUtils.t.sol";
|
|
@@ -116,15 +117,23 @@ contract SchedulerTest is Test, SchedulerEvents, PulseTestUtils {
|
|
|
priceIds: priceIds,
|
|
priceIds: priceIds,
|
|
|
readerWhitelist: readerWhitelist,
|
|
readerWhitelist: readerWhitelist,
|
|
|
whitelistEnabled: true,
|
|
whitelistEnabled: true,
|
|
|
|
|
+ isActive: true,
|
|
|
updateCriteria: updateCriteria,
|
|
updateCriteria: updateCriteria,
|
|
|
gasConfig: gasConfig
|
|
gasConfig: gasConfig
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- // Add subscription
|
|
|
|
|
|
|
+ // Calculate minimum balance
|
|
|
|
|
+ uint256 minimumBalance = scheduler.getMinimumBalance(
|
|
|
|
|
+ uint8(priceIds.length)
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // Add subscription with minimum balance
|
|
|
vm.expectEmit();
|
|
vm.expectEmit();
|
|
|
emit SubscriptionCreated(1, address(this));
|
|
emit SubscriptionCreated(1, address(this));
|
|
|
|
|
|
|
|
- uint256 subscriptionId = scheduler.addSubscription(params);
|
|
|
|
|
|
|
+ uint256 subscriptionId = scheduler.addSubscription{
|
|
|
|
|
+ value: minimumBalance
|
|
|
|
|
+ }(params);
|
|
|
assertEq(subscriptionId, 1, "Subscription ID should be 1");
|
|
assertEq(subscriptionId, 1, "Subscription ID should be 1");
|
|
|
|
|
|
|
|
// Verify subscription was added correctly
|
|
// Verify subscription was added correctly
|
|
@@ -165,7 +174,11 @@ contract SchedulerTest is Test, SchedulerEvents, PulseTestUtils {
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
assertTrue(status.isActive, "Subscription should be active");
|
|
assertTrue(status.isActive, "Subscription should be active");
|
|
|
- assertEq(status.balanceInWei, 0, "Initial balance should be 0");
|
|
|
|
|
|
|
+ assertEq(
|
|
|
|
|
+ status.balanceInWei,
|
|
|
|
|
+ minimumBalance,
|
|
|
|
|
+ "Initial balance should match minimum balance"
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function testUpdateSubscription() public {
|
|
function testUpdateSubscription() public {
|
|
@@ -197,6 +210,7 @@ contract SchedulerTest is Test, SchedulerEvents, PulseTestUtils {
|
|
|
priceIds: newPriceIds,
|
|
priceIds: newPriceIds,
|
|
|
readerWhitelist: newReaderWhitelist,
|
|
readerWhitelist: newReaderWhitelist,
|
|
|
whitelistEnabled: false, // Changed from true
|
|
whitelistEnabled: false, // Changed from true
|
|
|
|
|
+ isActive: true,
|
|
|
updateCriteria: newUpdateCriteria,
|
|
updateCriteria: newUpdateCriteria,
|
|
|
gasConfig: newGasConfig
|
|
gasConfig: newGasConfig
|
|
|
});
|
|
});
|
|
@@ -243,27 +257,132 @@ contract SchedulerTest is Test, SchedulerEvents, PulseTestUtils {
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- function testDeactivateSubscription() public {
|
|
|
|
|
- // First add a subscription
|
|
|
|
|
- uint256 subscriptionId = addTestSubscription();
|
|
|
|
|
|
|
+ function testAddSubscriptionInsufficientFunds() public {
|
|
|
|
|
+ // Create subscription parameters
|
|
|
|
|
+ bytes32[] memory priceIds = createPriceIds();
|
|
|
|
|
+ address[] memory readerWhitelist = new address[](1);
|
|
|
|
|
+ readerWhitelist[0] = address(reader);
|
|
|
|
|
+
|
|
|
|
|
+ SchedulerState.UpdateCriteria memory updateCriteria = SchedulerState
|
|
|
|
|
+ .UpdateCriteria({
|
|
|
|
|
+ updateOnHeartbeat: true,
|
|
|
|
|
+ heartbeatSeconds: 60,
|
|
|
|
|
+ updateOnDeviation: true,
|
|
|
|
|
+ deviationThresholdBps: 100
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ SchedulerState.GasConfig memory gasConfig = SchedulerState.GasConfig({
|
|
|
|
|
+ maxGasMultiplierCapPct: 10_000,
|
|
|
|
|
+ maxFeeMultiplierCapPct: 10_000
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ SchedulerState.SubscriptionParams memory params = SchedulerState
|
|
|
|
|
+ .SubscriptionParams({
|
|
|
|
|
+ priceIds: priceIds,
|
|
|
|
|
+ readerWhitelist: readerWhitelist,
|
|
|
|
|
+ whitelistEnabled: true,
|
|
|
|
|
+ isActive: true,
|
|
|
|
|
+ updateCriteria: updateCriteria,
|
|
|
|
|
+ gasConfig: gasConfig
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ // Calculate minimum balance
|
|
|
|
|
+ uint256 minimumBalance = scheduler.getMinimumBalance(
|
|
|
|
|
+ uint8(priceIds.length)
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // Try to add subscription with insufficient funds
|
|
|
|
|
+ vm.expectRevert(abi.encodeWithSelector(InsufficientBalance.selector));
|
|
|
|
|
+ scheduler.addSubscription{value: minimumBalance - 1 wei}(params);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ function testActivateDeactivateSubscription() public {
|
|
|
|
|
+ // First add a subscription with minimum balance
|
|
|
|
|
+ bytes32[] memory priceIds = createPriceIds();
|
|
|
|
|
+ address[] memory readerWhitelist = new address[](1);
|
|
|
|
|
+ readerWhitelist[0] = address(reader);
|
|
|
|
|
+
|
|
|
|
|
+ SchedulerState.UpdateCriteria memory updateCriteria = SchedulerState
|
|
|
|
|
+ .UpdateCriteria({
|
|
|
|
|
+ updateOnHeartbeat: true,
|
|
|
|
|
+ heartbeatSeconds: 60,
|
|
|
|
|
+ updateOnDeviation: true,
|
|
|
|
|
+ deviationThresholdBps: 100
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ SchedulerState.GasConfig memory gasConfig = SchedulerState.GasConfig({
|
|
|
|
|
+ maxGasMultiplierCapPct: 10_000,
|
|
|
|
|
+ maxFeeMultiplierCapPct: 10_000
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ SchedulerState.SubscriptionParams memory params = SchedulerState
|
|
|
|
|
+ .SubscriptionParams({
|
|
|
|
|
+ priceIds: priceIds,
|
|
|
|
|
+ readerWhitelist: readerWhitelist,
|
|
|
|
|
+ whitelistEnabled: true,
|
|
|
|
|
+ isActive: true,
|
|
|
|
|
+ updateCriteria: updateCriteria,
|
|
|
|
|
+ gasConfig: gasConfig
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ uint256 minimumBalance = scheduler.getMinimumBalance(
|
|
|
|
|
+ uint8(priceIds.length)
|
|
|
|
|
+ );
|
|
|
|
|
+ uint256 subscriptionId = scheduler.addSubscription{
|
|
|
|
|
+ value: minimumBalance
|
|
|
|
|
+ }(params);
|
|
|
|
|
+
|
|
|
|
|
+ // Deactivate subscription using updateSubscription
|
|
|
|
|
+ params.isActive = false;
|
|
|
|
|
|
|
|
- // Deactivate subscription
|
|
|
|
|
vm.expectEmit();
|
|
vm.expectEmit();
|
|
|
emit SubscriptionDeactivated(subscriptionId);
|
|
emit SubscriptionDeactivated(subscriptionId);
|
|
|
|
|
+ vm.expectEmit();
|
|
|
|
|
+ emit SubscriptionUpdated(subscriptionId);
|
|
|
|
|
|
|
|
- scheduler.deactivateSubscription(subscriptionId);
|
|
|
|
|
|
|
+ scheduler.updateSubscription(subscriptionId, params);
|
|
|
|
|
|
|
|
// Verify subscription was deactivated
|
|
// Verify subscription was deactivated
|
|
|
- (, SchedulerState.SubscriptionStatus memory status) = scheduler
|
|
|
|
|
- .getSubscription(subscriptionId);
|
|
|
|
|
|
|
+ (
|
|
|
|
|
+ SchedulerState.SubscriptionParams memory storedParams,
|
|
|
|
|
+ SchedulerState.SubscriptionStatus memory status
|
|
|
|
|
+ ) = scheduler.getSubscription(subscriptionId);
|
|
|
|
|
|
|
|
assertFalse(status.isActive, "Subscription should be inactive");
|
|
assertFalse(status.isActive, "Subscription should be inactive");
|
|
|
|
|
+ assertFalse(
|
|
|
|
|
+ storedParams.isActive,
|
|
|
|
|
+ "Subscription params should show inactive"
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // Reactivate subscription using updateSubscription
|
|
|
|
|
+ params.isActive = true;
|
|
|
|
|
+
|
|
|
|
|
+ vm.expectEmit();
|
|
|
|
|
+ emit SubscriptionActivated(subscriptionId);
|
|
|
|
|
+ vm.expectEmit();
|
|
|
|
|
+ emit SubscriptionUpdated(subscriptionId);
|
|
|
|
|
+
|
|
|
|
|
+ scheduler.updateSubscription(subscriptionId, params);
|
|
|
|
|
+
|
|
|
|
|
+ // Verify subscription was reactivated
|
|
|
|
|
+ (storedParams, status) = scheduler.getSubscription(subscriptionId);
|
|
|
|
|
+
|
|
|
|
|
+ assertTrue(status.isActive, "Subscription should be active");
|
|
|
|
|
+ assertTrue(
|
|
|
|
|
+ storedParams.isActive,
|
|
|
|
|
+ "Subscription params should show active"
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function testAddFunds() public {
|
|
function testAddFunds() public {
|
|
|
// First add a subscription
|
|
// First add a subscription
|
|
|
uint256 subscriptionId = addTestSubscription();
|
|
uint256 subscriptionId = addTestSubscription();
|
|
|
|
|
|
|
|
|
|
+ // Get initial balance (which includes minimum balance)
|
|
|
|
|
+ (, SchedulerState.SubscriptionStatus memory initialStatus) = scheduler
|
|
|
|
|
+ .getSubscription(subscriptionId);
|
|
|
|
|
+ uint256 initialBalance = initialStatus.balanceInWei;
|
|
|
|
|
+
|
|
|
// Add funds
|
|
// Add funds
|
|
|
uint256 fundAmount = 1 ether;
|
|
uint256 fundAmount = 1 ether;
|
|
|
scheduler.addFunds{value: fundAmount}(subscriptionId);
|
|
scheduler.addFunds{value: fundAmount}(subscriptionId);
|
|
@@ -274,23 +393,57 @@ contract SchedulerTest is Test, SchedulerEvents, PulseTestUtils {
|
|
|
|
|
|
|
|
assertEq(
|
|
assertEq(
|
|
|
status.balanceInWei,
|
|
status.balanceInWei,
|
|
|
- fundAmount,
|
|
|
|
|
- "Balance should match added funds"
|
|
|
|
|
|
|
+ initialBalance + fundAmount,
|
|
|
|
|
+ "Balance should match initial balance plus added funds"
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function testWithdrawFunds() public {
|
|
function testWithdrawFunds() public {
|
|
|
- // First add a subscription and funds
|
|
|
|
|
- uint256 subscriptionId = addTestSubscription();
|
|
|
|
|
- uint256 fundAmount = 1 ether;
|
|
|
|
|
- scheduler.addFunds{value: fundAmount}(subscriptionId);
|
|
|
|
|
|
|
+ // First add a subscription with minimum balance
|
|
|
|
|
+ bytes32[] memory priceIds = createPriceIds();
|
|
|
|
|
+ uint256 minimumBalance = scheduler.getMinimumBalance(
|
|
|
|
|
+ uint8(priceIds.length)
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ address[] memory readerWhitelist = new address[](1);
|
|
|
|
|
+ readerWhitelist[0] = address(reader);
|
|
|
|
|
+
|
|
|
|
|
+ SchedulerState.UpdateCriteria memory updateCriteria = SchedulerState
|
|
|
|
|
+ .UpdateCriteria({
|
|
|
|
|
+ updateOnHeartbeat: true,
|
|
|
|
|
+ heartbeatSeconds: 60,
|
|
|
|
|
+ updateOnDeviation: true,
|
|
|
|
|
+ deviationThresholdBps: 100
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ SchedulerState.GasConfig memory gasConfig = SchedulerState.GasConfig({
|
|
|
|
|
+ maxGasMultiplierCapPct: 10_000,
|
|
|
|
|
+ maxFeeMultiplierCapPct: 10_000
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ SchedulerState.SubscriptionParams memory params = SchedulerState
|
|
|
|
|
+ .SubscriptionParams({
|
|
|
|
|
+ priceIds: priceIds,
|
|
|
|
|
+ readerWhitelist: readerWhitelist,
|
|
|
|
|
+ whitelistEnabled: true,
|
|
|
|
|
+ isActive: true,
|
|
|
|
|
+ updateCriteria: updateCriteria,
|
|
|
|
|
+ gasConfig: gasConfig
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ uint256 subscriptionId = scheduler.addSubscription{
|
|
|
|
|
+ value: minimumBalance
|
|
|
|
|
+ }(params);
|
|
|
|
|
+
|
|
|
|
|
+ // Add extra funds
|
|
|
|
|
+ uint256 extraFunds = 1 ether;
|
|
|
|
|
+ scheduler.addFunds{value: extraFunds}(subscriptionId);
|
|
|
|
|
|
|
|
// Get initial balance
|
|
// Get initial balance
|
|
|
uint256 initialBalance = address(this).balance;
|
|
uint256 initialBalance = address(this).balance;
|
|
|
|
|
|
|
|
- // Withdraw half the funds
|
|
|
|
|
- uint256 withdrawAmount = fundAmount / 2;
|
|
|
|
|
- scheduler.withdrawFunds(subscriptionId, withdrawAmount);
|
|
|
|
|
|
|
+ // Withdraw extra funds
|
|
|
|
|
+ scheduler.withdrawFunds(subscriptionId, extraFunds);
|
|
|
|
|
|
|
|
// Verify funds were withdrawn
|
|
// Verify funds were withdrawn
|
|
|
(, SchedulerState.SubscriptionStatus memory status) = scheduler
|
|
(, SchedulerState.SubscriptionStatus memory status) = scheduler
|
|
@@ -298,14 +451,34 @@ contract SchedulerTest is Test, SchedulerEvents, PulseTestUtils {
|
|
|
|
|
|
|
|
assertEq(
|
|
assertEq(
|
|
|
status.balanceInWei,
|
|
status.balanceInWei,
|
|
|
- fundAmount - withdrawAmount,
|
|
|
|
|
- "Remaining balance incorrect"
|
|
|
|
|
|
|
+ minimumBalance,
|
|
|
|
|
+ "Remaining balance should be minimum balance"
|
|
|
);
|
|
);
|
|
|
assertEq(
|
|
assertEq(
|
|
|
address(this).balance,
|
|
address(this).balance,
|
|
|
- initialBalance + withdrawAmount,
|
|
|
|
|
|
|
+ initialBalance + extraFunds,
|
|
|
"Withdrawn amount not received"
|
|
"Withdrawn amount not received"
|
|
|
);
|
|
);
|
|
|
|
|
+
|
|
|
|
|
+ // Try to withdraw below minimum balance
|
|
|
|
|
+ vm.expectRevert(abi.encodeWithSelector(InsufficientBalance.selector));
|
|
|
|
|
+ scheduler.withdrawFunds(subscriptionId, 1 wei);
|
|
|
|
|
+
|
|
|
|
|
+ // Deactivate subscription
|
|
|
|
|
+ params.isActive = false;
|
|
|
|
|
+ scheduler.updateSubscription(subscriptionId, params);
|
|
|
|
|
+
|
|
|
|
|
+ // Now we should be able to withdraw all funds
|
|
|
|
|
+ scheduler.withdrawFunds(subscriptionId, minimumBalance);
|
|
|
|
|
+
|
|
|
|
|
+ // Verify all funds were withdrawn
|
|
|
|
|
+ (, status) = scheduler.getSubscription(subscriptionId);
|
|
|
|
|
+
|
|
|
|
|
+ assertEq(
|
|
|
|
|
+ status.balanceInWei,
|
|
|
|
|
+ 0,
|
|
|
|
|
+ "Balance should be 0 after withdrawing all funds"
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function testUpdatePriceFeedsWorks() public {
|
|
function testUpdatePriceFeedsWorks() public {
|
|
@@ -697,11 +870,17 @@ contract SchedulerTest is Test, SchedulerEvents, PulseTestUtils {
|
|
|
priceIds: priceIds,
|
|
priceIds: priceIds,
|
|
|
readerWhitelist: emptyWhitelist,
|
|
readerWhitelist: emptyWhitelist,
|
|
|
whitelistEnabled: false, // No whitelist
|
|
whitelistEnabled: false, // No whitelist
|
|
|
|
|
+ isActive: true,
|
|
|
updateCriteria: updateCriteria,
|
|
updateCriteria: updateCriteria,
|
|
|
gasConfig: gasConfig
|
|
gasConfig: gasConfig
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- uint256 subscriptionId = scheduler.addSubscription(params);
|
|
|
|
|
|
|
+ uint256 minimumBalance = scheduler.getMinimumBalance(
|
|
|
|
|
+ uint8(priceIds.length)
|
|
|
|
|
+ );
|
|
|
|
|
+ uint256 subscriptionId = scheduler.addSubscription{
|
|
|
|
|
+ value: minimumBalance
|
|
|
|
|
+ }(params);
|
|
|
|
|
|
|
|
// Update price feeds
|
|
// Update price feeds
|
|
|
uint256 fundAmount = 1 ether;
|
|
uint256 fundAmount = 1 ether;
|
|
@@ -790,13 +969,13 @@ contract SchedulerTest is Test, SchedulerEvents, PulseTestUtils {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function testGetActiveSubscriptions() public {
|
|
function testGetActiveSubscriptions() public {
|
|
|
- // Add multiple subscriptions with the test contract as manager
|
|
|
|
|
- addTestSubscription();
|
|
|
|
|
- addTestSubscription();
|
|
|
|
|
- uint256 subscriptionId = addTestSubscription();
|
|
|
|
|
|
|
+ console.log("Starting testGetActiveSubscriptions");
|
|
|
|
|
|
|
|
- // Verify we can deactivate our own subscription
|
|
|
|
|
- scheduler.deactivateSubscription(subscriptionId);
|
|
|
|
|
|
|
+ // Add two subscriptions with the test contract as manager
|
|
|
|
|
+ uint256 sub1 = addTestSubscription();
|
|
|
|
|
+ uint256 sub2 = addTestSubscription();
|
|
|
|
|
+
|
|
|
|
|
+ console.log("Added 2 test subscriptions with IDs:", sub1, sub2);
|
|
|
|
|
|
|
|
// Create a subscription with pusher as manager
|
|
// Create a subscription with pusher as manager
|
|
|
vm.startPrank(pusher);
|
|
vm.startPrank(pusher);
|
|
@@ -816,27 +995,38 @@ contract SchedulerTest is Test, SchedulerEvents, PulseTestUtils {
|
|
|
maxFeeMultiplierCapPct: 10_000
|
|
maxFeeMultiplierCapPct: 10_000
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- SchedulerState.SubscriptionParams memory params = SchedulerState
|
|
|
|
|
|
|
+ SchedulerState.SubscriptionParams memory pusherParams = SchedulerState
|
|
|
.SubscriptionParams({
|
|
.SubscriptionParams({
|
|
|
priceIds: priceIds,
|
|
priceIds: priceIds,
|
|
|
readerWhitelist: emptyWhitelist,
|
|
readerWhitelist: emptyWhitelist,
|
|
|
whitelistEnabled: false,
|
|
whitelistEnabled: false,
|
|
|
|
|
+ isActive: true,
|
|
|
updateCriteria: updateCriteria,
|
|
updateCriteria: updateCriteria,
|
|
|
gasConfig: gasConfig
|
|
gasConfig: gasConfig
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- scheduler.addSubscription(params);
|
|
|
|
|
|
|
+ uint256 minimumBalance = scheduler.getMinimumBalance(
|
|
|
|
|
+ uint8(priceIds.length)
|
|
|
|
|
+ );
|
|
|
|
|
+ uint256 pusherSub = scheduler.addSubscription{value: minimumBalance}(
|
|
|
|
|
+ pusherParams
|
|
|
|
|
+ );
|
|
|
|
|
+ console.log("Added pusher subscription with ID:", pusherSub);
|
|
|
vm.stopPrank();
|
|
vm.stopPrank();
|
|
|
|
|
|
|
|
- // Get active subscriptions - use owner who has admin rights
|
|
|
|
|
- vm.prank(owner);
|
|
|
|
|
- (
|
|
|
|
|
- uint256[] memory activeIds,
|
|
|
|
|
- SchedulerState.SubscriptionParams[] memory activeParams,
|
|
|
|
|
- uint256 totalCount
|
|
|
|
|
- ) = scheduler.getActiveSubscriptions(0, 10); // Start at index 0, get up to 10 results
|
|
|
|
|
|
|
+ // Get active subscriptions directly - should work without any special permissions
|
|
|
|
|
+ uint256[] memory activeIds;
|
|
|
|
|
+ SchedulerState.SubscriptionParams[] memory activeParams;
|
|
|
|
|
+ uint256 totalCount;
|
|
|
|
|
|
|
|
- // Verify active subscriptions
|
|
|
|
|
|
|
+ (activeIds, activeParams, totalCount) = scheduler
|
|
|
|
|
+ .getActiveSubscriptions(0, 10);
|
|
|
|
|
+ console.log(
|
|
|
|
|
+ "getActiveSubscriptions succeeded, total count:",
|
|
|
|
|
+ totalCount
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // We added 3 subscriptions and all should be active
|
|
|
assertEq(activeIds.length, 3, "Should have 3 active subscriptions");
|
|
assertEq(activeIds.length, 3, "Should have 3 active subscriptions");
|
|
|
assertEq(
|
|
assertEq(
|
|
|
activeParams.length,
|
|
activeParams.length,
|
|
@@ -867,11 +1057,8 @@ contract SchedulerTest is Test, SchedulerEvents, PulseTestUtils {
|
|
|
|
|
|
|
|
// Test pagination - get only the first subscription
|
|
// Test pagination - get only the first subscription
|
|
|
vm.prank(owner);
|
|
vm.prank(owner);
|
|
|
- (
|
|
|
|
|
- uint256[] memory firstPageIds,
|
|
|
|
|
- SchedulerState.SubscriptionParams[] memory firstPageParams,
|
|
|
|
|
- uint256 firstPageTotal
|
|
|
|
|
- ) = scheduler.getActiveSubscriptions(0, 1);
|
|
|
|
|
|
|
+ (uint256[] memory firstPageIds, , uint256 firstPageTotal) = scheduler
|
|
|
|
|
+ .getActiveSubscriptions(0, 1);
|
|
|
|
|
|
|
|
assertEq(
|
|
assertEq(
|
|
|
firstPageIds.length,
|
|
firstPageIds.length,
|
|
@@ -882,11 +1069,8 @@ contract SchedulerTest is Test, SchedulerEvents, PulseTestUtils {
|
|
|
|
|
|
|
|
// Test pagination - get the second page
|
|
// Test pagination - get the second page
|
|
|
vm.prank(owner);
|
|
vm.prank(owner);
|
|
|
- (
|
|
|
|
|
- uint256[] memory secondPageIds,
|
|
|
|
|
- SchedulerState.SubscriptionParams[] memory secondPageParams,
|
|
|
|
|
- uint256 secondPageTotal
|
|
|
|
|
- ) = scheduler.getActiveSubscriptions(1, 2);
|
|
|
|
|
|
|
+ (uint256[] memory secondPageIds, , uint256 secondPageTotal) = scheduler
|
|
|
|
|
+ .getActiveSubscriptions(1, 2);
|
|
|
|
|
|
|
|
assertEq(
|
|
assertEq(
|
|
|
secondPageIds.length,
|
|
secondPageIds.length,
|
|
@@ -935,11 +1119,15 @@ contract SchedulerTest is Test, SchedulerEvents, PulseTestUtils {
|
|
|
priceIds: priceIds,
|
|
priceIds: priceIds,
|
|
|
readerWhitelist: readerWhitelist,
|
|
readerWhitelist: readerWhitelist,
|
|
|
whitelistEnabled: true,
|
|
whitelistEnabled: true,
|
|
|
|
|
+ isActive: true,
|
|
|
updateCriteria: updateCriteria,
|
|
updateCriteria: updateCriteria,
|
|
|
gasConfig: gasConfig
|
|
gasConfig: gasConfig
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- return scheduler.addSubscription(params);
|
|
|
|
|
|
|
+ uint256 minimumBalance = scheduler.getMinimumBalance(
|
|
|
|
|
+ uint8(priceIds.length)
|
|
|
|
|
+ );
|
|
|
|
|
+ return scheduler.addSubscription{value: minimumBalance}(params);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Helper function to add a test subscription with variable number of feeds
|
|
// Helper function to add a test subscription with variable number of feeds
|
|
@@ -968,11 +1156,15 @@ contract SchedulerTest is Test, SchedulerEvents, PulseTestUtils {
|
|
|
priceIds: priceIds,
|
|
priceIds: priceIds,
|
|
|
readerWhitelist: readerWhitelist,
|
|
readerWhitelist: readerWhitelist,
|
|
|
whitelistEnabled: true,
|
|
whitelistEnabled: true,
|
|
|
|
|
+ isActive: true,
|
|
|
updateCriteria: updateCriteria,
|
|
updateCriteria: updateCriteria,
|
|
|
gasConfig: gasConfig
|
|
gasConfig: gasConfig
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- return scheduler.addSubscription(params);
|
|
|
|
|
|
|
+ uint256 minimumBalance = scheduler.getMinimumBalance(
|
|
|
|
|
+ uint8(priceIds.length)
|
|
|
|
|
+ );
|
|
|
|
|
+ return scheduler.addSubscription{value: minimumBalance}(params);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Helper function to add a test subscription with specific update criteria
|
|
// Helper function to add a test subscription with specific update criteria
|
|
@@ -993,11 +1185,15 @@ contract SchedulerTest is Test, SchedulerEvents, PulseTestUtils {
|
|
|
priceIds: priceIds,
|
|
priceIds: priceIds,
|
|
|
readerWhitelist: readerWhitelist,
|
|
readerWhitelist: readerWhitelist,
|
|
|
whitelistEnabled: true,
|
|
whitelistEnabled: true,
|
|
|
|
|
+ isActive: true,
|
|
|
updateCriteria: updateCriteria, // Use provided criteria
|
|
updateCriteria: updateCriteria, // Use provided criteria
|
|
|
gasConfig: gasConfig
|
|
gasConfig: gasConfig
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- return scheduler.addSubscription(params);
|
|
|
|
|
|
|
+ uint256 minimumBalance = scheduler.getMinimumBalance(
|
|
|
|
|
+ uint8(priceIds.length)
|
|
|
|
|
+ );
|
|
|
|
|
+ return scheduler.addSubscription{value: minimumBalance}(params);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Required to receive ETH when withdrawing funds
|
|
// Required to receive ETH when withdrawing funds
|