Skip to content

Commit

Permalink
handle block status in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
illia-malachyn committed Oct 9, 2024
1 parent d81b3f3 commit 3a6992c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
14 changes: 12 additions & 2 deletions access/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1408,9 +1408,14 @@ func (c *BaseClient) SubscribeBlockDigestsFromStartHeight(
blockStatus flow.BlockStatus,
opts ...grpc.CallOption,
) (<-chan flow.BlockDigest, <-chan error, error) {
status := convert.BlockStatusToEntity(blockStatus)
if status == entities.BlockStatus_BLOCK_UNKNOWN {
return nil, nil, newRPCError(errors.New("unknown block status"))
}

request := &access.SubscribeBlockDigestsFromStartHeightRequest{
StartBlockHeight: startHeight,
BlockStatus: convert.BlockStatusToEntity(blockStatus),
BlockStatus: status,
}

subscribeClient, err := c.rpcClient.SubscribeBlockDigestsFromStartHeight(ctx, request, opts...)
Expand All @@ -1435,8 +1440,13 @@ func (c *BaseClient) SubscribeBlockDigestsFromLatest(
blockStatus flow.BlockStatus,
opts ...grpc.CallOption,
) (<-chan flow.BlockDigest, <-chan error, error) {
status := convert.BlockStatusToEntity(blockStatus)
if status == entities.BlockStatus_BLOCK_UNKNOWN {
return nil, nil, newRPCError(errors.New("unknown block status"))
}

request := &access.SubscribeBlockDigestsFromLatestRequest{
BlockStatus: convert.BlockStatusToEntity(blockStatus),
BlockStatus: status,
}

subscribeClient, err := c.rpcClient.SubscribeBlockDigestsFromLatest(ctx, request, opts...)
Expand Down
8 changes: 4 additions & 4 deletions access/grpc/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2571,7 +2571,7 @@ func TestClient_SubscribeBlockDigest(t *testing.T) {
On("SubscribeBlockDigestsFromStartHeight", ctx, mock.Anything).
Return(stream, nil)

blockDigestsCh, errCh, err := c.SubscribeBlockDigestsFromStartHeight(ctx, startHeight, flow.BlockStatusUnknown)
blockDigestsCh, errCh, err := c.SubscribeBlockDigestsFromStartHeight(ctx, startHeight, flow.BlockStatusSealed)
require.NoError(t, err)

wg := sync.WaitGroup{}
Expand Down Expand Up @@ -2602,7 +2602,7 @@ func TestClient_SubscribeBlockDigest(t *testing.T) {
Return(stream, nil)

startBlockID := convert.MessageToIdentifier(stream.responses[0].BlockId)
blockDigestsCh, errCh, err := c.SubscribeBlockDigestsFromStartBlockID(ctx, startBlockID, flow.BlockStatusUnknown)
blockDigestsCh, errCh, err := c.SubscribeBlockDigestsFromStartBlockID(ctx, startBlockID, flow.BlockStatusSealed)
require.NoError(t, err)

wg := sync.WaitGroup{}
Expand Down Expand Up @@ -2632,7 +2632,7 @@ func TestClient_SubscribeBlockDigest(t *testing.T) {
On("SubscribeBlockDigestsFromLatest", ctx, mock.Anything).
Return(stream, nil)

blockDigestsCh, errCh, err := c.SubscribeBlockDigestsFromLatest(ctx, flow.BlockStatusUnknown)
blockDigestsCh, errCh, err := c.SubscribeBlockDigestsFromLatest(ctx, flow.BlockStatusSealed)
require.NoError(t, err)

wg := sync.WaitGroup{}
Expand Down Expand Up @@ -2660,7 +2660,7 @@ func TestClient_SubscribeBlockDigest(t *testing.T) {
On("SubscribeBlockDigestsFromLatest", ctx, mock.Anything).
Return(stream, nil)

blockDigestsCh, errCh, err := c.SubscribeBlockDigestsFromLatest(ctx, flow.BlockStatusUnknown)
blockDigestsCh, errCh, err := c.SubscribeBlockDigestsFromLatest(ctx, flow.BlockStatusSealed)
require.NoError(t, err)

wg := sync.WaitGroup{}
Expand Down

0 comments on commit 3a6992c

Please sign in to comment.