@@ -2,6 +2,7 @@ import { TIME_CONSTANTS } from '@filoz/synapse-sdk'
22import { describe , expect , it } from 'vitest'
33import {
44 computeAdjustmentForExactDays ,
5+ computeAdjustmentForExactDaysWithFile ,
56 computeAdjustmentForExactDeposit ,
67 computeTopUpForDuration ,
78 type PaymentStatus ,
@@ -142,3 +143,38 @@ describe('computeAdjustmentForExactDeposit', () => {
142143 expect ( res . clampedTarget ) . toBe ( 1_500n )
143144 } )
144145} )
146+
147+ describe ( 'computeAdjustmentForExactDaysWithFile' , ( ) => {
148+ it ( 'calculates deposit for new file when rateUsed is 0' , ( ) => {
149+ // Scenario: No existing storage, uploading first file
150+ const status = makeStatus ( { depositedAmount : 0n , lockupUsed : 0n , rateUsed : 0n } )
151+ const carSizeBytes = 1024 * 1024 * 1024 // 1 GiB
152+ const pricePerTiBPerEpoch = 1_000_000_000_000_000n // 0.001 USDFC per TiB per epoch
153+ const days = 30
154+
155+ const res = computeAdjustmentForExactDaysWithFile ( status , days , carSizeBytes , pricePerTiBPerEpoch )
156+
157+ // Should require deposit for both lockup and runway
158+ expect ( res . delta ) . toBeGreaterThan ( 0n )
159+ expect ( res . newRateUsed ) . toBeGreaterThan ( 0n )
160+ expect ( res . newLockupUsed ) . toBeGreaterThan ( 0n )
161+ } )
162+
163+ it ( 'adds file requirements to existing usage' , ( ) => {
164+ // Scenario: Existing storage, adding another file
165+ const rateUsed = 1_000_000_000_000_000_000n // 1 USDFC/epoch
166+ const lockupUsed = rateUsed * BigInt ( 10 ) * TIME_CONSTANTS . EPOCHS_PER_DAY // 10 days worth
167+ const depositedAmount = ( lockupUsed * 12n ) / 10n // 20% buffer
168+ const status = makeStatus ( { depositedAmount, lockupUsed, rateUsed } )
169+
170+ const carSizeBytes = 1024 * 1024 * 1024 // 1 GiB
171+ const pricePerTiBPerEpoch = 1_000_000_000_000_000n // 0.001 USDFC per TiB per epoch
172+ const days = 30
173+
174+ const res = computeAdjustmentForExactDaysWithFile ( status , days , carSizeBytes , pricePerTiBPerEpoch )
175+
176+ // New rate should be higher than existing
177+ expect ( res . newRateUsed ) . toBeGreaterThan ( rateUsed )
178+ expect ( res . newLockupUsed ) . toBeGreaterThan ( lockupUsed )
179+ } )
180+ } )
0 commit comments