github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/executiondatasync/execution_data/downloader_test.go (about) 1 package execution_data_test 2 3 import ( 4 "context" 5 "math/rand" 6 "testing" 7 8 "github.com/ipfs/go-cid" 9 "github.com/ipfs/go-datastore" 10 dssync "github.com/ipfs/go-datastore/sync" 11 "github.com/stretchr/testify/assert" 12 "github.com/stretchr/testify/mock" 13 "github.com/stretchr/testify/require" 14 15 "github.com/onflow/flow-go/module/blobs" 16 "github.com/onflow/flow-go/module/executiondatasync/execution_data" 17 "github.com/onflow/flow-go/network/mocknetwork" 18 ) 19 20 func TestCIDNotFound(t *testing.T) { 21 blobstore := blobs.NewBlobstore(dssync.MutexWrap(datastore.NewMapDatastore())) 22 blobService := new(mocknetwork.BlobService) 23 downloader := execution_data.NewDownloader(blobService) 24 edStore := execution_data.NewExecutionDataStore(blobstore, execution_data.DefaultSerializer) 25 bed := generateBlockExecutionData(t, 10, 3*execution_data.DefaultMaxBlobSize) 26 edID, err := edStore.Add(context.Background(), bed) 27 require.NoError(t, err) 28 29 blobGetter := new(mocknetwork.BlobGetter) 30 blobService.On("GetSession", mock.Anything).Return(blobGetter, nil) 31 blobGetter.On("GetBlob", mock.Anything, mock.AnythingOfType("cid.Cid")).Return( 32 func(ctx context.Context, c cid.Cid) blobs.Blob { 33 blob, _ := blobstore.Get(ctx, c) 34 return blob 35 }, 36 func(ctx context.Context, c cid.Cid) error { 37 _, err := blobstore.Get(ctx, c) 38 return err 39 }, 40 ) 41 blobGetter.On("GetBlobs", mock.Anything, mock.AnythingOfType("[]cid.Cid")).Return( 42 func(ctx context.Context, cids []cid.Cid) <-chan blobs.Blob { 43 blobCh := make(chan blobs.Blob, len(cids)) 44 missingIdx := rand.Intn(len(cids)) 45 for i, c := range cids { 46 if i != missingIdx { 47 blob, err := blobstore.Get(ctx, c) 48 assert.NoError(t, err) 49 blobCh <- blob 50 } 51 } 52 close(blobCh) 53 return blobCh 54 }, 55 ) 56 57 _, err = downloader.Get(context.Background(), edID) 58 var blobNotFoundError *execution_data.BlobNotFoundError 59 assert.ErrorAs(t, err, &blobNotFoundError) 60 }