Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddharth More authored and Siddharth More committed May 6, 2024
1 parent 6f33481 commit 99c05b0
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions disperser/dataapi/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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 (
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand All @@ -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{
Expand All @@ -1614,6 +1631,9 @@ func makeTestBlob(quorumID core.QuorumID, adversityThreshold uint8) core.Blob {
AdversaryThreshold: adversityThreshold,
},
},
BlobAuthHeader: core.BlobAuthHeader{
AccountID: accountId,
},
},
Data: gettysburgAddressBytes,
}
Expand Down

0 comments on commit 99c05b0

Please sign in to comment.