diff --git a/blob/service_test.go b/blob/service_test.go index 672ce091c1..fc48f96eb9 100644 --- a/blob/service_test.go +++ b/blob/service_test.go @@ -43,15 +43,15 @@ func TestBlobService_Get(t *testing.T) { appBlobs, err := blobtest.GenerateV0Blobs([]int{blobSize0, blobSize1}, false) require.NoError(t, err) - blobs0, err := convertBlobs(appBlobs...) + blobsWithDiffNamespaces, err := convertBlobs(appBlobs...) require.NoError(t, err) appBlobs, err = blobtest.GenerateV0Blobs([]int{blobSize2, blobSize3}, true) require.NoError(t, err) - blobs1, err := convertBlobs(appBlobs...) + blobsWithSameNamespace, err := convertBlobs(appBlobs...) require.NoError(t, err) - service := createService(ctx, t, append(blobs0, blobs1...)) + service := createService(ctx, t, append(blobsWithDiffNamespaces, blobsWithSameNamespace...)) test := []struct { name string doFn func() (interface{}, error) @@ -60,7 +60,10 @@ func TestBlobService_Get(t *testing.T) { { name: "get single blob", doFn: func() (interface{}, error) { - b, err := service.Get(ctx, 1, blobs0[0].Namespace(), blobs0[0].Commitment) + b, err := service.Get(ctx, 1, + blobsWithDiffNamespaces[0].Namespace(), + blobsWithDiffNamespaces[0].Commitment, + ) return []*Blob{b}, err }, expectedResult: func(res interface{}, err error) { @@ -71,13 +74,13 @@ func TestBlobService_Get(t *testing.T) { assert.True(t, ok) assert.Len(t, blobs, 1) - assert.Equal(t, blobs0[0].Commitment, blobs[0].Commitment) + assert.Equal(t, blobsWithDiffNamespaces[0].Commitment, blobs[0].Commitment) }, }, { name: "get all with the same namespace", doFn: func() (interface{}, error) { - return service.GetAll(ctx, 1, []share.Namespace{blobs1[0].Namespace()}) + return service.GetAll(ctx, 1, []share.Namespace{blobsWithSameNamespace[0].Namespace()}) }, expectedResult: func(res interface{}, err error) { require.NoError(t, err) @@ -88,19 +91,25 @@ func TestBlobService_Get(t *testing.T) { assert.Len(t, blobs, 2) - for i := range blobs1 { - require.Equal(t, blobs1[i].Commitment, blobs[i].Commitment) + for i := range blobsWithSameNamespace { + require.Equal(t, blobsWithSameNamespace[i].Commitment, blobs[i].Commitment) } }, }, { name: "verify indexes", doFn: func() (interface{}, error) { - b0, err := service.Get(ctx, 1, blobs0[0].Namespace(), blobs0[0].Commitment) + b0, err := service.Get(ctx, 1, + blobsWithDiffNamespaces[0].Namespace(), + blobsWithDiffNamespaces[0].Commitment, + ) require.NoError(t, err) - b1, err := service.Get(ctx, 1, blobs0[1].Namespace(), blobs0[1].Commitment) + b1, err := service.Get(ctx, 1, + blobsWithDiffNamespaces[1].Namespace(), + blobsWithDiffNamespaces[1].Commitment, + ) require.NoError(t, err) - b23, err := service.GetAll(ctx, 1, []share.Namespace{blobs1[0].Namespace()}) + b23, err := service.GetAll(ctx, 1, []share.Namespace{blobsWithSameNamespace[0].Namespace()}) require.NoError(t, err) return []*Blob{b0, b1, b23[0], b23[1]}, nil }, @@ -138,7 +147,12 @@ func TestBlobService_Get(t *testing.T) { doFn: func() (interface{}, error) { nid, err := share.NewBlobNamespaceV0(tmrand.Bytes(7)) require.NoError(t, err) - b, err := service.GetAll(ctx, 1, []share.Namespace{blobs0[0].Namespace(), nid, blobs0[1].Namespace()}) + b, err := service.GetAll(ctx, 1, + []share.Namespace{ + blobsWithDiffNamespaces[0].Namespace(), nid, + blobsWithDiffNamespaces[1].Namespace(), + }, + ) return b, err }, expectedResult: func(res interface{}, err error) { @@ -149,14 +163,17 @@ func TestBlobService_Get(t *testing.T) { assert.NotEmpty(t, blobs) assert.Len(t, blobs, 2) // check the order - require.True(t, bytes.Equal(blobs[0].Namespace(), blobs0[0].Namespace())) - require.True(t, bytes.Equal(blobs[1].Namespace(), blobs0[1].Namespace())) + require.True(t, bytes.Equal(blobs[0].Namespace(), blobsWithDiffNamespaces[0].Namespace())) + require.True(t, bytes.Equal(blobs[1].Namespace(), blobsWithDiffNamespaces[1].Namespace())) }, }, { name: "get blob with incorrect commitment", doFn: func() (interface{}, error) { - b, err := service.Get(ctx, 1, blobs0[0].Namespace(), blobs0[1].Commitment) + b, err := service.Get(ctx, 1, + blobsWithDiffNamespaces[0].Namespace(), + blobsWithDiffNamespaces[1].Commitment, + ) return []*Blob{b}, err }, expectedResult: func(res interface{}, err error) { @@ -189,7 +206,10 @@ func TestBlobService_Get(t *testing.T) { { name: "get proof", doFn: func() (interface{}, error) { - proof, err := service.GetProof(ctx, 1, blobs0[1].Namespace(), blobs0[1].Commitment) + proof, err := service.GetProof(ctx, 1, + blobsWithDiffNamespaces[1].Namespace(), + blobsWithDiffNamespaces[1].Commitment, + ) return proof, err }, expectedResult: func(res interface{}, err error) { @@ -216,17 +236,24 @@ func TestBlobService_Get(t *testing.T) { t.Fatal("could not prove the shares") } - rawShares, err := BlobsToShares(blobs0[1]) + rawShares, err := BlobsToShares(blobsWithDiffNamespaces[1]) require.NoError(t, err) - verifyFn(t, rawShares, proof, blobs0[1].Namespace()) + verifyFn(t, rawShares, proof, blobsWithDiffNamespaces[1].Namespace()) }, }, { name: "verify inclusion", doFn: func() (interface{}, error) { - proof, err := service.GetProof(ctx, 1, blobs0[0].Namespace(), blobs0[0].Commitment) + proof, err := service.GetProof(ctx, 1, + blobsWithDiffNamespaces[0].Namespace(), + blobsWithDiffNamespaces[0].Commitment, + ) require.NoError(t, err) - return service.Included(ctx, 1, blobs0[0].Namespace(), proof, blobs0[0].Commitment) + return service.Included(ctx, 1, + blobsWithDiffNamespaces[0].Namespace(), + proof, + blobsWithDiffNamespaces[0].Commitment, + ) }, expectedResult: func(res interface{}, err error) { require.NoError(t, err) @@ -238,9 +265,16 @@ func TestBlobService_Get(t *testing.T) { { name: "verify inclusion fails with different proof", doFn: func() (interface{}, error) { - proof, err := service.GetProof(ctx, 1, blobs0[1].Namespace(), blobs0[1].Commitment) + proof, err := service.GetProof(ctx, 1, + blobsWithDiffNamespaces[1].Namespace(), + blobsWithDiffNamespaces[1].Commitment, + ) require.NoError(t, err) - return service.Included(ctx, 1, blobs0[0].Namespace(), proof, blobs0[0].Commitment) + return service.Included(ctx, 1, + blobsWithDiffNamespaces[0].Namespace(), + proof, + blobsWithDiffNamespaces[0].Commitment, + ) }, expectedResult: func(res interface{}, err error) { require.Error(t, err) @@ -258,7 +292,10 @@ func TestBlobService_Get(t *testing.T) { blob, err := convertBlobs(appBlob...) require.NoError(t, err) - proof, err := service.GetProof(ctx, 1, blobs0[1].Namespace(), blobs0[1].Commitment) + proof, err := service.GetProof(ctx, 1, + blobsWithDiffNamespaces[1].Namespace(), + blobsWithDiffNamespaces[1].Commitment, + ) require.NoError(t, err) return service.Included(ctx, 1, blob[0].Namespace(), proof, blob[0].Commitment) }, @@ -272,11 +309,17 @@ func TestBlobService_Get(t *testing.T) { { name: "count proofs for the blob", doFn: func() (interface{}, error) { - proof0, err := service.GetProof(ctx, 1, blobs0[0].Namespace(), blobs0[0].Commitment) + proof0, err := service.GetProof(ctx, 1, + blobsWithDiffNamespaces[0].Namespace(), + blobsWithDiffNamespaces[0].Commitment, + ) if err != nil { return nil, err } - proof1, err := service.GetProof(ctx, 1, blobs0[1].Namespace(), blobs0[1].Commitment) + proof1, err := service.GetProof(ctx, 1, + blobsWithDiffNamespaces[1].Namespace(), + blobsWithDiffNamespaces[1].Commitment, + ) if err != nil { return nil, err } @@ -308,13 +351,16 @@ func TestBlobService_Get(t *testing.T) { blobs, ok := i.([]*Blob) require.True(t, ok) assert.Nil(t, blobs) - assert.Nil(t, err) + assert.NoError(t, err) }, }, { name: "marshal proof", doFn: func() (interface{}, error) { - proof, err := service.GetProof(ctx, 1, blobs0[1].Namespace(), blobs0[1].Commitment) + proof, err := service.GetProof(ctx, 1, + blobsWithDiffNamespaces[1].Namespace(), + blobsWithDiffNamespaces[1].Commitment, + ) require.NoError(t, err) return json.Marshal(proof) }, @@ -325,7 +371,10 @@ func TestBlobService_Get(t *testing.T) { var proof Proof require.NoError(t, json.Unmarshal(jsonData, &proof)) - newProof, err := service.GetProof(ctx, 1, blobs0[1].Namespace(), blobs0[1].Commitment) + newProof, err := service.GetProof(ctx, 1, + blobsWithDiffNamespaces[1].Namespace(), + blobsWithDiffNamespaces[1].Commitment, + ) require.NoError(t, err) require.NoError(t, proof.equal(*newProof)) }, @@ -340,23 +389,28 @@ func TestBlobService_Get(t *testing.T) { GetSharesByNamespace(gomock.Any(), gomock.Any(), gomock.Any()). DoAndReturn( func(ctx context.Context, h *header.ExtendedHeader, ns share.Namespace) (share.NamespacedShares, error) { - if ns.Equals(blobs0[0].Namespace()) { + if ns.Equals(blobsWithDiffNamespaces[0].Namespace()) { return nil, errors.New("internal error") } return shareService.GetSharesByNamespace(ctx, h, ns) }).AnyTimes() service.shareGetter = shareGetterMock - return service.GetAll(ctx, 1, []share.Namespace{blobs0[0].Namespace(), blobs1[0].Namespace()}) + return service.GetAll(ctx, 1, + []share.Namespace{ + blobsWithDiffNamespaces[0].Namespace(), + blobsWithSameNamespace[0].Namespace(), + }, + ) }, expectedResult: func(res interface{}, err error) { blobs, ok := res.([]*Blob) assert.True(t, ok) assert.Error(t, err) assert.Contains(t, err.Error(), "internal error") - assert.Equal(t, blobs[0].Namespace(), blobs1[0].Namespace()) + assert.Equal(t, blobs[0].Namespace(), blobsWithSameNamespace[0].Namespace()) assert.NotEmpty(t, blobs) - assert.Len(t, blobs, len(blobs1)) + assert.Len(t, blobs, len(blobsWithSameNamespace)) }, }, }