Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
Remove blobMetadataIndex
  • Loading branch information
pschork committed Jul 25, 2024
1 parent 45f9a09 commit 1527325
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 83 deletions.
59 changes: 1 addition & 58 deletions disperser/batcher/batchstore/minibatch_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@ func GenerateTableSchema(tableName string, readCapacityUnits int64, writeCapacit
AttributeName: aws.String("CreatedAt"),
AttributeType: types.ScalarAttributeTypeN,
},
{
AttributeName: aws.String("BlobHash"),
AttributeType: types.ScalarAttributeTypeS,
},
{
AttributeName: aws.String("MetadataHash"),
AttributeType: types.ScalarAttributeTypeS,
},
},
KeySchema: []types.KeySchemaElement{
{
Expand Down Expand Up @@ -141,26 +133,6 @@ func GenerateTableSchema(tableName string, readCapacityUnits int64, writeCapacit
WriteCapacityUnits: aws.Int64(writeCapacityUnits),
},
},
{
IndexName: aws.String(blobMetadataIndexName),
KeySchema: []types.KeySchemaElement{
{
AttributeName: aws.String("BlobHash"),
KeyType: types.KeyTypeHash,
},
{
AttributeName: aws.String("MetadataHash"),
KeyType: types.KeyTypeRange,
},
},
Projection: &types.Projection{
ProjectionType: types.ProjectionTypeAll,
},
ProvisionedThroughput: &types.ProvisionedThroughput{
ReadCapacityUnits: aws.Int64(readCapacityUnits),
WriteCapacityUnits: aws.Int64(writeCapacityUnits),
},
},
},
ProvisionedThroughput: &types.ProvisionedThroughput{
ReadCapacityUnits: aws.Int64(readCapacityUnits),
Expand Down Expand Up @@ -495,7 +467,7 @@ func (m *MinibatchStore) GetLatestFormedBatch(ctx context.Context) (batch *batch
if len(formed) == 0 {
return nil, nil, nil
}
batch = formed[0]
batch = formed[len(formed)-1]
minibatches, err = m.GetMinibatches(ctx, batch.ID)
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -680,35 +652,6 @@ func (m *MinibatchStore) GetDispersalResponse(ctx context.Context, batchID uuid.
return response, nil
}

func (m *MinibatchStore) GetDispersalResponsesByBlobMetada(ctx context.Context, blobHash string, metadataHash string) ([]*batcher.DispersalResponse, error) {
items, err := m.dynamoDBClient.QueryIndex(ctx, m.tableName, blobMetadataIndexName, "BlobHash = :blobHash AND MetadataHash = :metadataHash", commondynamodb.ExpresseionValues{
":blobHash": &types.AttributeValueMemberS{
Value: blobHash,
},
":metadataHash": &types.AttributeValueMemberS{
Value: metadataHash,
},
})
if err != nil {
return nil, err
}

if len(items) == 0 {
return nil, fmt.Errorf("no dispersal responses found for BlobHash %s MetadataHash %s", blobHash, metadataHash)
}

responses := make([]*batcher.DispersalResponse, len(items))
for i, item := range items {
responses[i], err = UnmarshalDispersalResponse(item)
if err != nil {
m.logger.Errorf("failed to unmarshal dispersal response at index %d: %v", i, err)
return nil, err
}
}

return responses, nil
}

func (m *MinibatchStore) GetDispersalResponses(ctx context.Context, batchID uuid.UUID) ([]*batcher.DispersalResponse, error) {
items, err := m.dynamoDBClient.Query(ctx, m.tableName, "BatchID = :batchID AND begins_with(SK, :prefix)", commondynamodb.ExpresseionValues{
":batchID": &types.AttributeValueMemberS{
Expand Down
40 changes: 15 additions & 25 deletions disperser/batcher/batchstore/minibatch_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,12 @@ func TestGetLatestFormedBatch(t *testing.T) {
id1, _ := uuid.NewV7()
id2, _ := uuid.NewV7()
ts := time.Now().Truncate(time.Second).UTC()
ts2 := ts.Add(10 * time.Second)
batch1 := &batcher.BatchRecord{
ID: id1,
CreatedAt: ts,
ReferenceBlockNumber: 1,
Status: batcher.BatchStatusPending,
Status: batcher.BatchStatusFormed,
HeaderHash: [32]byte{1},
AggregatePubKey: nil,
AggregateSignature: nil,
Expand All @@ -210,52 +211,44 @@ func TestGetLatestFormedBatch(t *testing.T) {
BatchSize: 1,
ReferenceBlockNumber: 1,
}
minibatch2 := &batcher.MinibatchRecord{
BatchID: id1,
MinibatchIndex: 2,
BlobHeaderHashes: [][32]byte{{1}},
BatchSize: 1,
ReferenceBlockNumber: 1,
}
batch2 := &batcher.BatchRecord{
ID: id2,
CreatedAt: ts,
CreatedAt: ts2,
ReferenceBlockNumber: 1,
Status: batcher.BatchStatusPending,
Status: batcher.BatchStatusFormed,
HeaderHash: [32]byte{1},
AggregatePubKey: nil,
AggregateSignature: nil,
}
minibatch3 := &batcher.MinibatchRecord{
minibatch2 := &batcher.MinibatchRecord{
BatchID: id2,
MinibatchIndex: 1,
BlobHeaderHashes: [][32]byte{{1}},
BatchSize: 1,
ReferenceBlockNumber: 1,
}
minibatch3 := &batcher.MinibatchRecord{
BatchID: id2,
MinibatchIndex: 2,
BlobHeaderHashes: [][32]byte{{1}},
BatchSize: 1,
ReferenceBlockNumber: 1,
}
err := minibatchStore.PutBatch(ctx, batch1)
assert.NoError(t, err)
err = minibatchStore.PutMinibatch(ctx, minibatch1)
assert.NoError(t, err)
err = minibatchStore.PutMinibatch(ctx, minibatch2)
assert.NoError(t, err)
err = minibatchStore.PutBatch(ctx, batch2)
assert.NoError(t, err)
err = minibatchStore.PutMinibatch(ctx, minibatch2)
assert.NoError(t, err)
err = minibatchStore.PutMinibatch(ctx, minibatch3)
assert.NoError(t, err)

batch, minibatches, err := minibatchStore.GetLatestFormedBatch(ctx)
assert.NoError(t, err)
//assert.Equal(t, (*batcher.BatchRecord)(nil), batch)
//assert.Equal(t, []*batcher.MinibatchRecord([]*batcher.MinibatchRecord(nil)), minibatches)

err = minibatchStore.UpdateBatchStatus(ctx, id1, batcher.BatchStatusFormed)
assert.NoError(t, err)

batch, minibatches, err = minibatchStore.GetLatestFormedBatch(ctx)
assert.NoError(t, err)
assert.Equal(t, 2, len(minibatches))
assert.Equal(t, batch.ID, batch1.ID)
assert.Equal(t, batch.ID, batch2.ID)
}
func TestPutDispersalRequest(t *testing.T) {
ctx := context.Background()
Expand Down Expand Up @@ -308,9 +301,6 @@ func TestPutDispersalResponse(t *testing.T) {
r, err := minibatchStore.GetDispersalResponse(ctx, response.BatchID, response.MinibatchIndex, opID)
assert.NoError(t, err)
assert.Equal(t, response, r)
rs, err := minibatchStore.GetDispersalResponsesByBlobMetada(ctx, blobHash, metadataHash)
assert.NoError(t, err)
assert.Equal(t, response, rs[0])
}

func TestDispersalStatus(t *testing.T) {
Expand Down

0 comments on commit 1527325

Please sign in to comment.