@@ -62,6 +62,7 @@ type testType struct {
6262 highestBackfill int
6363 startValue interface {}
6464 blockStatus flow.BlockStatus
65+ expectedBlocks []* flow.Block
6566}
6667
6768func TestBackendBlocksSuite (t * testing.T ) {
@@ -70,7 +71,7 @@ func TestBackendBlocksSuite(t *testing.T) {
7071
7172// SetupTest initializes the test suite with required dependencies.
7273func (s * BackendBlocksSuite ) SetupTest () {
73- s .log = zerolog . New ( zerolog . NewConsoleWriter () )
74+ s .log = unittest . Logger ( )
7475 s .state = new (protocol.State )
7576 s .snapshot = new (protocol.Snapshot )
7677 header := unittest .BlockHeaderFixture ()
@@ -98,13 +99,15 @@ func (s *BackendBlocksSuite) SetupTest() {
9899 parent := s .rootBlock .ToHeader ()
99100 s .blockMap [s .rootBlock .Height ] = s .rootBlock
100101
102+ s .T ().Logf ("Generating %d blocks, root block: %d %s" , blockCount , s .rootBlock .Height , s .rootBlock .ID ())
101103 for i := 0 ; i < blockCount ; i ++ {
102104 block := unittest .BlockWithParentFixture (parent )
103105 // update for next iteration
104106 parent = block .ToHeader ()
105107
106108 s .blocksArray = append (s .blocksArray , block )
107109 s .blockMap [block .Height ] = block
110+ s .T ().Logf ("Adding block %d %s" , block .Height , block .ID ())
108111 }
109112
110113 s .headers .On ("ByBlockID" , mock .AnythingOfType ("flow.Identifier" )).Return (
@@ -176,26 +179,33 @@ func (s *BackendBlocksSuite) backendParams() Params {
176179// starting from a specified block ID. It is designed to test the subscription functionality when the subscription
177180// starts from a custom block ID, either sealed or finalized.
178181func (s * BackendBlocksSuite ) subscribeFromStartBlockIdTestCases () []testType {
182+ expectedFromRoot := []* flow.Block {s .rootBlock }
183+ expectedFromRoot = append (expectedFromRoot , s .blocksArray ... )
184+
179185 baseTests := []testType {
180186 {
181187 name : "happy path - all new blocks" ,
182188 highestBackfill : - 1 , // no backfill
183189 startValue : s .rootBlock .ID (),
190+ expectedBlocks : expectedFromRoot ,
184191 },
185192 {
186193 name : "happy path - partial backfill" ,
187194 highestBackfill : 2 , // backfill the first 3 blocks
188195 startValue : s .blocksArray [0 ].ID (),
196+ expectedBlocks : s .blocksArray ,
189197 },
190198 {
191199 name : "happy path - complete backfill" ,
192200 highestBackfill : len (s .blocksArray ) - 1 , // backfill all blocks
193201 startValue : s .blocksArray [0 ].ID (),
202+ expectedBlocks : s .blocksArray ,
194203 },
195204 {
196205 name : "happy path - start from root block by id" ,
197206 highestBackfill : len (s .blocksArray ) - 1 , // backfill all blocks
198207 startValue : s .rootBlock .ID (), // start from root block
208+ expectedBlocks : expectedFromRoot ,
199209 },
200210 }
201211
@@ -206,26 +216,33 @@ func (s *BackendBlocksSuite) subscribeFromStartBlockIdTestCases() []testType {
206216// starting from a specified block height. It is designed to test the subscription functionality when the subscription
207217// starts from a custom height, either sealed or finalized.
208218func (s * BackendBlocksSuite ) subscribeFromStartHeightTestCases () []testType {
219+ expectedFromRoot := []* flow.Block {s .rootBlock }
220+ expectedFromRoot = append (expectedFromRoot , s .blocksArray ... )
221+
209222 baseTests := []testType {
210223 {
211224 name : "happy path - all new blocks" ,
212225 highestBackfill : - 1 , // no backfill
213226 startValue : s .rootBlock .Height ,
227+ expectedBlocks : expectedFromRoot ,
214228 },
215229 {
216230 name : "happy path - partial backfill" ,
217231 highestBackfill : 2 , // backfill the first 3 blocks
218232 startValue : s .blocksArray [0 ].Height ,
233+ expectedBlocks : s .blocksArray ,
219234 },
220235 {
221236 name : "happy path - complete backfill" ,
222237 highestBackfill : len (s .blocksArray ) - 1 , // backfill all blocks
223238 startValue : s .blocksArray [0 ].Height ,
239+ expectedBlocks : s .blocksArray ,
224240 },
225241 {
226242 name : "happy path - start from root block by id" ,
227243 highestBackfill : len (s .blocksArray ) - 1 , // backfill all blocks
228244 startValue : s .rootBlock .Height , // start from root block
245+ expectedBlocks : expectedFromRoot ,
229246 },
230247 }
231248
@@ -236,18 +253,24 @@ func (s *BackendBlocksSuite) subscribeFromStartHeightTestCases() []testType {
236253// starting from the latest sealed block. It is designed to test the subscription functionality when the subscription
237254// starts from the latest available block, either sealed or finalized.
238255func (s * BackendBlocksSuite ) subscribeFromLatestTestCases () []testType {
256+ expectedFromRoot := []* flow.Block {s .rootBlock }
257+ expectedFromRoot = append (expectedFromRoot , s .blocksArray ... )
258+
239259 baseTests := []testType {
240260 {
241261 name : "happy path - all new blocks" ,
242262 highestBackfill : - 1 , // no backfill
263+ expectedBlocks : expectedFromRoot ,
243264 },
244265 {
245266 name : "happy path - partial backfill" ,
246267 highestBackfill : 2 , // backfill the first 3 blocks
268+ expectedBlocks : expectedFromRoot ,
247269 },
248270 {
249271 name : "happy path - complete backfill" ,
250272 highestBackfill : len (s .blocksArray ) - 1 , // backfill all blocks
273+ expectedBlocks : expectedFromRoot ,
251274 },
252275 }
253276
@@ -396,7 +419,7 @@ func (s *BackendBlocksSuite) subscribe(
396419 sub := subscribeFn (subCtx , test .startValue , test .blockStatus )
397420
398421 // loop over all blocks
399- for i , b := range s . blocksArray {
422+ for i , b := range test . expectedBlocks {
400423 s .T ().Logf ("checking block %d %v %d" , i , b .ID (), b .Height )
401424
402425 // simulate new block received.
@@ -440,7 +463,7 @@ func (s *BackendBlocksSuite) requireBlocks(v interface{}, expectedBlock *flow.Bl
440463 actualBlock , ok := v .(* flow.Block )
441464 require .True (s .T (), ok , "unexpected response type: %T" , v )
442465
443- s .Require ().Equal ( expectedBlock .Height , actualBlock .Height )
466+ s .Require ().Equalf ( expectedBlock . Height , actualBlock . Height , "expected block height %d, got %d" , expectedBlock .Height , actualBlock .Height )
444467 s .Require ().Equal (expectedBlock .ID (), actualBlock .ID ())
445468 s .Require ().Equal (* expectedBlock , * actualBlock )
446469}
0 commit comments