diff --git a/test/dummy.go b/test/dummy.go index fcf847c..809a3b8 100644 --- a/test/dummy.go +++ b/test/dummy.go @@ -16,8 +16,8 @@ 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") +// ErrTooHigh is returned when requested height is to high +var ErrTooHigh = errors.New("given height is from the future") // DummyDA is a simple implementation of in-memory DA. Not production ready! Intended only for testing! // @@ -85,10 +85,16 @@ 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() + + if height > d.height { + return nil, ErrTooHigh + } + kvps, ok := d.data[height] if !ok { - return nil, ErrNoBlobAtHeight + return nil, nil } + ids := make([]da.ID, len(kvps)) for i, kv := range kvps { ids[i] = kv.key diff --git a/test/test_suite.go b/test/test_suite.go index 117f8b9..d1860af 100644 --- a/test/test_suite.go +++ b/test/test_suite.go @@ -3,7 +3,6 @@ package test import ( "bytes" "context" - "strings" "sync" "testing" "time" @@ -29,8 +28,8 @@ 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) + t.Run("Given height is from the future", func(t *testing.T) { + HeightFromFutureTest(t, d) }) } @@ -138,8 +137,8 @@ func ConcurrentReadWriteTest(t *testing.T, d da.DA) { defer wg.Done() for i := uint64(1); i <= 100; i++ { _, err := d.GetIDs(ctx, i, []byte{}) - if err != nil && !strings.Contains(err.Error(), ErrNoBlobAtHeight.Error()) { - assert.NoError(t, err) + if err != nil { + assert.Equal(t, err.Error(), ErrTooHigh.Error()) } } }() @@ -147,7 +146,7 @@ func ConcurrentReadWriteTest(t *testing.T, d da.DA) { go func() { defer wg.Done() for i := uint64(1); i <= 100; i++ { - _, err := d.Submit(ctx, [][]byte{[]byte("test")}, 0, testNamespace) + _, err := d.Submit(ctx, [][]byte{[]byte("test")}, 0, []byte{}) assert.NoError(t, err) } }() @@ -155,11 +154,10 @@ 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) { +// HeightFromFutureTest tests the case when the given height is from the future +func HeightFromFutureTest(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{}) + ids, err := d.GetIDs(ctx, 999999999, []byte{}) assert.Error(t, err) - assert.ErrorContains(t, err, ErrNoBlobAtHeight.Error()) + assert.Nil(t, ids) }