From 9591858f7fc388eeba022edd061d4b515a936308 Mon Sep 17 00:00:00 2001 From: gupadhyaya Date: Thu, 8 Aug 2024 16:27:18 +0400 Subject: [PATCH] fix GetNextBatch of dummy sequencer --- test/dummy.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/dummy.go b/test/dummy.go index bd02b21..e8cafda 100644 --- a/test/dummy.go +++ b/test/dummy.go @@ -70,11 +70,28 @@ func (d *DummySequencer) SubmitRollupTransaction(ctx context.Context, rollupId [ // GetNextBatch implements sequencing.Sequencer. func (d *DummySequencer) GetNextBatch(ctx context.Context, lastBatch *sequencing.Batch) (*sequencing.Batch, error) { + if d.lastBatchHash == nil { + if lastBatch != nil { + return nil, errors.New("lastBatch is supposed to be nil") + } + } else if lastBatch == nil { + return nil, errors.New("lastBatch is not supposed to be nil") + } else { + lastBatchBytes, err := lastBatch.Marshal() + if err != nil { + return nil, err + } + if !bytes.Equal(d.lastBatchHash, hashSHA256(lastBatchBytes)) { + return nil, errors.New("supplied lastBatch does not match with sequencer last batch") + } + } + batch := d.tq.GetNextBatch() batchBytes, err := batch.Marshal() if err != nil { return nil, err } + d.lastBatchHash = hashSHA256(batchBytes) d.seenBatches[string(d.lastBatchHash)] = struct{}{} return &batch, nil