11package block
22
33import (
4+ "bytes"
45 "context"
56 "encoding/binary"
67 "errors"
@@ -27,7 +28,12 @@ import (
2728)
2829
2930// setupManagerForPublishBlockTest creates a Manager instance with mocks for testing publishBlockInternal.
30- func setupManagerForPublishBlockTest (t * testing.T , isProposer bool , initialHeight uint64 , lastSubmittedHeight uint64 ) (
31+ func setupManagerForPublishBlockTest (
32+ t * testing.T ,
33+ initialHeight uint64 ,
34+ lastSubmittedHeight uint64 ,
35+ logBuffer * bytes.Buffer ,
36+ ) (
3137 * Manager ,
3238 * mocks.Store ,
3339 * mocks.Executor ,
@@ -57,7 +63,10 @@ func setupManagerForPublishBlockTest(t *testing.T, isProposer bool, initialHeigh
5763 headerCh := make (chan * types.SignedHeader , 1 )
5864 dataCh := make (chan * types.Data , 1 )
5965 _ , cancel := context .WithCancel (context .Background ())
60- logger := log .NewTestLogger (t )
66+ logger := log .NewLogger (
67+ logBuffer ,
68+ log .ColorOption (false ),
69+ )
6170
6271 lastSubmittedBytes := make ([]byte , 8 )
6372 binary .LittleEndian .PutUint64 (lastSubmittedBytes , lastSubmittedHeight )
@@ -109,14 +118,14 @@ func setupManagerForPublishBlockTest(t *testing.T, isProposer bool, initialHeigh
109118// TestPublishBlockInternal_MaxPendingHeadersReached verifies that publishBlockInternal returns an error if the maximum number of pending headers is reached.
110119func TestPublishBlockInternal_MaxPendingHeadersReached (t * testing.T ) {
111120 t .Parallel ()
112- assert := assert .New (t )
113121 require := require .New (t )
114122
115123 currentHeight := uint64 (10 )
116124 lastSubmitted := uint64 (5 )
117125 maxPending := uint64 (5 )
126+ logBuffer := new (bytes.Buffer )
118127
119- manager , mockStore , mockExec , mockSeq , _ , _ , _ , cancel := setupManagerForPublishBlockTest (t , true , currentHeight + 1 , lastSubmitted )
128+ manager , mockStore , mockExec , mockSeq , _ , _ , _ , cancel := setupManagerForPublishBlockTest (t , currentHeight + 1 , lastSubmitted , logBuffer )
120129 defer cancel ()
121130
122131 manager .config .Node .MaxPendingHeaders = maxPending
@@ -126,8 +135,8 @@ func TestPublishBlockInternal_MaxPendingHeadersReached(t *testing.T) {
126135
127136 err := manager .publishBlock (ctx )
128137
129- require .Error (err , "publishBlockInternal should return an error" )
130- assert .Contains (err . Error (), "pending blocks [5] reached limit [5]" , "error message mismatch" )
138+ require .Nil (err , "publishBlockInternal should not return an error (otherwise the chain would halt) " )
139+ require .Contains (logBuffer . String (), "pending blocks [5] reached limit [5]" , "log message mismatch" )
131140
132141 mockStore .AssertExpectations (t )
133142 mockExec .AssertNotCalled (t , "GetTxs" , mock .Anything )
@@ -336,7 +345,7 @@ func Test_publishBlock_Success(t *testing.T) {
336345 newHeight := initialHeight + 1
337346 chainID := "testchain"
338347
339- manager , mockStore , mockExec , mockSeq , _ , headerCh , dataCh , _ := setupManagerForPublishBlockTest (t , true , initialHeight , 0 )
348+ manager , mockStore , mockExec , mockSeq , _ , headerCh , dataCh , _ := setupManagerForPublishBlockTest (t , initialHeight , 0 , new (bytes. Buffer ) )
340349 manager .lastState .LastBlockHeight = initialHeight
341350
342351 mockStore .On ("Height" , t .Context ()).Return (initialHeight , nil ).Once ()
0 commit comments