-
Notifications
You must be signed in to change notification settings - Fork 268
Expand file tree
/
Copy pathclient_test.go
More file actions
126 lines (117 loc) · 4.04 KB
/
Copy pathclient_test.go
File metadata and controls
126 lines (117 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package jsonrpc
import (
"context"
"testing"
logging "github.com/ipfs/go-log/v2"
"github.com/stretchr/testify/assert"
"github.com/evstack/ev-node/core/da"
)
// TestSubmitWithOptions_SizeValidation tests the corrected behavior of SubmitWithOptions
// where it validates the entire batch before submission and returns ErrBlobSizeOverLimit
// if the batch is too large, instead of silently dropping blobs.
func TestSubmitWithOptions_SizeValidation(t *testing.T) {
logger := logging.Logger("test")
testCases := []struct {
name string
maxBlobSize uint64
inputBlobs []da.Blob
expectError bool
expectedError error
description string
}{
{
name: "Empty input",
maxBlobSize: 1000,
inputBlobs: []da.Blob{},
expectError: false,
description: "Empty input should return empty result without error",
},
{
name: "Single blob within limit",
maxBlobSize: 1000,
inputBlobs: []da.Blob{make([]byte, 500)},
expectError: false,
description: "Single blob smaller than limit should succeed",
},
{
name: "Single blob exceeds limit",
maxBlobSize: 1000,
inputBlobs: []da.Blob{make([]byte, 1500)},
expectError: true,
expectedError: da.ErrBlobSizeOverLimit,
description: "Single blob larger than limit should fail",
},
{
name: "Multiple blobs within limit",
maxBlobSize: 1000,
inputBlobs: []da.Blob{make([]byte, 300), make([]byte, 400), make([]byte, 200)},
expectError: false,
description: "Multiple blobs totaling less than limit should succeed",
},
{
name: "Multiple blobs exceed total limit",
maxBlobSize: 1000,
inputBlobs: []da.Blob{make([]byte, 400), make([]byte, 400), make([]byte, 400)},
expectError: true,
expectedError: da.ErrBlobSizeOverLimit,
description: "Multiple blobs totaling more than limit should fail completely",
},
{
name: "Mixed: some blobs fit, total exceeds limit",
maxBlobSize: 1000,
inputBlobs: []da.Blob{make([]byte, 100), make([]byte, 200), make([]byte, 800)},
expectError: true,
expectedError: da.ErrBlobSizeOverLimit,
description: "Should fail completely, not partially submit blobs that fit",
},
{
name: "One blob exceeds limit individually",
maxBlobSize: 1000,
inputBlobs: []da.Blob{make([]byte, 300), make([]byte, 1500), make([]byte, 200)},
expectError: true,
expectedError: da.ErrBlobSizeOverLimit,
description: "Should fail if any individual blob exceeds limit",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
// Create API with test configuration
api := &API{
Logger: logger,
MaxBlobSize: tc.maxBlobSize,
Namespace: []byte("test"),
}
// Mock the Internal.SubmitWithOptions to always succeed if called
// This tests that our validation logic works before reaching the actual RPC call
mockCalled := false
api.Internal.SubmitWithOptions = func(ctx context.Context, blobs []da.Blob, gasPrice float64, namespace []byte, options []byte) ([]da.ID, error) {
mockCalled = true
// Return mock IDs for successful submissions
ids := make([]da.ID, len(blobs))
for i := range blobs {
ids[i] = []byte{byte(i)}
}
return ids, nil
}
// Call SubmitWithOptions
ctx := context.Background()
result, err := api.SubmitWithOptions(ctx, tc.inputBlobs, 1.0, nil, nil)
// Verify expectations
if tc.expectError {
assert.Error(t, err, tc.description)
if tc.expectedError != nil {
assert.ErrorIs(t, err, tc.expectedError, tc.description)
}
assert.Nil(t, result, "Result should be nil on error")
assert.False(t, mockCalled, "Internal RPC should not be called when validation fails")
} else {
assert.NoError(t, err, tc.description)
assert.NotNil(t, result, "Result should not be nil on success")
if len(tc.inputBlobs) > 0 {
assert.True(t, mockCalled, "Internal RPC should be called for valid submissions")
assert.Len(t, result, len(tc.inputBlobs), "Should return IDs for all submitted blobs")
}
}
})
}
}