@@ -5,12 +5,12 @@ import (
55 "testing"
66
77 "github.com/stretchr/testify/assert"
8- "github.com/stretchr/testify/mock"
98 "github.com/stretchr/testify/require"
109 "github.com/stretchr/testify/suite"
1110 "google.golang.org/grpc/codes"
1211 "google.golang.org/grpc/status"
1312
13+ "github.com/onflow/flow-go/engine"
1414 "github.com/onflow/flow-go/engine/access/subscription"
1515 "github.com/onflow/flow-go/model/flow"
1616 "github.com/onflow/flow-go/utils/unittest"
@@ -31,13 +31,6 @@ func (s *BackendBlockHeadersSuite) SetupTest() {
3131
3232// TestSubscribeBlockHeadersFromStartBlockID tests the SubscribeBlockHeadersFromStartBlockID method.
3333func (s * BackendBlockHeadersSuite ) TestSubscribeBlockHeadersFromStartBlockID () {
34- s .blockTracker .On (
35- "GetStartHeightFromBlockID" ,
36- mock .AnythingOfType ("flow.Identifier" ),
37- ).Return (func (startBlockID flow.Identifier ) (uint64 , error ) {
38- return s .blockTrackerReal .GetStartHeightFromBlockID (startBlockID )
39- }, nil )
40-
4134 call := func (ctx context.Context , startValue interface {}, blockStatus flow.BlockStatus ) subscription.Subscription {
4235 return s .backend .SubscribeBlockHeadersFromStartBlockID (ctx , startValue .(flow.Identifier ), blockStatus )
4336 }
@@ -47,13 +40,6 @@ func (s *BackendBlockHeadersSuite) TestSubscribeBlockHeadersFromStartBlockID() {
4740
4841// TestSubscribeBlockHeadersFromStartHeight tests the SubscribeBlockHeadersFromStartHeight method.
4942func (s * BackendBlockHeadersSuite ) TestSubscribeBlockHeadersFromStartHeight () {
50- s .blockTracker .On (
51- "GetStartHeightFromHeight" ,
52- mock .AnythingOfType ("uint64" ),
53- ).Return (func (startHeight uint64 ) (uint64 , error ) {
54- return s .blockTrackerReal .GetStartHeightFromHeight (startHeight )
55- }, nil )
56-
5743 call := func (ctx context.Context , startValue interface {}, blockStatus flow.BlockStatus ) subscription.Subscription {
5844 return s .backend .SubscribeBlockHeadersFromStartHeight (ctx , startValue .(uint64 ), blockStatus )
5945 }
@@ -63,13 +49,6 @@ func (s *BackendBlockHeadersSuite) TestSubscribeBlockHeadersFromStartHeight() {
6349
6450// TestSubscribeBlockHeadersFromLatest tests the SubscribeBlockHeadersFromLatest method.
6551func (s * BackendBlockHeadersSuite ) TestSubscribeBlockHeadersFromLatest () {
66- s .blockTracker .On (
67- "GetStartHeightFromLatest" ,
68- mock .Anything ,
69- ).Return (func (ctx context.Context ) (uint64 , error ) {
70- return s .blockTrackerReal .GetStartHeightFromLatest (ctx )
71- }, nil )
72-
7352 call := func (ctx context.Context , startValue interface {}, blockStatus flow.BlockStatus ) subscription.Subscription {
7453 return s .backend .SubscribeBlockHeadersFromLatest (ctx , blockStatus )
7554 }
@@ -106,43 +85,30 @@ func (s *BackendBlockHeadersSuite) TestSubscribeBlockHeadersHandlesErrors() {
10685 ctx , cancel := context .WithCancel (context .Background ())
10786 defer cancel ()
10887
109- // mock block tracker for GetStartHeightFromBlockID
110- s .blockTracker .On (
111- "GetStartHeightFromBlockID" ,
112- mock .AnythingOfType ("flow.Identifier" ),
113- ).Return (func (startBlockID flow.Identifier ) (uint64 , error ) {
114- return s .blockTrackerReal .GetStartHeightFromBlockID (startBlockID )
115- }, nil )
88+ backend , err := New (s .backendParams (engine .NewBroadcaster ()))
89+ s .Require ().NoError (err )
11690
11791 s .Run ("returns error for unknown start block id is provided" , func () {
11892 subCtx , subCancel := context .WithCancel (ctx )
11993 defer subCancel ()
12094
121- sub := s . backend .SubscribeBlockHeadersFromStartBlockID (subCtx , unittest .IdentifierFixture (), flow .BlockStatusFinalized )
95+ sub := backend .SubscribeBlockHeadersFromStartBlockID (subCtx , unittest .IdentifierFixture (), flow .BlockStatusFinalized )
12296 assert .Equal (s .T (), codes .NotFound , status .Code (sub .Err ()), "expected %s, got %v: %v" , codes .NotFound , status .Code (sub .Err ()).String (), sub .Err ())
12397 })
12498
125- // mock block tracker for GetStartHeightFromHeight
126- s .blockTracker .On (
127- "GetStartHeightFromHeight" ,
128- mock .AnythingOfType ("uint64" ),
129- ).Return (func (startHeight uint64 ) (uint64 , error ) {
130- return s .blockTrackerReal .GetStartHeightFromHeight (startHeight )
131- }, nil )
132-
13399 s .Run ("returns error if start height before root height" , func () {
134100 subCtx , subCancel := context .WithCancel (ctx )
135101 defer subCancel ()
136102
137- sub := s . backend .SubscribeBlockHeadersFromStartHeight (subCtx , s .rootBlock .Height - 1 , flow .BlockStatusFinalized )
103+ sub := backend .SubscribeBlockHeadersFromStartHeight (subCtx , s .rootBlock .Height - 1 , flow .BlockStatusFinalized )
138104 assert .Equal (s .T (), codes .InvalidArgument , status .Code (sub .Err ()), "expected %s, got %v: %v" , codes .InvalidArgument , status .Code (sub .Err ()).String (), sub .Err ())
139105 })
140106
141107 s .Run ("returns error for unknown start height is provided" , func () {
142108 subCtx , subCancel := context .WithCancel (ctx )
143109 defer subCancel ()
144110
145- sub := s . backend .SubscribeBlockHeadersFromStartHeight (subCtx , s .blocksArray [len (s .blocksArray )- 1 ].Height + 10 , flow .BlockStatusFinalized )
111+ sub := backend .SubscribeBlockHeadersFromStartHeight (subCtx , s .blocksArray [len (s .blocksArray )- 1 ].Height + 10 , flow .BlockStatusFinalized )
146112 assert .Equal (s .T (), codes .NotFound , status .Code (sub .Err ()), "expected %s, got %v: %v" , codes .NotFound , status .Code (sub .Err ()).String (), sub .Err ())
147113 })
148114}
0 commit comments