Skip to content

Commit 850849f

Browse files
committed
fix block streaming tests
1 parent 2d9e11b commit 850849f

File tree

3 files changed

+29
-12
lines changed

3 files changed

+29
-12
lines changed

cmd/access/node_builder/access_node_builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,7 @@ func (builder *FlowAccessNodeBuilder) Build() (cmd.Node, error) {
20602060
// handles block-related operations.
20612061
blockTracker, err := subscriptiontracker.NewBlockTracker(
20622062
node.State,
2063-
builder.FinalizedRootBlock.Height,
2063+
builder.SealedRootBlock.Height,
20642064
node.Storage.Headers,
20652065
broadcaster,
20662066
)

engine/access/rpc/backend/backend_stream_blocks_test.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type testType struct {
6262
highestBackfill int
6363
startValue interface{}
6464
blockStatus flow.BlockStatus
65+
expectedBlocks []*flow.Block
6566
}
6667

6768
func TestBackendBlocksSuite(t *testing.T) {
@@ -70,7 +71,7 @@ func TestBackendBlocksSuite(t *testing.T) {
7071

7172
// SetupTest initializes the test suite with required dependencies.
7273
func (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.
178181
func (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.
208218
func (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.
238255
func (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
}

engine/access/subscription/tracker/block_tracker.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,10 @@ type BlockTrackerImpl struct {
4444

4545
// NewBlockTracker creates a new BlockTrackerImpl instance.
4646
//
47-
// Parameters:
48-
// - state: The protocol state used for retrieving block information.
49-
// - rootHeight: The root block height, serving as the baseline for calculating the start height.
50-
// - headers: The storage headers for accessing block headers.
51-
// - broadcaster: The engine broadcaster for publishing notifications.
52-
//
5347
// No errors are expected during normal operation.
5448
func NewBlockTracker(
5549
state protocol.State,
56-
rootHeight uint64,
50+
sealedRootHeight uint64,
5751
headers storage.Headers,
5852
broadcaster *engine.Broadcaster,
5953
) (*BlockTrackerImpl, error) {
@@ -70,7 +64,7 @@ func NewBlockTracker(
7064
}
7165

7266
return &BlockTrackerImpl{
73-
BaseTracker: NewBaseTrackerImpl(rootHeight, state, headers),
67+
BaseTracker: NewBaseTrackerImpl(sealedRootHeight, state, headers),
7468
state: state,
7569
finalizedHighestHeight: counters.NewMonotonicCounter(lastFinalized.Height),
7670
sealedHighestHeight: counters.NewMonotonicCounter(lastSealed.Height),

0 commit comments

Comments
 (0)