Skip to content

Commit 9eb9e59

Browse files
authored
fix: Dummy test (#2300)
Fixes Deadlock in test <!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. NOTE: PR titles should follow semantic commits: https://www.conventionalcommits.org/en/v1.0.0/ --> ## Overview <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. Ex: Closes #<issue number> --> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Updated naming and visibility of certain components for improved accessibility. - Adjusted constructor and method signatures for consistency. - **Tests** - Streamlined and updated test cases for better clarity and reliability. - Modified test behavior to expect empty results rather than errors in specific scenarios. - Removed unused test and helper functions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 70d8b72 commit 9eb9e59

2 files changed

Lines changed: 32 additions & 41 deletions

File tree

core/sequencer/dummy.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,24 @@ import (
1010
// DummySequencer
1111
//---------------------
1212

13-
// dummySequencer is a dummy implementation of the Sequencer interface for testing
14-
type dummySequencer struct {
13+
var _ Sequencer = (*DummySequencer)(nil)
14+
15+
// DummySequencer is a dummy implementation of the Sequencer interface for testing
16+
type DummySequencer struct {
1517
mu sync.RWMutex
1618
batches map[string]*Batch
1719
batchSubmissionChan chan Batch
1820
}
1921

2022
// NewDummySequencer creates a new dummy Sequencer instance
21-
func NewDummySequencer() Sequencer {
22-
return &dummySequencer{
23+
func NewDummySequencer() *DummySequencer {
24+
return &DummySequencer{
2325
batches: make(map[string]*Batch),
2426
}
2527
}
2628

2729
// SubmitRollupBatchTxs submits a batch of transactions to the sequencer
28-
func (s *dummySequencer) SubmitRollupBatchTxs(ctx context.Context, req SubmitRollupBatchTxsRequest) (*SubmitRollupBatchTxsResponse, error) {
30+
func (s *DummySequencer) SubmitRollupBatchTxs(ctx context.Context, req SubmitRollupBatchTxsRequest) (*SubmitRollupBatchTxsResponse, error) {
2931
s.mu.Lock()
3032
defer s.mu.Unlock()
3133

@@ -37,7 +39,7 @@ func (s *dummySequencer) SubmitRollupBatchTxs(ctx context.Context, req SubmitRol
3739
}
3840

3941
// GetNextBatch gets the next batch from the sequencer
40-
func (s *dummySequencer) GetNextBatch(ctx context.Context, req GetNextBatchRequest) (*GetNextBatchResponse, error) {
42+
func (s *DummySequencer) GetNextBatch(ctx context.Context, req GetNextBatchRequest) (*GetNextBatchResponse, error) {
4143
s.mu.RLock()
4244
defer s.mu.RUnlock()
4345

@@ -53,12 +55,12 @@ func (s *dummySequencer) GetNextBatch(ctx context.Context, req GetNextBatchReque
5355
}
5456

5557
// VerifyBatch verifies a batch of transactions received from the sequencer
56-
func (s *dummySequencer) VerifyBatch(ctx context.Context, req VerifyBatchRequest) (*VerifyBatchResponse, error) {
58+
func (s *DummySequencer) VerifyBatch(ctx context.Context, req VerifyBatchRequest) (*VerifyBatchResponse, error) {
5759
return &VerifyBatchResponse{
5860
Status: true,
5961
}, nil
6062
}
6163

62-
func (s *dummySequencer) SetBatchSubmissionChan(batchSubmissionChan chan Batch) {
64+
func (s *DummySequencer) SetBatchSubmissionChan(batchSubmissionChan chan Batch) {
6365
s.batchSubmissionChan = batchSubmissionChan
6466
}

core/sequencer/dummy_test.go

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,16 @@
11
package sequencer
22

33
import (
4-
"context"
54
"fmt"
65
"reflect"
7-
"strings"
86
"testing"
97
"time"
108
)
119

12-
func TestNewDummySequencer(t *testing.T) {
13-
seq := NewDummySequencer()
14-
if seq == nil {
15-
t.Fatal("NewDummySequencer should return a non-nil sequencer")
16-
}
17-
18-
// Type assertion to ensure it's the correct type
19-
_, ok := seq.(*dummySequencer)
20-
if !ok {
21-
t.Fatal("NewDummySequencer should return a *dummySequencer")
22-
}
23-
}
24-
2510
func TestDummySequencer_SubmitRollupBatchTxs(t *testing.T) {
2611
seq := NewDummySequencer()
27-
ctx := context.Background()
12+
seq.SetBatchSubmissionChan(make(chan Batch, 1))
13+
ctx := t.Context()
2814

2915
// Create a test batch
3016
batch := &Batch{
@@ -66,21 +52,24 @@ func TestDummySequencer_SubmitRollupBatchTxs(t *testing.T) {
6652

6753
func TestDummySequencer_GetNextBatch(t *testing.T) {
6854
seq := NewDummySequencer()
69-
ctx := context.Background()
55+
seq.SetBatchSubmissionChan(make(chan Batch, 1))
56+
57+
ctx := t.Context()
7058

7159
t.Run("non-existent rollup ID", func(t *testing.T) {
7260
// Try to get a batch for a non-existent rollup ID
7361
nonExistentRollupID := []byte("non-existent-rollup")
74-
_, err := seq.GetNextBatch(ctx, GetNextBatchRequest{
62+
req, err := seq.GetNextBatch(ctx, GetNextBatchRequest{
7563
RollupId: nonExistentRollupID,
7664
})
77-
78-
// Should return an error
79-
if err == nil {
80-
t.Fatal("GetNextBatch should return an error for non-existent rollup ID")
65+
if err != nil {
66+
t.Fatalf("no error expected: %s", err)
67+
}
68+
if req == nil || req.Batch == nil {
69+
t.Fatal("unexpected nil response")
8170
}
82-
if err.Error() == "" || !contains(err.Error(), "no batch found for rollup ID") {
83-
t.Fatalf("Error message should indicate the rollup ID was not found, got: %v", err)
71+
if len(req.Batch.Transactions) != 0 {
72+
t.Error("batch should be empty")
8473
}
8574
})
8675

@@ -131,7 +120,8 @@ func TestDummySequencer_GetNextBatch(t *testing.T) {
131120

132121
func TestDummySequencer_VerifyBatch(t *testing.T) {
133122
seq := NewDummySequencer()
134-
ctx := context.Background()
123+
seq.SetBatchSubmissionChan(make(chan Batch, 1))
124+
ctx := t.Context()
135125

136126
// The dummy implementation always returns true regardless of input
137127
rollupID := []byte("test-rollup")
@@ -156,7 +146,7 @@ func TestDummySequencer_VerifyBatch(t *testing.T) {
156146

157147
func TestDummySequencer_Concurrency(t *testing.T) {
158148
seq := NewDummySequencer()
159-
ctx := context.Background()
149+
ctx := t.Context()
160150

161151
// Test concurrent submissions and retrievals
162152
const numGoroutines = 10
@@ -165,6 +155,7 @@ func TestDummySequencer_Concurrency(t *testing.T) {
165155
// Create a wait group to wait for all goroutines to finish
166156
done := make(chan struct{})
167157
errors := make(chan error, numGoroutines*numOperationsPerGoroutine)
158+
seq.SetBatchSubmissionChan(make(chan Batch, numGoroutines*numOperationsPerGoroutine))
168159

169160
for i := 0; i < numGoroutines; i++ {
170161
go func(routineID int) {
@@ -228,7 +219,9 @@ func TestDummySequencer_Concurrency(t *testing.T) {
228219

229220
func TestDummySequencer_MultipleRollups(t *testing.T) {
230221
seq := NewDummySequencer()
231-
ctx := context.Background()
222+
seq.SetBatchSubmissionChan(make(chan Batch, 3))
223+
224+
ctx := t.Context()
232225

233226
// Create multiple rollup IDs and batches
234227
rollupIDs := [][]byte{
@@ -271,7 +264,8 @@ func TestDummySequencer_MultipleRollups(t *testing.T) {
271264

272265
func TestDummySequencer_BatchOverwrite(t *testing.T) {
273266
seq := NewDummySequencer()
274-
ctx := context.Background()
267+
seq.SetBatchSubmissionChan(make(chan Batch, 3))
268+
ctx := t.Context()
275269

276270
rollupID := []byte("test-rollup")
277271

@@ -323,8 +317,3 @@ func TestDummySequencer_BatchOverwrite(t *testing.T) {
323317
t.Fatal("Retrieved batch should not be the first submitted one")
324318
}
325319
}
326-
327-
// Helper function to check if a string contains a substring
328-
func contains(s, substr string) bool {
329-
return strings.Contains(s, substr)
330-
}

0 commit comments

Comments
 (0)