Skip to content

Commit

Permalink
fix: Return an err no blob at a given height in case there is no bl…
Browse files Browse the repository at this point in the history
…ob (#88)

* Return an err `no blob at a given height` in case there is no blob

* Fix lint

* Silly way of checking error for proxy test

* test: nit

---------

Co-authored-by: Javed Khan <[email protected]>
  • Loading branch information
yarikbratashchuk and tuxcanfly authored Aug 20, 2024
1 parent c18ad55 commit 5e6b934
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
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())
}

0 comments on commit 5e6b934

Please sign in to comment.