Skip to content

Commit

Permalink
Fix test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth More authored and Siddharth More committed May 5, 2024
1 parent e655eb2 commit badbd96
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 5 deletions.
2 changes: 1 addition & 1 deletion disperser/apiserver/ratelimit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func simulateClient(t *testing.T, signer core.BlobRequestSigner, origin string,

authHeader := core.BlobAuthHeader{
BlobCommitments: encoding.BlobCommitments{},
AccountID: "",
AccountID: "test",
Nonce: authHeaderReply.BlobAuthHeader.ChallengeParameter,
}

Expand Down
4 changes: 4 additions & 0 deletions disperser/apiserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,9 +730,13 @@ func simulateBlobConfirmation(t *testing.T, requestID []byte, blobSize uint, sec
BlobStatus: disperser.Processing,
Expiry: 0,
NumRetries: 0,
AccountID: "test",
RequestMetadata: &disperser.RequestMetadata{
BlobRequestHeader: core.BlobRequestHeader{
SecurityParams: securityParams,
BlobAuthHeader: core.BlobAuthHeader{
AccountID: "test",
},
},
RequestedAt: requestedAt,
BlobSize: blobSize,
Expand Down
99 changes: 99 additions & 0 deletions disperser/common/blobstore/blob_metadata_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestBlobMetadataStoreOperations(t *testing.T) {
BlobStatus: disperser.Processing,
Expiry: 0,
NumRetries: 0,
AccountID: "test",
RequestMetadata: &disperser.RequestMetadata{
BlobRequestHeader: blob.RequestHeader,
BlobSize: blobSize,
Expand All @@ -43,6 +44,7 @@ func TestBlobMetadataStoreOperations(t *testing.T) {
BlobStatus: disperser.Finalized,
Expiry: 0,
NumRetries: 0,
AccountID: "test",
RequestMetadata: &disperser.RequestMetadata{
BlobRequestHeader: blob.RequestHeader,
BlobSize: blobSize,
Expand Down Expand Up @@ -123,6 +125,7 @@ func TestBlobMetadataStoreOperationsWithPagination(t *testing.T) {
BlobStatus: disperser.Processing,
Expiry: 0,
NumRetries: 0,
AccountID: "test",
RequestMetadata: &disperser.RequestMetadata{
BlobRequestHeader: blob.RequestHeader,
BlobSize: blobSize,
Expand All @@ -139,6 +142,7 @@ func TestBlobMetadataStoreOperationsWithPagination(t *testing.T) {
BlobStatus: disperser.Finalized,
Expiry: 0,
NumRetries: 0,
AccountID: "test",
RequestMetadata: &disperser.RequestMetadata{
BlobRequestHeader: blob.RequestHeader,
BlobSize: blobSize,
Expand Down Expand Up @@ -229,9 +233,13 @@ func getConfirmedMetadata(t *testing.T, metadataKey disperser.BlobKey) *disperse
BlobStatus: disperser.Confirmed,
Expiry: 0,
NumRetries: 0,
AccountID: "test",
RequestMetadata: &disperser.RequestMetadata{
BlobRequestHeader: core.BlobRequestHeader{
SecurityParams: securityParams,
BlobAuthHeader: core.BlobAuthHeader{
AccountID: "test",
},
},
RequestedAt: requestedAt,
BlobSize: blobSize,
Expand Down Expand Up @@ -321,3 +329,94 @@ func TestBlobMetadataStoreWithAccountId(t *testing.T) {
},
})
}

func TestBlobMetadataStoreTwoDifferentAccountId(t *testing.T) {
ctx := context.Background()
blobKey1 := disperser.BlobKey{
BlobHash: blobHash,
MetadataHash: "hash",
}
blob1 := &core.Blob{
RequestHeader: core.BlobRequestHeader{
SecurityParams: securityParams,
BlobAuthHeader: core.BlobAuthHeader{
AccountID: "test1",
},
},

Data: []byte("test1"),
}
metadata1 := &disperser.BlobMetadata{
MetadataHash: blobKey1.MetadataHash,
BlobHash: blobHash,
BlobStatus: disperser.Processing,
AccountID: "test1",
Expiry: 0,
NumRetries: 0,
RequestMetadata: &disperser.RequestMetadata{
BlobRequestHeader: blob1.RequestHeader,
BlobSize: uint(len(blob1.Data)),
RequestedAt: 123,
},
}
blobKey2 := disperser.BlobKey{
BlobHash: "blob2",
MetadataHash: "hash2",
}
blob2 := &core.Blob{
RequestHeader: core.BlobRequestHeader{
SecurityParams: securityParams,
BlobAuthHeader: core.BlobAuthHeader{
AccountID: "test2",
},
},

Data: []byte("test2"),
}
metadata2 := &disperser.BlobMetadata{
MetadataHash: blobKey2.MetadataHash,
BlobHash: blobKey2.BlobHash,
BlobStatus: disperser.Finalized,
AccountID: "test2",
Expiry: 0,
NumRetries: 0,
RequestMetadata: &disperser.RequestMetadata{
BlobRequestHeader: blob2.RequestHeader,
BlobSize: uint(len(blob2.Data)),
RequestedAt: 123,
},
ConfirmationInfo: &disperser.ConfirmationInfo{},
}
err := blobMetadataStore.QueueNewBlobMetadata(ctx, metadata1)
assert.NoError(t, err)
err = blobMetadataStore.QueueNewBlobMetadata(ctx, metadata2)
assert.NoError(t, err)

processing, err := blobMetadataStore.GetBlobMetadataByStatus(ctx, disperser.Processing)
assert.NoError(t, err)
assert.Len(t, processing, 1)
assert.Equal(t, metadata1, processing[0])

processingCount, err := blobMetadataStore.GetBlobMetadataByStatusCount(ctx, disperser.Processing)
assert.NoError(t, err)
assert.Equal(t, int32(1), processingCount)

blobCountByAccountId1, err := blobMetadataStore.GetBlobMetadataCountByAccountID(ctx, "test1")
assert.NoError(t, err)
assert.Equal(t, int32(1), blobCountByAccountId1)

blobCountByAccountId2, err := blobMetadataStore.GetBlobMetadataCountByAccountID(ctx, "test2")
assert.NoError(t, err)
assert.Equal(t, int32(1), blobCountByAccountId2)

deleteItems(t, []commondynamodb.Key{
{
"MetadataHash": &types.AttributeValueMemberS{Value: blobKey1.MetadataHash},
"BlobHash": &types.AttributeValueMemberS{Value: blobKey1.BlobHash},
},
{
"MetadataHash": &types.AttributeValueMemberS{Value: blobKey2.MetadataHash},
"BlobHash": &types.AttributeValueMemberS{Value: blobKey2.BlobHash},
},
})
}
7 changes: 3 additions & 4 deletions disperser/common/blobstore/blobstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ var (
blob = &core.Blob{
RequestHeader: core.BlobRequestHeader{
SecurityParams: securityParams,
BlobAuthHeader: core.BlobAuthHeader{
AccountID: "test",
},
},

Data: []byte("test"),
Expand Down Expand Up @@ -85,10 +88,6 @@ func setup(m *testing.M) {
EndpointURL: fmt.Sprintf("http://0.0.0.0:%s", localStackPort),
}

fmt.Printf("Creating dynamodb table %s\n", metadataTableName)
fmt.Printf("Table Schema: %v\n", blobstore.GenerateTableSchema(metadataTableName, 10, 10).AttributeDefinitions)
fmt.Printf("Table Schema: %v\n", blobstore.GenerateTableSchema(metadataTableName, 10, 10).KeySchema)
fmt.Printf("Table Schema: %v\n", blobstore.GenerateTableSchema(metadataTableName, 10, 10).GlobalSecondaryIndexes)
_, err := test_utils.CreateTable(context.Background(), cfg, metadataTableName, blobstore.GenerateTableSchema(metadataTableName, 10, 10))
if err != nil {
teardown()
Expand Down

0 comments on commit badbd96

Please sign in to comment.