From 99c05b0f29b7d6657ee8aed42240d4fa49fd03ce Mon Sep 17 00:00:00 2001 From: Siddharth More Date: Sun, 5 May 2024 17:28:02 -0700 Subject: [PATCH] fix test --- disperser/dataapi/server_test.go | 60 +++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/disperser/dataapi/server_test.go b/disperser/dataapi/server_test.go index ce8ebea298..63c2ded802 100644 --- a/disperser/dataapi/server_test.go +++ b/disperser/dataapi/server_test.go @@ -155,9 +155,9 @@ func (c *MockHttpClient) CheckHealth(url string) (string, error) { func TestFetchBlobHandler(t *testing.T) { r := setUpRouter() - blob := makeTestBlob(0, 80) + blob := makeTestBlob(0, 80, "test") key := queueBlob(t, &blob, blobstore) - markBlobConfirmed(t, &blob, key, expectedBatchHeaderHash, blobstore) + markBlobConfirmed(t, &blob, key, expectedBatchHeaderHash, "test", blobstore) blobKey := key.String() r.GET("/v1/feed/blobs/:blob_key", testDataApiServer.FetchBlobHandler) @@ -196,7 +196,7 @@ func TestFetchBlobsHandler(t *testing.T) { defer goleak.VerifyNone(t) r := setUpRouter() - blob := makeTestBlob(0, 10) + blob := makeTestBlob(0, 10, "test") for _, batch := range subgraphBatches { var ( @@ -206,7 +206,7 @@ func TestFetchBlobsHandler(t *testing.T) { batchHeaderHashBytes := []byte(batch.BatchHeaderHash) batchHeaderHash, err := dataapi.ConvertHexadecimalToBytes(batchHeaderHashBytes) assert.NoError(t, err) - markBlobConfirmed(t, &blob, key, batchHeaderHash, blobstore) + markBlobConfirmed(t, &blob, key, batchHeaderHash, "test", blobstore) } mockSubgraphApi.On("QueryBatches").Return(subgraphBatches, nil) @@ -235,15 +235,31 @@ func TestFetchBlobsHandler(t *testing.T) { func TestFetchBlobCountByAccountIdHandler(t *testing.T) { r := setUpRouter() + testBlob := core.Blob{ + RequestHeader: core.BlobRequestHeader{ + SecurityParams: []*core.SecurityParam{ + { + QuorumID: 0, + AdversaryThreshold: 80, + }, + }, + BlobAuthHeader: core.BlobAuthHeader{ + AccountID: "test1", + }, + }, + Data: gettysburgAddressBytes, + } - blob := makeTestBlob(0, 80) - key := queueBlob(t, &blob, blobstore) - markBlobConfirmed(t, &blob, key, expectedBatchHeaderHash, blobstore) - accountd := "test" + // Create Blob With test1 accountId + blob := makeTestBlob(0, 80, "test1") + key := queueBlob(t, &testBlob, blobstore) + // mark Blob confirmed with accountId test1 + markBlobConfirmed(t, &blob, key, expectedBatchHeaderHash, "test1", blobstore) + accountId := "test1" r.GET("/v1/feed/blobs/:accountId", testDataApiServer.FetchBlobCountByAccountIdHandler) w := httptest.NewRecorder() - req := httptest.NewRequest(http.MethodGet, "/v1/feed/blobs/"+accountd, nil) + req := httptest.NewRequest(http.MethodGet, "/v1/feed/blobs/"+accountId, nil) r.ServeHTTP(w, req) res := w.Result() @@ -259,22 +275,23 @@ func TestFetchBlobCountByAccountIdHandler(t *testing.T) { assert.Equal(t, http.StatusOK, res.StatusCode) assert.Equal(t, int32(1), response.Count) - assert.Equal(t, "test", response.AccountId) + assert.Equal(t, "test1", response.AccountId) } func TestFetchBlobCountByAccountIdInvalidHandler(t *testing.T) { r := setUpRouter() - - blob := makeTestBlob(0, 80) + // Create Blob With test accountId + blob := makeTestBlob(0, 80, "test2") key := queueBlob(t, &blob, blobstore) - markBlobConfirmed(t, &blob, key, expectedBatchHeaderHash, blobstore) + // mark Blob confirmed with accountId test + markBlobConfirmed(t, &blob, key, expectedBatchHeaderHash, "test2", blobstore) // BlobAccountId is "test" // Search by AccountId test1 - accountd := "test1" + accountId := "test3" r.GET("/v1/feed/blobs/:accountId", testDataApiServer.FetchBlobCountByAccountIdHandler) w := httptest.NewRecorder() - req := httptest.NewRequest(http.MethodGet, "/v1/feed/blobs/"+accountd, nil) + req := httptest.NewRequest(http.MethodGet, "/v1/feed/blobs/"+accountId, nil) r.ServeHTTP(w, req) res := w.Result() @@ -297,7 +314,7 @@ func TestFetchMetricsHandler(t *testing.T) { r := setUpRouter() - blob := makeTestBlob(0, 10) + blob := makeTestBlob(0, 10, "test") for _, batch := range subgraphBatches { var ( key = queueBlob(t, &blob, blobstore) @@ -307,7 +324,7 @@ func TestFetchMetricsHandler(t *testing.T) { batchHeaderHash, err := dataapi.ConvertHexadecimalToBytes(batchHeaderHashBytes) assert.NoError(t, err) - markBlobConfirmed(t, &blob, key, batchHeaderHash, blobstore) + markBlobConfirmed(t, &blob, key, batchHeaderHash, "test", blobstore) } s := new(model.SampleStream) @@ -1554,7 +1571,7 @@ func queueBlob(t *testing.T, blob *core.Blob, queue disperser.BlobStore) dispers return key } -func markBlobConfirmed(t *testing.T, blob *core.Blob, key disperser.BlobKey, batchHeaderHash [32]byte, queue disperser.BlobStore) { +func markBlobConfirmed(t *testing.T, blob *core.Blob, key disperser.BlobKey, batchHeaderHash [32]byte, accountId string, queue disperser.BlobStore) { // simulate blob confirmation var commitX, commitY fp.Element _, err := commitX.SetString("21661178944771197726808973281966770251114553549453983978976194544185382599016") @@ -1588,7 +1605,7 @@ func markBlobConfirmed(t *testing.T, blob *core.Blob, key disperser.BlobKey, bat BlobStatus: disperser.Confirmed, Expiry: 0, NumRetries: 0, - AccountID: "test", + AccountID: accountId, RequestMetadata: &disperser.RequestMetadata{ BlobRequestHeader: core.BlobRequestHeader{ SecurityParams: blob.RequestHeader.SecurityParams, @@ -1605,7 +1622,7 @@ func markBlobConfirmed(t *testing.T, blob *core.Blob, key disperser.BlobKey, bat assert.Equal(t, disperser.Confirmed, updated.BlobStatus) } -func makeTestBlob(quorumID core.QuorumID, adversityThreshold uint8) core.Blob { +func makeTestBlob(quorumID core.QuorumID, adversityThreshold uint8, accountId string) core.Blob { blob := core.Blob{ RequestHeader: core.BlobRequestHeader{ SecurityParams: []*core.SecurityParam{ @@ -1614,6 +1631,9 @@ func makeTestBlob(quorumID core.QuorumID, adversityThreshold uint8) core.Blob { AdversaryThreshold: adversityThreshold, }, }, + BlobAuthHeader: core.BlobAuthHeader{ + AccountID: accountId, + }, }, Data: gettysburgAddressBytes, }