@@ -178,19 +178,20 @@ func TestCache_RestoreFromStore_PlaceholderOverwrittenByRealHash(t *testing.T) {
178178 assert .Equal (t , uint64 (99 ), daH )
179179}
180180
181- // TestCache_RestoreFromStore_RoundTrip verifies that setDAIncluded persists a
181+ // TestCache_RestoreFromStore_RoundTrip verifies that SaveToStore persists a
182182// snapshot that a freshly-constructed cache can fully recover.
183183func TestCache_RestoreFromStore_RoundTrip (t * testing.T ) {
184184 st := testMemStore (t )
185185 ctx := context .Background ()
186186
187- // First cache instance: write some in-flight entries.
187+ // First cache instance: write some in-flight entries, then flush (shutdown) .
188188 c1 := NewCache [testItem ](st , "rt/" )
189189 c1 .setDAIncluded ("hashA" , 10 , 1 )
190190 c1 .setDAIncluded ("hashB" , 20 , 2 )
191191 c1 .setDAIncluded ("hashC" , 30 , 3 )
192192 // Remove one entry to confirm deletions are also snapshotted.
193193 c1 .removeDAIncluded ("hashB" )
194+ require .NoError (t , c1 .SaveToStore (ctx ))
194195
195196 // Second cache instance on same store: should recover {hashA→10, hashC→30}.
196197 c2 := NewCache [testItem ](st , "rt/" )
@@ -324,6 +325,7 @@ func TestCache_ClearFromStore(t *testing.T) {
324325 c := NewCache [testItem ](st , "clear-test/" )
325326 c .setDAIncluded ("hash1" , 100 , 1 )
326327 c .setDAIncluded ("hash2" , 200 , 2 )
328+ require .NoError (t , c .SaveToStore (ctx ))
327329
328330 // Verify the snapshot key was written before clearing.
329331 _ , err := st .GetMetadata (ctx , "clear-test/__snap" )
@@ -381,9 +383,10 @@ func TestCache_NoPlaceholderLeakAfterRefire(t *testing.T) {
381383 st := testMemStore (t )
382384 ctx := context .Background ()
383385
384- // Step 1: initial run — write a real hash for height 3.
386+ // Step 1: initial run — write a real hash for height 3, then flush (shutdown) .
385387 c1 := NewCache [testItem ](st , "pfx/" )
386388 c1 .setDAIncluded ("realHash3" , 99 , 3 )
389+ require .NoError (t , c1 .SaveToStore (ctx ))
387390 // snapshot now contains [{blockHeight:3, daHeight:99}]
388391
389392 // Step 2: restart — placeholder installed for height 3.
@@ -424,9 +427,10 @@ func TestCache_RestartIdempotent(t *testing.T) {
424427 const blockH = uint64 (5 )
425428 const daH = uint64 (42 )
426429
427- // ── Run 1: normal operation, height 5 in-flight ─────────────────── ───────
430+ // ── Run 1: normal operation, height 5 in-flight; flush at shutdown ───────
428431 c1 := NewCache [testItem ](st , "pfx/" )
429432 c1 .setDAIncluded (realHash , daH , blockH )
433+ require .NoError (t , c1 .SaveToStore (ctx ))
430434 // snapshot: [{5, 42}]
431435
432436 for restart := 1 ; restart <= 3 ; restart ++ {
@@ -442,16 +446,16 @@ func TestCache_RestartIdempotent(t *testing.T) {
442446 require .True (t , ok , "restart %d: height-based lookup must succeed" , restart )
443447 assert .Equal (t , daH , gotDAH , "restart %d: height-based DA height correct" , restart )
444448
445- // ── DA retriever re-fires with the real hash
449+ // ── DA retriever re-fires with the real hash, then flushes (shutdown).
446450 cR .setDAIncluded (realHash , daH , blockH )
451+ require .NoError (t , cR .SaveToStore (ctx ), "restart %d: SaveToStore" , restart )
447452
448453 // After re-fire: real hash present, no orphan, snapshot updated.
449454 _ , realPresent := cR .daIncluded .Get (realHash )
450455 assert .True (t , realPresent , "restart %d: real hash present after re-fire" , restart )
451456 assert .Equal (t , 1 , cR .daIncluded .Len (), "restart %d: no orphan after re-fire" , restart )
452457
453- // The snapshot rewritten by re-fire must still encode the right data
458+ // The snapshot written by SaveToStore must still encode the right data
454459 // so the next restart can load it correctly.
455- // (persistSnapshot fires inside setDAIncluded, so the store is up to date.)
456460 }
457461}
0 commit comments