@@ -262,6 +262,53 @@ func TestAsyncBlockRetriever_ReconnectOnSubscriptionError(t *testing.T) {
262262 assert .Equal (t , []byte ("reconnect-tx" ), block .Blobs [0 ])
263263}
264264
265+ func TestAsyncBlockRetriever_FetchAndCacheBlock_ErrorResponse (t * testing.T ) {
266+ fiNs := datypes .NamespaceFromString ("test-fi-ns" ).Bytes ()
267+ specs := map [string ]struct {
268+ code datypes.StatusCode
269+ message string
270+ wantErr string
271+ }{
272+ "status_error" : {
273+ code : datypes .StatusError ,
274+ message : "rpc failure" ,
275+ wantErr : "retrieve block at height 123: rpc failure" ,
276+ },
277+ "status_context_deadline" : {
278+ code : datypes .StatusContextDeadline ,
279+ message : "timeout" ,
280+ wantErr : "retrieve block at height 123: timeout" ,
281+ },
282+ }
283+
284+ for name , spec := range specs {
285+ t .Run (name , func (t * testing.T ) {
286+ client := & mocks.MockClient {}
287+ client .
288+ On ("Retrieve" , mock .Anything , uint64 (123 ), fiNs ).
289+ Return (datypes.ResultRetrieve {
290+ BaseResult : datypes.BaseResult {
291+ Code : spec .code ,
292+ Message : spec .message ,
293+ },
294+ }).
295+ Once ()
296+
297+ logger := zerolog .Nop ()
298+ fetcher := NewAsyncBlockRetriever (client , logger , fiNs , 100 * time .Millisecond , 100 , 10 ).(* asyncBlockRetriever )
299+
300+ err := fetcher .fetchAndCacheBlock (t .Context (), 123 )
301+ require .EqualError (t , err , spec .wantErr )
302+
303+ block , getErr := fetcher .GetCachedBlock (t .Context (), 123 )
304+ require .NoError (t , getErr )
305+ assert .Nil (t , block )
306+
307+ client .AssertExpectations (t )
308+ })
309+ }
310+ }
311+
265312func TestBlockData_Serialization (t * testing.T ) {
266313 block := & BlockData {
267314 Height : 100 ,
0 commit comments