Skip to content
This repository was archived by the owner on May 7, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion test/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import (
// DefaultMaxBlobSize is the default max blob size
const DefaultMaxBlobSize = 64 * 64 * 482

// ErrNoBlobAtHeight is returned when there is no blob at given height.
var ErrNoBlobAtHeight = errors.New("no blob at given height")

// DummyDA is a simple implementation of in-memory DA. Not production ready! Intended only for testing!
//
// Data is stored in a map, where key is a serialized sequence number. This key is returned as ID.
Expand Down Expand Up @@ -82,7 +85,10 @@ func (d *DummyDA) Get(ctx context.Context, ids []da.ID, _ da.Namespace) ([]da.Bl
func (d *DummyDA) GetIDs(ctx context.Context, height uint64, _ da.Namespace) ([]da.ID, error) {
d.mu.Lock()
defer d.mu.Unlock()
kvps := d.data[height]
kvps, ok := d.data[height]
if !ok {
return nil, ErrNoBlobAtHeight
}
ids := make([]da.ID, len(kvps))
for i, kv := range kvps {
ids[i] = kv.key
Expand Down
17 changes: 16 additions & 1 deletion test/test_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package test
import (
"bytes"
"context"
"strings"
"sync"
"testing"
"time"
Expand All @@ -28,6 +29,9 @@ func RunDATestSuite(t *testing.T, d da.DA) {
t.Run("Concurrent read/write test", func(t *testing.T) {
ConcurrentReadWriteTest(t, d)
})
t.Run("No blobs at a given height", func(t *testing.T) {
NoBlobsAtHeightTest(t, d)
})
}

// BasicDATest tests round trip of messages to DA and back.
Expand Down Expand Up @@ -134,7 +138,9 @@ func ConcurrentReadWriteTest(t *testing.T, d da.DA) {
defer wg.Done()
for i := uint64(1); i <= 100; i++ {
_, err := d.GetIDs(ctx, i, []byte{})
assert.NoError(t, err)
if err != nil && !strings.Contains(err.Error(), ErrNoBlobAtHeight.Error()) {
assert.NoError(t, err)
}
}
}()

Expand All @@ -148,3 +154,12 @@ func ConcurrentReadWriteTest(t *testing.T, d da.DA) {

wg.Wait()
}

// NoBlobsAtHeightTest tests the case when there are no blobs at a given height in DA
func NoBlobsAtHeightTest(t *testing.T, d da.DA) {
ctx := context.TODO()
// GetIDs should return ErrNoBlobAtHeight when there are no blobs at a given height
_, err := d.GetIDs(ctx, 999999999, []byte{})
assert.Error(t, err)
assert.ErrorContains(t, err, ErrNoBlobAtHeight.Error())
}