Skip to content

Commit 6b4fc2e

Browse files
committed
fix problems with merge
1 parent 330f694 commit 6b4fc2e

19 files changed

Lines changed: 321 additions & 431 deletions

block/internal/da/blob_api_mock.go

Lines changed: 57 additions & 57 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

block/internal/da/client.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,6 @@ import (
1515
datypes "github.com/evstack/ev-node/pkg/da/types"
1616
)
1717

18-
var (
19-
ErrBlobNotFound = datypes.ErrBlobNotFound
20-
ErrBlobSizeOverLimit = datypes.ErrBlobSizeOverLimit
21-
ErrTxTimedOut = datypes.ErrTxTimedOut
22-
ErrTxAlreadyInMempool = datypes.ErrTxAlreadyInMempool
23-
ErrTxIncorrectAccountSequence = datypes.ErrTxIncorrectAccountSequence
24-
ErrContextDeadline = datypes.ErrContextDeadline
25-
ErrHeightFromFuture = datypes.ErrHeightFromFuture
26-
ErrContextCanceled = datypes.ErrContextCanceled
27-
)
28-
2918
// Config contains configuration for the Celestia blob client.
3019
type Config struct {
3120
Client *blobrpc.Client

block/internal/da/client_test.go

Lines changed: 28 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -166,224 +166,49 @@ func TestCelestiaClient_SubmitOptionsMerge(t *testing.T) {
166166
}
167167

168168
func TestClient_RetrieveHeaders(t *testing.T) {
169-
logger := zerolog.Nop()
170-
dataLayerHeight := uint64(100)
171-
mockIDs := [][]byte{[]byte("id1")}
172-
mockBlobs := [][]byte{[]byte("header-blob")}
173-
mockTimestamp := time.Now()
169+
ns := share.MustNewV0Namespace([]byte("header-ns"))
170+
blb, err := blobrpc.NewBlobV0(ns, []byte("header-blob"))
171+
require.NoError(t, err)
174172

175-
mockDAInstance := &mockDA{
176-
getIDsFunc: func(ctx context.Context, height uint64, namespace []byte) (*coreda.GetIDsResult, error) {
177-
return &coreda.GetIDsResult{
178-
IDs: mockIDs,
179-
Timestamp: mockTimestamp,
180-
}, nil
181-
},
182-
getFunc: func(ctx context.Context, ids []coreda.ID, namespace []byte) ([]coreda.Blob, error) {
183-
return mockBlobs, nil
184-
},
173+
mockAPI := &mockBlobAPI{
174+
blobs: []*blobrpc.Blob{blb},
185175
}
186176

187177
client := NewClient(Config{
188-
DA: mockDAInstance,
189-
Logger: logger,
190-
Namespace: "test-header-ns",
191-
DataNamespace: "test-data-ns",
178+
Client: makeBlobRPCClient(mockAPI),
179+
Logger: zerolog.Nop(),
180+
Namespace: "header-ns",
181+
DataNamespace: "data-ns",
192182
})
193183

194-
result := client.RetrieveHeaders(context.Background(), dataLayerHeight)
184+
result := client.RetrieveHeaders(context.Background(), 42)
195185

196-
assert.Equal(t, coreda.StatusSuccess, result.Code)
197-
assert.Equal(t, dataLayerHeight, result.Height)
198-
assert.Equal(t, len(mockBlobs), len(result.Data))
186+
assert.Equal(t, datypes.StatusSuccess, result.Code)
187+
assert.Equal(t, uint64(42), result.Height)
188+
assert.Equal(t, 1, len(result.Data))
199189
}
200190

201191
func TestClient_RetrieveData(t *testing.T) {
202-
logger := zerolog.Nop()
203-
dataLayerHeight := uint64(200)
204-
mockIDs := [][]byte{[]byte("id1"), []byte("id2")}
205-
mockBlobs := [][]byte{[]byte("data-blob-1"), []byte("data-blob-2")}
206-
mockTimestamp := time.Now()
207-
208-
mockDAInstance := &mockDA{
209-
getIDsFunc: func(ctx context.Context, height uint64, namespace []byte) (*coreda.GetIDsResult, error) {
210-
return &coreda.GetIDsResult{
211-
IDs: mockIDs,
212-
Timestamp: mockTimestamp,
213-
}, nil
214-
},
215-
getFunc: func(ctx context.Context, ids []coreda.ID, namespace []byte) ([]coreda.Blob, error) {
216-
return mockBlobs, nil
217-
},
218-
}
219-
220-
client := NewClient(Config{
221-
DA: mockDAInstance,
222-
Logger: logger,
223-
Namespace: "test-header-ns",
224-
DataNamespace: "test-data-ns",
225-
})
226-
227-
result := client.RetrieveData(context.Background(), dataLayerHeight)
228-
229-
assert.Equal(t, coreda.StatusSuccess, result.Code)
230-
assert.Equal(t, dataLayerHeight, result.Height)
231-
assert.Equal(t, len(mockBlobs), len(result.Data))
232-
}
233-
234-
func TestClient_RetrieveBatched(t *testing.T) {
235-
logger := zerolog.Nop()
236-
dataLayerHeight := uint64(100)
237-
238-
// Create 200 IDs to exceed default batch size
239-
numIDs := 200
240-
mockIDs := make([][]byte, numIDs)
241-
for i := range numIDs {
242-
mockIDs[i] = []byte{byte(i)}
243-
}
244-
245-
// Track which batches were requested
246-
batchCalls := []int{}
247-
248-
mockDAInstance := &mockDA{
249-
getIDsFunc: func(ctx context.Context, height uint64, namespace []byte) (*coreda.GetIDsResult, error) {
250-
return &coreda.GetIDsResult{
251-
IDs: mockIDs,
252-
Timestamp: time.Now(),
253-
}, nil
254-
},
255-
getFunc: func(ctx context.Context, ids []coreda.ID, namespace []byte) ([]coreda.Blob, error) {
256-
batchCalls = append(batchCalls, len(ids))
257-
// Return a blob for each ID in the batch
258-
blobs := make([][]byte, len(ids))
259-
for i := range ids {
260-
blobs[i] = []byte("blob")
261-
}
262-
return blobs, nil
263-
},
264-
}
265-
266-
client := NewClient(Config{
267-
DA: mockDAInstance,
268-
Logger: logger,
269-
Namespace: "test-ns",
270-
DataNamespace: "test-data-ns",
271-
RetrieveBatchSize: 50, // Set smaller batch size for testing
272-
})
273-
274-
encodedNamespace := coreda.NamespaceFromString("test-ns")
275-
result := client.Retrieve(context.Background(), dataLayerHeight, encodedNamespace.Bytes())
276-
277-
assert.Equal(t, coreda.StatusSuccess, result.Code)
278-
assert.Equal(t, numIDs, len(result.Data))
279-
280-
// Should have made 4 batches: 50 + 50 + 50 + 50 = 200
281-
assert.Equal(t, 4, len(batchCalls))
282-
assert.Equal(t, 50, batchCalls[0])
283-
assert.Equal(t, 50, batchCalls[1])
284-
assert.Equal(t, 50, batchCalls[2])
285-
assert.Equal(t, 50, batchCalls[3])
286-
}
287-
288-
func TestClient_RetrieveBatched_PartialBatch(t *testing.T) {
289-
logger := zerolog.Nop()
290-
dataLayerHeight := uint64(100)
291-
292-
// Create 175 IDs to test partial batch at the end
293-
numIDs := 175
294-
mockIDs := make([][]byte, numIDs)
295-
for i := range numIDs {
296-
mockIDs[i] = []byte{byte(i)}
297-
}
298-
299-
batchCalls := []int{}
300-
301-
mockDAInstance := &mockDA{
302-
getIDsFunc: func(ctx context.Context, height uint64, namespace []byte) (*coreda.GetIDsResult, error) {
303-
return &coreda.GetIDsResult{
304-
IDs: mockIDs,
305-
Timestamp: time.Now(),
306-
}, nil
307-
},
308-
getFunc: func(ctx context.Context, ids []coreda.ID, namespace []byte) ([]coreda.Blob, error) {
309-
batchCalls = append(batchCalls, len(ids))
310-
blobs := make([][]byte, len(ids))
311-
for i := range ids {
312-
blobs[i] = []byte("blob")
313-
}
314-
return blobs, nil
315-
},
316-
}
317-
318-
client := NewClient(Config{
319-
DA: mockDAInstance,
320-
Logger: logger,
321-
Namespace: "test-ns",
322-
DataNamespace: "test-data-ns",
323-
RetrieveBatchSize: 50,
324-
})
325-
326-
encodedNamespace := coreda.NamespaceFromString("test-ns")
327-
result := client.Retrieve(context.Background(), dataLayerHeight, encodedNamespace.Bytes())
328-
329-
assert.Equal(t, coreda.StatusSuccess, result.Code)
330-
assert.Equal(t, numIDs, len(result.Data))
331-
332-
// Should have made 4 batches: 50 + 50 + 50 + 25 = 175
333-
assert.Equal(t, 4, len(batchCalls))
334-
assert.Equal(t, 50, batchCalls[0])
335-
assert.Equal(t, 50, batchCalls[1])
336-
assert.Equal(t, 50, batchCalls[2])
337-
assert.Equal(t, 25, batchCalls[3]) // Partial batch
338-
}
339-
340-
func TestClient_RetrieveBatched_ErrorInSecondBatch(t *testing.T) {
341-
logger := zerolog.Nop()
342-
dataLayerHeight := uint64(100)
343-
344-
// Create 200 IDs to require multiple batches
345-
numIDs := 200
346-
mockIDs := make([][]byte, numIDs)
347-
for i := range numIDs {
348-
mockIDs[i] = []byte{byte(i)}
349-
}
350-
351-
batchCallCount := 0
192+
ns := share.MustNewV0Namespace([]byte("data-ns"))
193+
blb1, err := blobrpc.NewBlobV0(ns, []byte("data-blob-1"))
194+
require.NoError(t, err)
195+
blb2, err := blobrpc.NewBlobV0(ns, []byte("data-blob-2"))
196+
require.NoError(t, err)
352197

353-
mockDAInstance := &mockDA{
354-
getIDsFunc: func(ctx context.Context, height uint64, namespace []byte) (*coreda.GetIDsResult, error) {
355-
return &coreda.GetIDsResult{
356-
IDs: mockIDs,
357-
Timestamp: time.Now(),
358-
}, nil
359-
},
360-
getFunc: func(ctx context.Context, ids []coreda.ID, namespace []byte) ([]coreda.Blob, error) {
361-
batchCallCount++
362-
// Fail on second batch
363-
if batchCallCount == 2 {
364-
return nil, errors.New("network error in batch 2")
365-
}
366-
blobs := make([][]byte, len(ids))
367-
for i := range ids {
368-
blobs[i] = []byte("blob")
369-
}
370-
return blobs, nil
371-
},
198+
mockAPI := &mockBlobAPI{
199+
blobs: []*blobrpc.Blob{blb1, blb2},
372200
}
373201

374202
client := NewClient(Config{
375-
DA: mockDAInstance,
376-
Logger: logger,
377-
Namespace: "test-ns",
378-
DataNamespace: "test-data-ns",
379-
RetrieveBatchSize: 50,
203+
Client: makeBlobRPCClient(mockAPI),
204+
Logger: zerolog.Nop(),
205+
Namespace: "header-ns",
206+
DataNamespace: "data-ns",
380207
})
381208

382-
encodedNamespace := coreda.NamespaceFromString("test-ns")
383-
result := client.Retrieve(context.Background(), dataLayerHeight, encodedNamespace.Bytes())
209+
result := client.RetrieveData(context.Background(), 99)
384210

385-
assert.Equal(t, coreda.StatusError, result.Code)
386-
assert.Assert(t, result.Message != "")
387-
// Error message should mention the batch range
388-
assert.Assert(t, len(result.Message) > 0)
211+
assert.Equal(t, datypes.StatusSuccess, result.Code)
212+
assert.Equal(t, uint64(99), result.Height)
213+
assert.Equal(t, 2, len(result.Data))
389214
}

0 commit comments

Comments
 (0)