diff --git a/blob/blob.go b/blob/blob.go index b3c9a0b980..9844ced8bf 100644 --- a/blob/blob.go +++ b/blob/blob.go @@ -144,7 +144,7 @@ func (b *Blob) UnmarshalJSON(data []byte) error { // It will build blobs either until appShares will be empty or the first incomplete blob will appear, so in this // specific case it will return all built blobs + remaining shares. func buildBlobsIfExist(appShares []shares.Share) ([]*Blob, []shares.Share, error) { - blobs := make([]*Blob, 0) + blobs := make([]*Blob, 0, len(appShares)) for { if len(appShares) == 0 { return blobs, nil, nil diff --git a/blob/service_test.go b/blob/service_test.go index 64296b969c..6777084eb4 100644 --- a/blob/service_test.go +++ b/blob/service_test.go @@ -344,6 +344,25 @@ func TestService_GetSingleBlobWithoutPadding(t *testing.T) { assert.Equal(t, newBlob.Commitment, blobs[1].Commitment) } +func TestService_Get(t *testing.T) { + ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) + t.Cleanup(cancel) + + sizes := []int{1, 6, 3, 2, 4, 6, 8, 2, 15, 17} + + appBlobs, err := blobtest.GenerateV0Blobs(sizes, true) + require.NoError(t, err) + blobs, err := convertBlobs(appBlobs...) + require.NoError(t, err) + + service := createService(ctx, t, blobs) + for _, blob := range blobs { + b, err := service.Get(ctx, 1, blob.Namespace(), blob.Commitment) + require.NoError(t, err) + assert.Equal(t, b.Commitment, blob.Commitment) + } +} + func TestService_GetAllWithoutPadding(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) t.Cleanup(cancel)