Skip to content

Commit 82e4ed7

Browse files
Fix proxy_test
1 parent 5779c23 commit 82e4ed7

9 files changed

Lines changed: 39 additions & 29 deletions

File tree

block/manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func getManager(t *testing.T, da da.DA, gasPrice float64, gasMultiplier float64)
6161
// TestInitialStateClean verifies that getInitialState initializes state correctly when no state is stored.
6262
func TestInitialStateClean(t *testing.T) {
6363
require := require.New(t)
64-
ctx := context.TODO()
64+
ctx := t.Context()
6565

6666
// Create genesis document
6767
genesisData, _, _ := types.GetGenesisWithPrivkey("TestInitialStateClean")

core/da/dummy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ func (d *DummyDA) SubmitWithOptions(ctx context.Context, blobs []Blob, gasPrice
162162
d.mu.Lock()
163163
defer d.mu.Unlock()
164164

165-
height := uint64(len(d.blobsByHeight))
165+
height := d.currentHeight
166166
ids := make([]ID, 0, len(blobs))
167167
var currentSize uint64
168168

core/da/dummy_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
func TestDummyDA(t *testing.T) {
1010
// Create a new DummyDA instance with a max blob size of 1024 bytes
1111
dummyDA := NewDummyDA(1024, 0, 0, 10*time.Second)
12+
// Height is always 0
1213
ctx := context.Background()
1314

1415
// Test MaxBlobSize

core/da/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ var (
1111
ErrTxAlreadyInMempool = errors.New("tx already in mempool")
1212
ErrTxIncorrectAccountSequence = errors.New("incorrect account sequence")
1313
ErrContextDeadline = errors.New("context deadline")
14-
ErrFutureHeight = errors.New("future height")
14+
ErrHeightFromFuture = errors.New("given height is from the future")
1515
)

da/cmd/local-da/local.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func (d *LocalDA) GetIDs(ctx context.Context, height uint64, _ []byte) (*coreda.
112112

113113
if height > d.height {
114114
d.logger.Error("GetIDs: height in future", "requested", height, "current", d.height)
115-
return nil, fmt.Errorf("height %d is in the future: %w", height, coreda.ErrFutureHeight)
115+
return nil, fmt.Errorf("height %d is in the future: %w", height, coreda.ErrHeightFromFuture)
116116
}
117117

118118
kvps, ok := d.data[height]

da/jsonrpc/client.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"fmt"
88
"net/http"
9+
"strings"
910

1011
"cosmossdk.io/log"
1112
"github.com/filecoin-project/go-jsonrpc"
@@ -60,6 +61,10 @@ func (api *API) GetIDs(ctx context.Context, height uint64, _ []byte) (*da.GetIDs
6061
api.Logger.Debug("RPC call indicates blobs not found", "method", "GetIDs", "height", height)
6162
return nil, err // Return the specific ErrBlobNotFound
6263
}
64+
if strings.Contains(err.Error(), da.ErrHeightFromFuture.Error()) {
65+
api.Logger.Debug("RPC call indicates height from future", "method", "GetIDs", "height", height)
66+
return nil, err // Return the specific ErrHeightFromFuture
67+
}
6368
api.Logger.Error("RPC call failed", "method", "GetIDs", "error", err)
6469
return nil, err
6570
}

da/jsonrpc/proxy_test.go

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"errors"
77
"fmt"
8+
"strings"
89
"sync"
910
"testing"
1011
"time"
@@ -36,8 +37,14 @@ var emptyOptions = []byte{}
3637
// TestProxy runs the go-da DA test suite against the JSONRPC service
3738
// NOTE: This test requires a test JSONRPC service to run on the port
3839
// 3450 which is chosen to be sufficiently distinct from the default port
40+
41+
func getTestDABlockTime() time.Duration {
42+
return 100 * time.Millisecond
43+
}
44+
3945
func TestProxy(t *testing.T) {
40-
dummy := coreda.NewDummyDA(100_000, 0, 0, 10*time.Second)
46+
dummy := coreda.NewDummyDA(100_000, 0, 0, getTestDABlockTime())
47+
dummy.StartHeightTicker()
4148
logger := log.NewTestLogger(t)
4249
server := proxy.NewServer(logger, ServerHost, ServerPort, dummy)
4350
err := server.Start(context.Background())
@@ -50,25 +57,21 @@ func TestProxy(t *testing.T) {
5057

5158
client, err := proxy.NewClient(context.Background(), logger, ClientURL, "", "74657374")
5259
require.NoError(t, err)
53-
RunDATestSuite(t, &client.DA)
54-
}
5560

56-
// RunDATestSuite runs all tests against given DA
57-
func RunDATestSuite(t *testing.T, d coreda.DA) {
5861
t.Run("Basic DA test", func(t *testing.T) {
59-
BasicDATest(t, d)
62+
BasicDATest(t, &client.DA)
6063
})
6164
t.Run("Get IDs and all data", func(t *testing.T) {
62-
GetIDsTest(t, d)
65+
GetIDsTest(t, &client.DA)
6366
})
6467
t.Run("Check Errors", func(t *testing.T) {
65-
CheckErrors(t, d)
68+
CheckErrors(t, &client.DA)
6669
})
6770
t.Run("Concurrent read/write test", func(t *testing.T) {
68-
ConcurrentReadWriteTest(t, d)
71+
ConcurrentReadWriteTest(t, &client.DA)
6972
})
7073
t.Run("Given height is from the future", func(t *testing.T) {
71-
HeightFromFutureTest(t, d)
74+
HeightFromFutureTest(t, &client.DA)
7275
})
7376
}
7477

@@ -77,7 +80,7 @@ func BasicDATest(t *testing.T, d coreda.DA) {
7780
msg1 := []byte("message 1")
7881
msg2 := []byte("message 2")
7982

80-
ctx := context.TODO()
83+
ctx := t.Context()
8184
id1, err := d.Submit(ctx, []coreda.Blob{msg1}, 0, testNamespace)
8285
assert.NoError(t, err)
8386
assert.NotEmpty(t, id1)
@@ -86,6 +89,8 @@ func BasicDATest(t *testing.T, d coreda.DA) {
8689
assert.NoError(t, err)
8790
assert.NotEmpty(t, id2)
8891

92+
time.Sleep(getTestDABlockTime())
93+
8994
id3, err := d.SubmitWithOptions(ctx, []coreda.Blob{msg1}, 0, testNamespace, []byte("random options"))
9095
assert.NoError(t, err)
9196
assert.NotEmpty(t, id3)
@@ -119,7 +124,7 @@ func BasicDATest(t *testing.T, d coreda.DA) {
119124

120125
// CheckErrors ensures that errors are handled properly by DA.
121126
func CheckErrors(t *testing.T, d coreda.DA) {
122-
ctx := context.TODO()
127+
ctx := t.Context()
123128
blob, err := d.Get(ctx, []coreda.ID{[]byte("invalid blob id")}, testNamespace)
124129
assert.Error(t, err)
125130
assert.ErrorContains(t, err, coreda.ErrBlobNotFound.Error())
@@ -130,7 +135,7 @@ func CheckErrors(t *testing.T, d coreda.DA) {
130135
func GetIDsTest(t *testing.T, d coreda.DA) {
131136
msgs := []coreda.Blob{[]byte("msg1"), []byte("msg2"), []byte("msg3")}
132137

133-
ctx := context.TODO()
138+
ctx := t.Context()
134139
ids, err := d.Submit(ctx, msgs, 0, testNamespace)
135140
assert.NoError(t, err)
136141
assert.Len(t, ids, len(msgs))
@@ -140,9 +145,12 @@ func GetIDsTest(t *testing.T, d coreda.DA) {
140145
// To Keep It Simple: we assume working with DA used exclusively for this test (mock, devnet, etc)
141146
// As we're the only user, we don't need to handle external data (that could be submitted in real world).
142147
// There is no notion of height, so we need to scan the DA to get test data back.
143-
for i := uint64(1); !found && !time.Now().After(end); i++ {
148+
for i := uint64(0); !found && !time.Now().After(end); i++ {
144149
ret, err := d.GetIDs(ctx, i, []byte{})
145150
if err != nil {
151+
if strings.Contains(err.Error(), coreda.ErrHeightFromFuture.Error()) {
152+
break
153+
}
146154
t.Error("failed to get IDs:", err)
147155
}
148156
assert.NotNil(t, ret)
@@ -170,7 +178,7 @@ func GetIDsTest(t *testing.T, d coreda.DA) {
170178
// ConcurrentReadWriteTest tests the use of mutex lock in DummyDA by calling separate methods that use `d.data` and making sure there's no race conditions
171179
func ConcurrentReadWriteTest(t *testing.T, d coreda.DA) {
172180
var wg sync.WaitGroup
173-
ctx, cancel := context.WithTimeout(context.TODO(), 5*time.Second)
181+
ctx, cancel := context.WithTimeout(t.Context(), 5*time.Second)
174182
defer cancel()
175183

176184
writeDone := make(chan struct{})
@@ -179,7 +187,7 @@ func ConcurrentReadWriteTest(t *testing.T, d coreda.DA) {
179187
go func() {
180188
defer wg.Done()
181189
for i := uint64(1); i <= 50; i++ {
182-
_, err := d.Submit(ctx, []coreda.Blob{[]byte(fmt.Sprintf("test-%d", i))}, 0, []byte{})
190+
_, err := d.Submit(ctx, []coreda.Blob{[]byte(fmt.Sprintf("test-%d", i))}, 0, []byte("test"))
183191
assert.NoError(t, err)
184192
}
185193
close(writeDone)
@@ -193,10 +201,7 @@ func ConcurrentReadWriteTest(t *testing.T, d coreda.DA) {
193201
case <-writeDone:
194202
return
195203
default:
196-
ret, err := d.GetIDs(ctx, 1, []byte("test"))
197-
if err != nil {
198-
assert.Empty(t, ret.IDs)
199-
}
204+
d.GetIDs(ctx, 0, []byte("test"))
200205
}
201206
}
202207
}()
@@ -206,11 +211,11 @@ func ConcurrentReadWriteTest(t *testing.T, d coreda.DA) {
206211

207212
// HeightFromFutureTest tests the case when the given height is from the future
208213
func HeightFromFutureTest(t *testing.T, d coreda.DA) {
209-
ctx := context.TODO()
214+
ctx := t.Context()
210215
_, err := d.GetIDs(ctx, 999999999, []byte("test"))
211216
assert.Error(t, err)
212-
// Specifically check if the error is ErrBlobNotFound (or contains its message)
213-
assert.ErrorContains(t, err, coreda.ErrBlobNotFound.Error())
217+
// Specifically check if the error contains the error message ErrHeightFromFuture
218+
assert.ErrorContains(t, err, coreda.ErrHeightFromFuture.Error())
214219
}
215220

216221
// TestSubmitWithOptions tests the SubmitWithOptions method with various scenarios

node/full_node_integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ func (s *FullNodeTestSuite) TestBlockProduction() {
163163
// Verify chain state
164164
state, err := s.node.Store.GetState(s.ctx)
165165
s.NoError(err)
166-
s.GreaterOrEqual(height, state.LastBlockHeight)
166+
s.GreaterOrEqual(state.LastBlockHeight, height)
167167

168168
// Verify at least one block contains the test transaction
169169
s.True(foundTx, "Expected at least one block to contain the test transaction")

node/helpers_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ func createTestComponents(t *testing.T, config rollkitconfig.Config) (coreexecut
4343
executor := coreexecutor.NewDummyExecutor()
4444
sequencer := coresequencer.NewDummySequencer()
4545
dummyDA := coreda.NewDummyDA(100_000, 0, 0, config.DA.BlockTime.Duration)
46-
dummyDA.StartHeightTicker()
4746

4847
// Create genesis and keys for P2P client
4948
_, genesisValidatorKey, _ := types.GetGenesisWithPrivkey("test-chain")

0 commit comments

Comments
 (0)