@@ -783,6 +783,112 @@ contract SchedulerTest is Test, SchedulerEvents, PulseSchedulerTestUtils {
783783 scheduler.updateSubscription (subscriptionId, params);
784784 }
785785
786+ function testPermanentSubscriptionDepositLimit () public {
787+ // Test 1: Creating a permanent subscription with deposit exceeding MAX_DEPOSIT_LIMIT should fail
788+ SchedulerState.SubscriptionParams
789+ memory params = createDefaultSubscriptionParams (2 , address (reader));
790+ params.isPermanent = true ;
791+
792+ uint256 maxDepositLimit = 100 ether ; // Same as MAX_DEPOSIT_LIMIT in SchedulerState
793+ uint256 excessiveDeposit = maxDepositLimit + 1 ether ;
794+ vm.deal (address (this ), excessiveDeposit);
795+
796+ vm.expectRevert (
797+ abi.encodeWithSelector (MaxDepositLimitExceeded.selector )
798+ );
799+ scheduler.createSubscription {value: excessiveDeposit}(params);
800+
801+ // Test 2: Creating a permanent subscription with deposit within MAX_DEPOSIT_LIMIT should succeed
802+ uint256 validDeposit = maxDepositLimit;
803+ vm.deal (address (this ), validDeposit);
804+
805+ uint256 subscriptionId = scheduler.createSubscription {
806+ value: validDeposit
807+ }(params);
808+
809+ // Verify subscription was created correctly
810+ (
811+ SchedulerState.SubscriptionParams memory storedParams ,
812+ SchedulerState.SubscriptionStatus memory status
813+ ) = scheduler.getSubscription (subscriptionId);
814+
815+ assertTrue (
816+ storedParams.isPermanent,
817+ "Subscription should be permanent "
818+ );
819+ assertEq (
820+ status.balanceInWei,
821+ validDeposit,
822+ "Balance should match deposit amount "
823+ );
824+
825+ // Test 3: Adding funds to a permanent subscription with deposit exceeding MAX_DEPOSIT_LIMIT should fail
826+ uint256 largeAdditionalFunds = maxDepositLimit + 1 ;
827+ vm.deal (address (this ), largeAdditionalFunds);
828+
829+ vm.expectRevert (
830+ abi.encodeWithSelector (MaxDepositLimitExceeded.selector )
831+ );
832+ scheduler.addFunds {value: largeAdditionalFunds}(subscriptionId);
833+
834+ // Test 4: Adding funds to a permanent subscription within MAX_DEPOSIT_LIMIT should succeed
835+ // Create a non-permanent subscription to test partial funding
836+ SchedulerState.SubscriptionParams
837+ memory nonPermanentParams = createDefaultSubscriptionParams (
838+ 2 ,
839+ address (reader)
840+ );
841+ uint256 minimumBalance = scheduler.getMinimumBalance (
842+ uint8 (nonPermanentParams.priceIds.length )
843+ );
844+ vm.deal (address (this ), minimumBalance);
845+
846+ uint256 nonPermanentSubId = scheduler.createSubscription {
847+ value: minimumBalance
848+ }(nonPermanentParams);
849+
850+ // Add funds to the non-permanent subscription (should be within limit)
851+ uint256 validAdditionalFunds = 5 ether ;
852+ vm.deal (address (this ), validAdditionalFunds);
853+
854+ scheduler.addFunds {value: validAdditionalFunds}(nonPermanentSubId);
855+
856+ // Verify funds were added correctly
857+ (
858+ ,
859+ SchedulerState.SubscriptionStatus memory nonPermanentStatus
860+ ) = scheduler.getSubscription (nonPermanentSubId);
861+
862+ assertEq (
863+ nonPermanentStatus.balanceInWei,
864+ minimumBalance + validAdditionalFunds,
865+ "Balance should be increased by the funded amount "
866+ );
867+
868+ // Test 5: Non-permanent subscriptions should not be subject to the deposit limit
869+ uint256 largeDeposit = maxDepositLimit * 2 ;
870+ vm.deal (address (this ), largeDeposit);
871+
872+ SchedulerState.SubscriptionParams
873+ memory unlimitedParams = createDefaultSubscriptionParams (
874+ 2 ,
875+ address (reader)
876+ );
877+ uint256 unlimitedSubId = scheduler.createSubscription {
878+ value: largeDeposit
879+ }(unlimitedParams);
880+
881+ // Verify subscription was created with the large deposit
882+ (, SchedulerState.SubscriptionStatus memory unlimitedStatus ) = scheduler
883+ .getSubscription (unlimitedSubId);
884+
885+ assertEq (
886+ unlimitedStatus.balanceInWei,
887+ largeDeposit,
888+ "Non-permanent subscription should accept large deposits "
889+ );
890+ }
891+
786892 function testAnyoneCanAddFunds () public {
787893 // Create a subscription
788894 uint256 subscriptionId = addTestSubscription (
0 commit comments