@@ -130,7 +130,7 @@ func collectEvents(t *testing.T, ch <-chan common.DAHeightEvent, timeout time.Du
130130 }
131131}
132132
133- func TestP2PHandler_ProcessRange_EmitsEventWhenHeaderAndDataPresent (t * testing.T ) {
133+ func TestP2PHandler_ProcessHeight_EmitsEventWhenHeaderAndDataPresent (t * testing.T ) {
134134 p := setupP2P (t )
135135 ctx := context .Background ()
136136
@@ -149,15 +149,16 @@ func TestP2PHandler_ProcessRange_EmitsEventWhenHeaderAndDataPresent(t *testing.T
149149 p .DataStore .EXPECT ().GetByHeight (mock .Anything , uint64 (5 )).Return (data , nil ).Once ()
150150
151151 ch := make (chan common.DAHeightEvent , 1 )
152- p .Handler .ProcessHeaderRange (ctx , 5 , 5 , ch )
152+ err = p .Handler .ProcessHeight (ctx , 5 , ch )
153+ require .NoError (t , err )
153154
154155 events := collectEvents (t , ch , 50 * time .Millisecond )
155156 require .Len (t , events , 1 )
156157 require .Equal (t , uint64 (5 ), events [0 ].Header .Height ())
157158 require .NotNil (t , events [0 ].Data )
158159}
159160
160- func TestP2PHandler_ProcessRange_SkipsWhenDataMissing (t * testing.T ) {
161+ func TestP2PHandler_ProcessHeight_SkipsWhenDataMissing (t * testing.T ) {
161162 p := setupP2P (t )
162163 ctx := context .Background ()
163164
@@ -174,27 +175,30 @@ func TestP2PHandler_ProcessRange_SkipsWhenDataMissing(t *testing.T) {
174175 p .DataStore .EXPECT ().GetByHeight (mock .Anything , uint64 (7 )).Return (nil , errors .New ("missing" )).Once ()
175176
176177 ch := make (chan common.DAHeightEvent , 1 )
177- p .Handler .ProcessHeaderRange (ctx , 7 , 7 , ch )
178+ err = p .Handler .ProcessHeight (ctx , 7 , ch )
179+ require .Error (t , err )
178180
179181 require .Empty (t , collectEvents (t , ch , 50 * time .Millisecond ))
180182}
181183
182- func TestP2PHandler_ProcessRange_SkipsWhenHeaderMissing (t * testing.T ) {
184+ func TestP2PHandler_ProcessHeight_SkipsWhenHeaderMissing (t * testing.T ) {
183185 p := setupP2P (t )
184186 ctx := context .Background ()
185187
186188 p .HeaderStore .EXPECT ().GetByHeight (mock .Anything , uint64 (9 )).Return (nil , errors .New ("missing" )).Once ()
187189
188190 ch := make (chan common.DAHeightEvent , 1 )
189- p .Handler .ProcessHeaderRange (ctx , 9 , 9 , ch )
191+ err := p .Handler .ProcessHeight (ctx , 9 , ch )
192+ require .Error (t , err )
190193
191194 require .Empty (t , collectEvents (t , ch , 50 * time .Millisecond ))
192195 p .DataStore .AssertNotCalled (t , "GetByHeight" , mock .Anything , uint64 (9 ))
193196}
194197
195- func TestP2PHandler_ProcessRange_SkipsOnProposerMismatch (t * testing.T ) {
198+ func TestP2PHandler_ProcessHeight_SkipsOnProposerMismatch (t * testing.T ) {
196199 p := setupP2P (t )
197200 ctx := context .Background ()
201+ var err error
198202
199203 badAddr , pub , signer := buildTestSigner (t )
200204 require .NotEqual (t , string (p .Genesis .ProposerAddress ), string (badAddr ))
@@ -205,19 +209,29 @@ func TestP2PHandler_ProcessRange_SkipsOnProposerMismatch(t *testing.T) {
205209 p .HeaderStore .EXPECT ().GetByHeight (mock .Anything , uint64 (11 )).Return (header , nil ).Once ()
206210
207211 ch := make (chan common.DAHeightEvent , 1 )
208- p .Handler .ProcessHeaderRange (ctx , 11 , 11 , ch )
212+ err = p .Handler .ProcessHeight (ctx , 11 , ch )
213+ require .Error (t , err )
209214
210215 require .Empty (t , collectEvents (t , ch , 50 * time .Millisecond ))
211216 p .DataStore .AssertNotCalled (t , "GetByHeight" , mock .Anything , uint64 (11 ))
212217}
213218
214- func TestP2PHandler_ProcessRange_UsesProcessedHeightToSkip (t * testing.T ) {
219+ func TestP2PHandler_ProcessedHeightSkipsPreviouslyHandledBlocks (t * testing.T ) {
215220 p := setupP2P (t )
216221 ctx := context .Background ()
217222
218223 // Mark up to height 5 as processed.
219224 p .Handler .SetProcessedHeight (5 )
220225
226+ ch := make (chan common.DAHeightEvent , 1 )
227+
228+ // Heights below or equal to 5 should be skipped without touching the stores.
229+ require .NoError (t , p .Handler .ProcessHeight (ctx , 4 , ch ))
230+ require .Empty (t , collectEvents (t , ch , 50 * time .Millisecond ))
231+ p .HeaderStore .AssertNotCalled (t , "GetByHeight" , mock .Anything , uint64 (4 ))
232+ p .DataStore .AssertNotCalled (t , "GetByHeight" , mock .Anything , uint64 (4 ))
233+
234+ // Height 6 should be fetched normally.
221235 header := p2pMakeSignedHeader (t , p .Genesis .ChainID , 6 , p .ProposerAddr , p .ProposerPub , p .Signer )
222236 data := makeData (p .Genesis .ChainID , 6 , 1 )
223237 header .DataHash = data .DACommitment ()
@@ -230,15 +244,14 @@ func TestP2PHandler_ProcessRange_UsesProcessedHeightToSkip(t *testing.T) {
230244 p .HeaderStore .EXPECT ().GetByHeight (mock .Anything , uint64 (6 )).Return (header , nil ).Once ()
231245 p .DataStore .EXPECT ().GetByHeight (mock .Anything , uint64 (6 )).Return (data , nil ).Once ()
232246
233- ch := make (chan common.DAHeightEvent , 1 )
234- p .Handler .ProcessHeaderRange (ctx , 4 , 6 , ch )
247+ require .NoError (t , p .Handler .ProcessHeight (ctx , 6 , ch ))
235248
236249 events := collectEvents (t , ch , 50 * time .Millisecond )
237250 require .Len (t , events , 1 )
238251 require .Equal (t , uint64 (6 ), events [0 ].Header .Height ())
239252}
240253
241- func TestP2PHandler_OnHeightProcessedPreventsDuplicates (t * testing.T ) {
254+ func TestP2PHandler_SetProcessedHeightPreventsDuplicates (t * testing.T ) {
242255 p := setupP2P (t )
243256 ctx := context .Background ()
244257
@@ -255,18 +268,18 @@ func TestP2PHandler_OnHeightProcessedPreventsDuplicates(t *testing.T) {
255268 p .DataStore .EXPECT ().GetByHeight (mock .Anything , uint64 (8 )).Return (data , nil ).Once ()
256269
257270 ch := make (chan common.DAHeightEvent , 1 )
258- p .Handler .ProcessHeaderRange (ctx , 8 , 8 , ch )
271+ require . NoError ( t , p .Handler .ProcessHeight (ctx , 8 , ch ) )
259272
260273 events := collectEvents (t , ch , 50 * time .Millisecond )
261274 require .Len (t , events , 1 )
262275
263- // Mark the height as processed; a subsequent range should skip lookups .
276+ // Mark the height as processed; a subsequent request should skip store access .
264277 p .Handler .SetProcessedHeight (8 )
265278
266279 p .HeaderStore .AssertExpectations (t )
267280 p .DataStore .AssertExpectations (t )
268281
269282 // No additional expectations set; if the handler queried the stores again the mock would fail.
270- p .Handler .ProcessHeaderRange (ctx , 7 , 8 , ch )
283+ require . NoError ( t , p .Handler .ProcessHeight (ctx , 8 , ch ) )
271284 require .Empty (t , collectEvents (t , ch , 50 * time .Millisecond ))
272285}
0 commit comments