@@ -107,95 +107,6 @@ func TestHeadersConjunctionProperty(t *testing.T) {
107107 }
108108}
109109
110- // TestImportSkipOperation tests the import skip operation. It checks that
111- // the import is skipped if the target header store is populated with headers.
112- func TestImportSkipOperation (t * testing.T ) {
113- t .Parallel ()
114- ctx := context .Background ()
115- type Prep struct {
116- options * ImportOptions
117- }
118- type Verify struct {
119- tc * testing.T
120- importOptions * ImportOptions
121- importResult * ImportResult
122- }
123- testCases := []struct {
124- name string
125- prep func () Prep
126- verify func (Verify )
127- expectErr bool
128- expectErrMsg string
129- }{
130- {
131- name : "TargetFilterStorePopulatedWithHeaders" ,
132- prep : func () Prep {
133- // Mock target block header store.
134- tBS := & headerfs.MockBlockHeaderStore {}
135- tBS .On ("ChainTip" ).Return (
136- & wire.BlockHeader {}, uint32 (0 ), nil ,
137- )
138-
139- // Mock target filter header store.
140- tFS := & headerfs.MockFilterHeaderStore {}
141- tFS .On ("ChainTip" ).Return (
142- & chainhash.Hash {}, uint32 (3 ), nil ,
143- )
144-
145- // Configure header import sources.
146- bIS := "/path/to/blocks"
147- fIS := "/path/to/filters"
148-
149- ops := & ImportOptions {
150- BlockHeadersSource : bIS ,
151- FilterHeadersSource : fIS ,
152- TargetBlockHeaderStore : tBS ,
153- TargetFilterHeaderStore : tFS ,
154- }
155-
156- return Prep {
157- options : ops ,
158- }
159- },
160- verify : func (v Verify ) {
161- // Verify the default batch size is set.
162- ops := v .importOptions
163- require .Equal (
164- v .tc , DefaultWriteBatchSizePerRegion ,
165- ops .WriteBatchSizePerRegion ,
166- )
167-
168- // Verify no headers added/processed.
169- require .Equal (
170- v .tc , 0 , v .importResult .AddedCount ,
171- )
172- require .Equal (
173- v .tc , 0 , v .importResult .ProcessedCount ,
174- )
175- },
176- },
177- }
178-
179- for _ , tc := range testCases {
180- t .Run (tc .name , func (t * testing.T ) {
181- prep := tc .prep ()
182- importResult , err := prep .options .Import (ctx )
183- verify := Verify {
184- tc : t ,
185- importOptions : prep .options ,
186- importResult : importResult ,
187- }
188- if tc .expectErr {
189- require .ErrorContains (t , err , tc .expectErrMsg )
190- tc .verify (verify )
191- return
192- }
193- require .NoError (t , err )
194- tc .verify (verify )
195- })
196- }
197- }
198-
199110// TestImportOperationOnFileHeaderSource tests the import operation on a file
200111// header source. It checks that the import is successful and that the headers
201112// are written to the target header stores.
@@ -599,104 +510,6 @@ func TestImportOperationOnHTTPHeaderSource(t *testing.T) {
599510 }
600511}
601512
602- // TestTargetStoreFreshnessDetection tests the logic for detecting whether the
603- // target header stores are fresh (only contain genesis headers). It covers
604- // various combinations of block and filter header heights and error cases.
605- func TestTargetStoreFreshnessDetection (t * testing.T ) {
606- t .Parallel ()
607- testCases := []struct {
608- name string
609- blockHeight uint32
610- filterHeight uint32
611- expectFresh bool
612- expectErr bool
613- expectFilterStoreErr error
614- expectBlockStoreErr error
615- }{
616- {
617- name : "OnlyGenesisHeadersExist" ,
618- blockHeight : 0 ,
619- filterHeight : 0 ,
620- expectFresh : true ,
621- },
622- {
623- name : "BlockHeightGreaterThanZero" ,
624- blockHeight : 1 ,
625- filterHeight : 0 ,
626- expectFresh : false ,
627- },
628- {
629- name : "FilterHeightGreaterThanZero" ,
630- blockHeight : 0 ,
631- filterHeight : 1 ,
632- expectFresh : false ,
633- },
634- {
635- name : "BothHeightsGreaterThanZero" ,
636- blockHeight : 10 ,
637- filterHeight : 10 ,
638- expectFresh : false ,
639- },
640- {
641- name : "ErrorOnBlockStore" ,
642- expectErr : true ,
643- expectBlockStoreErr : errors .New (
644- "failed to get target block header" ,
645- ),
646- },
647- {
648- name : "ErrorOnFilterStore" ,
649- expectErr : true ,
650- expectFilterStoreErr : errors .New (
651- "failed to get target filter header" ,
652- ),
653- },
654- }
655-
656- for _ , tc := range testCases {
657- t .Run (tc .name , func (t * testing.T ) {
658- // Setup mock block header store.
659- mockBlockStore := & headerfs.MockBlockHeaderStore {}
660- mockBlockStore .On ("ChainTip" ).Return (
661- & wire.BlockHeader {}, tc .blockHeight ,
662- tc .expectBlockStoreErr ,
663- )
664-
665- // Setup mock filter header store.
666- mockFilterStore := & headerfs.MockFilterHeaderStore {}
667- mockFilterStore .On ("ChainTip" ).Return (
668- & chainhash.Hash {}, tc .filterHeight ,
669- tc .expectFilterStoreErr ,
670- )
671-
672- // Create importer.
673- importer := & HeadersImport {}
674-
675- // Test the function.
676- isFresh , err := importer .isTargetFresh (
677- mockBlockStore , mockFilterStore ,
678- )
679- if tc .expectErr {
680- if tc .expectBlockStoreErr != nil {
681- require .ErrorContains (
682- t , err ,
683- tc .expectBlockStoreErr .Error (),
684- )
685- }
686- if tc .expectFilterStoreErr != nil {
687- require .ErrorContains (
688- t , err ,
689- tc .expectFilterStoreErr .Error (),
690- )
691- }
692- return
693- }
694- require .NoError (t , err )
695- require .Equal (t , isFresh , tc .expectFresh )
696- })
697- }
698- }
699-
700513// TestOpenFileHeaderImportSources tests the open operation on a file header
701514// import source.
702515func TestOpenFileHeaderImportSources (t * testing.T ) {
0 commit comments