@@ -2,6 +2,7 @@ package executing
22
33import (
44 "context"
5+ "fmt"
56 "testing"
67 "time"
78
@@ -256,6 +257,8 @@ func TestExecutor_RestartNoPendingHeader(t *testing.T) {
256257 cfg .Node .BlockTime = config.DurationWrapper {Duration : 10 * time .Millisecond }
257258 cfg .Node .MaxPendingHeadersAndData = 1000
258259
260+ const numBlocks = 5
261+
259262 gen := genesis.Genesis {
260263 ChainID : "test-chain" ,
261264 InitialHeight : 1 ,
@@ -294,24 +297,29 @@ func TestExecutor_RestartNoPendingHeader(t *testing.T) {
294297 Return (initStateRoot , uint64 (1024 ), nil ).Once ()
295298 require .NoError (t , exec1 .initializeState ())
296299
297- exec1 .ctx , exec1 .cancel = context .WithCancel (context . Background ())
300+ exec1 .ctx , exec1 .cancel = context .WithCancel (t . Context ())
298301
299- // Produce first block
302+ // Produce n blocks
300303 mockSeq1 .EXPECT ().GetNextBatch (mock .Anything , mock .AnythingOfType ("sequencer.GetNextBatchRequest" )).
301304 RunAndReturn (func (ctx context.Context , req coreseq.GetNextBatchRequest ) (* coreseq.GetNextBatchResponse , error ) {
302305 return & coreseq.GetNextBatchResponse {
303306 Batch : & coreseq.Batch {
304- Transactions : [][]byte {[]byte ("tx1 " )},
307+ Transactions : [][]byte {[]byte ("any_tx " )},
305308 },
306309 Timestamp : time .Now (),
307310 }, nil
308- }).Once ( )
311+ }).Times ( numBlocks )
309312
310- mockExec1 .EXPECT ().ExecuteTxs (mock .Anything , mock .Anything , uint64 (1 ), mock .AnythingOfType ("time.Time" ), initStateRoot ).
311- Return ([]byte ("new_root_1" ), uint64 (1024 ), nil ).Once ()
313+ lastStateRoot := initStateRoot
314+ for i := range numBlocks {
315+ newStateRoot := []byte (fmt .Sprintf ("new_root_%d" , i + 1 ))
316+ mockExec1 .EXPECT ().ExecuteTxs (mock .Anything , mock .Anything , gen .InitialHeight + uint64 (i ), mock .AnythingOfType ("time.Time" ), lastStateRoot ).
317+ Return (newStateRoot , uint64 (1024 ), nil ).Once ()
318+ lastStateRoot = newStateRoot
312319
313- err = exec1 .produceBlock ()
314- require .NoError (t , err )
320+ require .NoError (t , exec1 .produceBlock ())
321+ }
322+ require .Equal (t , uint64 (numBlocks ), exec1 .GetLastState ().LastBlockHeight )
315323
316324 // Stop first executor
317325 exec1 .cancel ()
@@ -343,12 +351,12 @@ func TestExecutor_RestartNoPendingHeader(t *testing.T) {
343351 require .NoError (t , err )
344352
345353 require .NoError (t , exec2 .initializeState ())
346- exec2 .ctx , exec2 .cancel = context .WithCancel (context . Background ())
354+ exec2 .ctx , exec2 .cancel = context .WithCancel (t . Context ())
347355 defer exec2 .cancel ()
348356
349357 // Verify state loaded correctly
350358 state := exec2 .getLastState ()
351- assert .Equal (t , uint64 (1 ), state .LastBlockHeight )
359+ require .Equal (t , uint64 (numBlocks ), state .LastBlockHeight )
352360
353361 // Now produce next block - should go through normal sequencer flow since no pending block
354362 mockSeq2 .EXPECT ().GetNextBatch (mock .Anything , mock .AnythingOfType ("sequencer.GetNextBatchRequest" )).
@@ -361,16 +369,16 @@ func TestExecutor_RestartNoPendingHeader(t *testing.T) {
361369 }, nil
362370 }).Once ()
363371
364- mockExec2 .EXPECT ().ExecuteTxs (mock .Anything , mock .Anything , uint64 (2 ), mock .AnythingOfType ("time.Time" ), [] byte ( "new_root_1" ) ).
365- Return ([]byte ("new_root_2 " ), uint64 (1024 ), nil ).Once ()
372+ mockExec2 .EXPECT ().ExecuteTxs (mock .Anything , mock .Anything , uint64 (numBlocks + 1 ), mock .AnythingOfType ("time.Time" ), lastStateRoot ).
373+ Return ([]byte ("new_root_after_restart " ), uint64 (1024 ), nil ).Once ()
366374
367375 err = exec2 .produceBlock ()
368376 require .NoError (t , err )
369377
370378 // Verify normal operation
371379 h , err := memStore .Height (context .Background ())
372380 require .NoError (t , err )
373- assert .Equal (t , uint64 (2 ), h )
381+ assert .Equal (t , uint64 (numBlocks + 1 ), h )
374382
375383 // Verify sequencer was called (normal flow)
376384 mockSeq2 .AssertCalled (t , "GetNextBatch" , mock .Anything , mock .AnythingOfType ("sequencer.GetNextBatchRequest" ))
0 commit comments