@@ -140,6 +140,60 @@ describe('planFilecoinPayFunding', () => {
140140 expect ( plan . current . runway . state ) . toBe ( 'no-spend' )
141141 expect ( plan . projected . runway . state ) . toBe ( 'no-spend' )
142142 } )
143+
144+ it ( 'throws when both runway and deposit targets are provided' , async ( ) => {
145+ const status = makeStatus ( { filecoinPayBalance : 0n , wallet : 1_000n } )
146+ vi . spyOn ( paymentsIndex , 'getPaymentStatus' ) . mockResolvedValue ( status )
147+ vi . spyOn ( paymentsIndex , 'checkAndSetAllowances' ) . mockResolvedValue ( {
148+ updated : false ,
149+ currentAllowances : status . currentAllowances ,
150+ } )
151+ vi . spyOn ( paymentsIndex , 'validatePaymentRequirements' ) . mockReturnValue ( { isValid : true } )
152+
153+ await expect (
154+ planFilecoinPayFunding ( {
155+ synapse : synapseStub as any ,
156+ targetRunwayDays : 10 ,
157+ targetDeposit : 1_000n ,
158+ } )
159+ ) . rejects . toThrow ( 'Specify either targetRunwayDays or targetDeposit, not both' )
160+ } )
161+
162+ it ( 'throws when no target is provided' , async ( ) => {
163+ const status = makeStatus ( { filecoinPayBalance : 0n , wallet : 1_000n } )
164+ vi . spyOn ( paymentsIndex , 'getPaymentStatus' ) . mockResolvedValue ( status )
165+ vi . spyOn ( paymentsIndex , 'checkAndSetAllowances' ) . mockResolvedValue ( {
166+ updated : false ,
167+ currentAllowances : status . currentAllowances ,
168+ } )
169+ vi . spyOn ( paymentsIndex , 'validatePaymentRequirements' ) . mockReturnValue ( { isValid : true } )
170+
171+ await expect (
172+ planFilecoinPayFunding ( {
173+ synapse : synapseStub as any ,
174+ } )
175+ ) . rejects . toThrow ( 'A funding target is required' )
176+ } )
177+
178+ it ( 'fetches pricing when pieceSizeBytes is provided without pricePerTiBPerEpoch' , async ( ) => {
179+ const status = makeStatus ( { filecoinPayBalance : 0n , wallet : 1_000n } )
180+ vi . spyOn ( paymentsIndex , 'getPaymentStatus' ) . mockResolvedValue ( status )
181+ vi . spyOn ( paymentsIndex , 'checkAndSetAllowances' ) . mockResolvedValue ( {
182+ updated : false ,
183+ currentAllowances : status . currentAllowances ,
184+ } )
185+ vi . spyOn ( paymentsIndex , 'validatePaymentRequirements' ) . mockReturnValue ( { isValid : true } )
186+
187+ const { plan } = await planFilecoinPayFunding ( {
188+ synapse : synapseStub as any ,
189+ targetRunwayDays : 10 ,
190+ pieceSizeBytes : 1024 ,
191+ } )
192+
193+ expect ( plan . pricePerTiBPerEpoch ) . toBe ( 1n )
194+ expect ( plan . delta ) . toBeGreaterThan ( 0n )
195+ expect ( plan . reasonCode ) . toBe ( 'runway-with-piece' )
196+ } )
143197} )
144198
145199describe ( 'executeFilecoinPayFunding' , ( ) => {
0 commit comments