@@ -8,21 +8,11 @@ import (
88 "testing"
99 "time"
1010
11- "cosmossdk.io/log"
1211 testutils "github.com/celestiaorg/utils/test"
13- ds "github.com/ipfs/go-datastore"
14- dssync "github.com/ipfs/go-datastore/sync"
1512 "github.com/stretchr/testify/require"
1613 "github.com/stretchr/testify/suite"
1714
18- coreda "github.com/rollkit/rollkit/core/da"
1915 coreexecutor "github.com/rollkit/rollkit/core/execution"
20- coresequencer "github.com/rollkit/rollkit/core/sequencer"
21- rollkitconfig "github.com/rollkit/rollkit/pkg/config"
22- "github.com/rollkit/rollkit/pkg/p2p"
23- "github.com/rollkit/rollkit/pkg/p2p/key"
24- remote_signer "github.com/rollkit/rollkit/pkg/signer/noop"
25- "github.com/rollkit/rollkit/types"
2616)
2717
2818// FullNodeTestSuite is a test suite for full node integration tests
@@ -56,114 +46,31 @@ func (s *FullNodeTestSuite) SetupTest() {
5646 s .ctx , s .cancel = context .WithCancel (context .Background ())
5747 s .errCh = make (chan error , 1 )
5848
59- // Setup node with proper configuration
49+ // Setup a test node
6050 config := getTestConfig (s .T (), 1 )
61- config .Node .BlockTime .Duration = 100 * time .Millisecond // Faster block production for tests
62- config .DA .BlockTime .Duration = 200 * time .Millisecond // Faster DA submission for tests
63- config .Node .MaxPendingBlocks = 100 // Allow more pending blocks
64- config .Node .Aggregator = true // Enable aggregator mode
6551
6652 // Add debug logging for configuration
6753 s .T ().Logf ("Test configuration: BlockTime=%v, DABlockTime=%v, MaxPendingBlocks=%d" ,
6854 config .Node .BlockTime .Duration , config .DA .BlockTime .Duration , config .Node .MaxPendingBlocks )
6955
70- // Create genesis with current time
71- genesis , genesisValidatorKey , _ := types .GetGenesisWithPrivkey ("test-chain" )
72- remoteSigner , err := remote_signer .NewNoopSigner (genesisValidatorKey )
73- require .NoError (err )
74-
75- // Create node key for P2P client
76- nodeKey := & key.NodeKey {
77- PrivKey : genesisValidatorKey ,
78- PubKey : genesisValidatorKey .GetPublic (),
79- }
56+ node , cleanup := setupTestNodeWithCleanup (s .T (), config )
57+ defer cleanup ()
8058
81- config .ChainID = genesis .ChainID
82-
83- dummyExec := coreexecutor .NewDummyExecutor ()
84- dummySequencer := coresequencer .NewDummySequencer ()
85- dummyDA := coreda .NewDummyDA (100_000 , 0 , 0 )
86- dummyClient := coreda .NewDummyClient (dummyDA , []byte (MockDANamespace ))
87- p2pClient , err := p2p .NewClient (config , nodeKey , dssync .MutexWrap (ds .NewMapDatastore ()), log .NewTestLogger (s .T ()), p2p .NopMetrics ())
88- require .NoError (err )
89-
90- err = InitFiles (config .RootDir )
91- require .NoError (err )
92-
93- node , err := NewNode (
94- s .ctx ,
95- config ,
96- dummyExec ,
97- dummySequencer ,
98- dummyClient ,
99- remoteSigner ,
100- * nodeKey ,
101- p2pClient ,
102- genesis ,
103- dssync .MutexWrap (ds .NewMapDatastore ()),
104- DefaultMetricsProvider (rollkitconfig .DefaultInstrumentationConfig ()),
105- log .NewTestLogger (s .T ()),
106- )
107- require .NoError (err )
108- require .NotNil (node )
59+ s .node = node
10960
110- fn , ok := node .(* FullNode )
111- require .True (ok )
112-
113- s .node = fn
114-
115- s .executor = dummyExec
61+ s .executor = node .blockManager .GetExecutor ().(* coreexecutor.DummyExecutor )
11662
11763 // Start the node in a goroutine using Run instead of Start
11864 s .startNodeInBackground (s .node )
11965
120- // Wait for the node to start and initialize DA connection
121- time .Sleep (1 * time .Second )
122-
12366 // Verify that the node is running and producing blocks
124- height , err := getNodeHeight (s .node , Header )
67+ err := waitForFirstBlock (s .node , Header )
12568 require .NoError (err , "Failed to get node height" )
126- require .Greater (height , uint64 (0 ), "Node should have produced at least one block" )
12769
128- // Wait for DA inclusion with retry
129- err = testutils .Retry (30 , 100 * time .Millisecond , func () error {
130- daHeight := s .node .blockManager .GetDAIncludedHeight ()
131- if daHeight == 0 {
132- return fmt .Errorf ("waiting for DA inclusion" )
133- }
134- return nil
135- })
70+ // Wait for the first block to be DA included
71+ err = waitForFirstBlockToBeDAIncludedHeight (s .node )
13672 require .NoError (err , "Failed to get DA inclusion" )
13773
138- // Wait for additional blocks to be produced
139- time .Sleep (500 * time .Millisecond )
140-
141- // Additional debug info after node start
142- initialHeight , err := s .node .Store .Height (s .ctx )
143- require .NoError (err )
144- s .T ().Logf ("Node started - Initial block height: %d" , initialHeight )
145- s .T ().Logf ("DA client initialized: %v" , s .node .blockManager .DALCInitialized ())
146-
147- // Wait longer for height to stabilize and log intermediate values
148- for range 5 {
149- time .Sleep (200 * time .Millisecond )
150- currentHeight , err := s .node .Store .Height (s .ctx )
151- require .NoError (err )
152- s .T ().Logf ("Current height during stabilization: %d" , currentHeight )
153- }
154-
155- // Get final height after stabilization period
156- finalHeight , err := s .node .Store .Height (s .ctx )
157- require .NoError (err )
158- s .T ().Logf ("Final setup height: %d" , finalHeight )
159-
160- // Store the stable height for test use
161- s .node .blockManager .SetLastState (s .node .blockManager .GetLastState ())
162-
163- // Log additional state information
164- s .T ().Logf ("Last submitted height: %d" , s .node .blockManager .PendingHeaders ().GetLastSubmittedHeight ())
165- s .T ().Logf ("DA included height: %d" , s .node .blockManager .GetDAIncludedHeight ())
166-
16774 // Verify sequencer client is working
16875 err = testutils .Retry (30 , 100 * time .Millisecond , func () error {
16976 if s .node .blockManager .SeqClient () == nil {
@@ -213,11 +120,48 @@ func TestFullNodeTestSuite(t *testing.T) {
213120 suite .Run (t , new (FullNodeTestSuite ))
214121}
215122
123+ func (s * FullNodeTestSuite ) TestBlockProduction () {
124+ s .executor .InjectTx ([]byte ("test transaction" ))
125+ err := waitForAtLeastNBlocks (s .node , 5 , Store )
126+ s .NoError (err , "Failed to produce second block" )
127+
128+ // Get the current height
129+ height , err := s .node .Store .Height (s .ctx )
130+ require .NoError (s .T (), err )
131+ s .GreaterOrEqual (height , uint64 (5 ), "Expected block height >= 5" )
132+
133+ // Get all blocks and log their contents
134+ for h := uint64 (1 ); h <= height ; h ++ {
135+ header , data , err := s .node .Store .GetBlockData (s .ctx , h )
136+ s .NoError (err )
137+ s .NotNil (header )
138+ s .NotNil (data )
139+ s .T ().Logf ("Block height: %d, Time: %s, Number of transactions: %d" , h , header .Time (), len (data .Txs ))
140+ }
141+
142+ // Get the latest block
143+ header , data , err := s .node .Store .GetBlockData (s .ctx , height )
144+ s .NoError (err )
145+ s .NotNil (header )
146+ s .NotNil (data )
147+
148+ // Log block details
149+ s .T ().Logf ("Latest block height: %d, Time: %s, Number of transactions: %d" , height , header .Time (), len (data .Txs ))
150+
151+ // Verify chain state
152+ state , err := s .node .Store .GetState (s .ctx )
153+ s .NoError (err )
154+ s .Equal (height , state .LastBlockHeight )
155+
156+ // Verify block content
157+ s .NotEmpty (data .Txs , "Expected block to contain transactions" )
158+ }
159+
160+ // TestSubmitBlocksToDA tests the submission of blocks to the DA
216161func (s * FullNodeTestSuite ) TestSubmitBlocksToDA () {
217162 require := require .New (s .T ())
218163
219164 // Get initial state
220- initialDAHeight := s .node .blockManager .GetDAIncludedHeight ()
221165 initialHeight , err := getNodeHeight (s .node , Header )
222166 require .NoError (err )
223167
@@ -236,38 +180,19 @@ func (s *FullNodeTestSuite) TestSubmitBlocksToDA() {
236180
237181 // Monitor batch retrieval
238182 s .T ().Log ("=== Monitoring Batch Retrieval ===" )
239- for i := range 5 {
240- time .Sleep (200 * time .Millisecond )
241- // We can't directly check batch queue size, but we can monitor block production
242- currentHeight , err := s .node .Store .Height (s .ctx )
243- require .NoError (err )
244- s .T ().Logf ("Current height after batch check %d: %d" , i , currentHeight )
245- }
246-
247- // Try to trigger block production explicitly
248- s .T ().Log ("=== Attempting to Trigger Block Production ===" )
249-
250- // Monitor after trigger
251- for i := range 5 {
252- time .Sleep (200 * time .Millisecond )
253- currentHeight , err := s .node .Store .Height (s .ctx )
254- require .NoError (err )
255- currentDAHeight := s .node .blockManager .GetDAIncludedHeight ()
256- pendingHeaders , _ := s .node .blockManager .PendingHeaders ().GetPendingHeaders ()
257- s .T ().Logf ("Post-trigger check %d - Height: %d, DA Height: %d, Pending: %d" ,
258- i , currentHeight , currentDAHeight , len (pendingHeaders ))
259- }
183+ err = waitForAtLeastNBlocks (s .node , 5 , Store )
184+ require .NoError (err , "Failed to produce additional blocks" )
260185
261186 // Final assertions with more detailed error messages
262- finalDAHeight := s .node .blockManager .GetDAIncludedHeight ()
263187 finalHeight , err := s .node .Store .Height (s .ctx )
264188 require .NoError (err )
265189
266190 require .Greater (finalHeight , initialHeight , "Block height should have increased" )
267- require .Greater (finalDAHeight , initialDAHeight , "DA height should have increased" )
268191}
269192
270193func (s * FullNodeTestSuite ) TestDAInclusion () {
194+ s .T ().Skip ("skipping DA inclusion test" )
195+ // this test currently thinks DAIncludedHeight is returning a DA height, but it's actually returning a block height
271196 require := require .New (s .T ())
272197
273198 // Get initial height and DA height
@@ -335,6 +260,7 @@ func (s *FullNodeTestSuite) TestDAInclusion() {
335260 require .Greater (finalDAHeight , initialDAHeight , "DA height should increase" )
336261}
337262
263+ // TestMaxPending tests that the node will stop producing blocks when the limit is reached
338264func (s * FullNodeTestSuite ) TestMaxPending () {
339265 require := require .New (s .T ())
340266
@@ -351,39 +277,10 @@ func (s *FullNodeTestSuite) TestMaxPending() {
351277 config := getTestConfig (s .T (), 1 )
352278 config .Node .MaxPendingBlocks = 2
353279
354- genesis , genesisValidatorKey , _ := types .GetGenesisWithPrivkey ("test-chain" )
355- remoteSigner , err := remote_signer .NewNoopSigner (genesisValidatorKey )
356- require .NoError (err )
357-
358- nodeKey , err := key .GenerateNodeKey ()
359- require .NoError (err )
360-
361- executor , sequencer , dac , p2pClient , ds := createTestComponents (s .T ())
362-
363- err = InitFiles (config .RootDir )
364- require .NoError (err )
365-
366- node , err := NewNode (
367- s .ctx ,
368- config ,
369- executor ,
370- sequencer ,
371- dac ,
372- remoteSigner ,
373- * nodeKey ,
374- p2pClient ,
375- genesis ,
376- ds ,
377- DefaultMetricsProvider (rollkitconfig .DefaultInstrumentationConfig ()),
378- log .NewTestLogger (s .T ()),
379- )
380- require .NoError (err )
381- require .NotNil (node )
382-
383- fn , ok := node .(* FullNode )
384- require .True (ok )
280+ node , cleanup := setupTestNodeWithCleanup (s .T (), config )
281+ defer cleanup ()
385282
386- s .node = fn
283+ s .node = node
387284
388285 // Start the node using Run in a goroutine
389286 s .startNodeInBackground (s .node )
@@ -415,7 +312,7 @@ func (s *FullNodeTestSuite) TestStateRecovery() {
415312 require .NoError (err )
416313
417314 // Wait for some blocks
418- time . Sleep ( 2 * s .node . nodeConfig . Node . BlockTime . Duration )
315+ waitForAtLeastNBlocks ( s .node , 5 , Store )
419316
420317 // Stop the current node
421318 s .cancel ()
@@ -431,51 +328,20 @@ func (s *FullNodeTestSuite) TestStateRecovery() {
431328 case <- waitCh :
432329 // Node stopped successfully
433330 case <- time .After (2 * time .Second ):
434- s .T ().Log ( "Warning: Node did not stop gracefully within timeout" )
331+ s .T ().Fatalf ( " Node did not stop gracefully within timeout" )
435332 }
436333
437334 // Create a new context
438335 s .ctx , s .cancel = context .WithCancel (context .Background ())
439336 s .errCh = make (chan error , 1 )
440337
441- // Create a NEW node instance instead of reusing the old one
442338 config := getTestConfig (s .T (), 1 )
443- genesis , genesisValidatorKey , _ := types .GetGenesisWithPrivkey ("test-chain" )
444- remoteSigner , err := remote_signer .NewNoopSigner (genesisValidatorKey )
445- require .NoError (err )
446-
447- dummyExec := coreexecutor .NewDummyExecutor ()
448- dummySequencer := coresequencer .NewDummySequencer ()
449- dummyDA := coreda .NewDummyDA (100_000 , 0 , 0 )
450- dummyClient := coreda .NewDummyClient (dummyDA , []byte (MockDANamespace ))
451- config .ChainID = genesis .ChainID
452- p2pClient , err := p2p .NewClient (config , nil , dssync .MutexWrap (ds .NewMapDatastore ()), log .NewTestLogger (s .T ()), p2p .NopMetrics ())
453- require .NoError (err )
454-
455- nodeKey , err := key .GenerateNodeKey ()
456- require .NoError (err )
457-
458- node , err := NewNode (
459- s .ctx ,
460- config ,
461- dummyExec ,
462- dummySequencer ,
463- dummyClient ,
464- remoteSigner ,
465- * nodeKey ,
466- p2pClient ,
467- genesis ,
468- dssync .MutexWrap (ds .NewMapDatastore ()),
469- DefaultMetricsProvider (rollkitconfig .DefaultInstrumentationConfig ()),
470- log .NewTestLogger (s .T ()),
471- )
472- require .NoError (err )
473-
474- fn , ok := node .(* FullNode )
475- require .True (ok )
339+ // Create a new node instance instead of reusing the old one
340+ node , cleanup := setupTestNodeWithCleanup (s .T (), config )
341+ defer cleanup ()
476342
477343 // Replace the old node with the new one
478- s .node = fn
344+ s .node = node
479345
480346 // Start the new node
481347 s .startNodeInBackground (s .node )
0 commit comments