@@ -29,32 +29,70 @@ func TestService_Lifecycle(t *testing.T) {
2929 require .NoError (t , err , "make available should not return error" )
3030 require .True (t , service .Available (), "service should be available after make available" )
3131
32- // when
33- info , err := service .GetInfo (t .Context ())
34-
35- // then:
36- require .NoError (t , err , "get info should not return error" )
37- assert .Equal (t , defs .NetworkMainnet , info .Chain )
38- assert .Equal (t , "gorm-sqlite-inmemory" , info .Storage )
39- assert .Equal (t , []string {"woc_poll" }, info .LiveIngestors )
40- assert .Equal (t , []string {"chaintracks_cdn (source_url=https://cdn.projectbabbage.com/blockheaders)" , "whats_on_chain_cdn" }, info .BulkIngestors )
41- t .Logf ("Bulk height: %d" , info .HeightBulk ) // TODO: When we use live data (not mocked), this value is not constant; will be changed to assert.Equal later
42- t .Logf ("Live height: %d" , info .HeightLive )
43-
4432 // when:
4533 height , err := service .GetPresentHeight (t .Context ())
4634
4735 // then:
4836 require .NoError (t , err , "get present height should not return error" )
4937 require .Greater (t , height , uint (900000 ), "present height should be greater than 900000" )
5038
51- // when:
52- tipHeader , err := service .FindChainTipHeader (t .Context ())
39+ t .Run ("GetInfo" , func (t * testing.T ) {
40+ // when:
41+ info , err := service .GetInfo (t .Context ())
42+
43+ // then:
44+ require .NoError (t , err , "get info should not return error" )
45+ assert .Equal (t , defs .NetworkMainnet , info .Chain )
46+ assert .Equal (t , "gorm-sqlite-inmemory" , info .Storage )
47+ assert .Equal (t , []string {"woc_poll" }, info .LiveIngestors )
48+ assert .Equal (t , []string {"chaintracks_cdn (source_url=https://cdn.projectbabbage.com/blockheaders)" , "whats_on_chain_cdn" }, info .BulkIngestors )
49+ t .Logf ("Bulk height: %d" , info .HeightBulk ) // TODO: When we use live data (not mocked), this value is not constant; will be changed to assert.Equal later
50+ t .Logf ("Live height: %d" , info .HeightLive )
51+ })
5352
54- // then:
55- require .NoError (t , err , "find chain tip header should not return error" )
56- require .NotNil (t , tipHeader , "tip header should not be nil" )
57- require .Equal (t , height , tipHeader .Height , "tip header height should be equal to present height" )
53+ t .Run ("FindChainTipHeader" , func (t * testing.T ) {
54+ // when:
55+ tipHeader , err := service .FindChainTipHeader (t .Context ())
56+
57+ // then:
58+ require .NoError (t , err , "find chain tip header should not return error" )
59+ require .NotNil (t , tipHeader , "tip header should not be nil" )
60+ require .Equal (t , height , tipHeader .Height , "tip header height should be equal to present height" )
61+ })
62+
63+ t .Run ("FindHeaderForHeight_recent" , func (t * testing.T ) {
64+ // when:
65+ header , err := service .FindHeaderForHeight (t .Context (), height - 10 )
66+
67+ // then:
68+ require .NoError (t , err , "find header for height should not return error" )
69+ require .NotNil (t , header , "header should not be nil" )
70+ require .Equal (t , height - 10 , header .Height , "header height should be equal to requested height" )
71+ t .Logf ("Header at height %d: %#+v" , header .Height , header )
72+ })
73+
74+ t .Run ("FindHeaderForHeight_genesis" , func (t * testing.T ) {
75+ // when:
76+ header , err := service .FindHeaderForHeight (t .Context (), 0 )
77+
78+ // then:
79+ require .NoError (t , err , "find header for height 0 should not return error" )
80+ require .NotNil (t , header , "header at height 0 should not be nil" )
81+ require .Equal (t , uint (0 ), header .Height , "header height should be 0" )
82+ require .Equal (t , "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f" , header .Hash , "header hash at height 0 should be genesis hash" )
83+ t .Logf ("Genesis header: %#+v" , header )
84+ })
85+
86+ t .Run ("FindHeaderForHeight_old" , func (t * testing.T ) {
87+ // when:
88+ header , err := service .FindHeaderForHeight (t .Context (), height - 5000 )
89+
90+ // then:
91+ require .NoError (t , err , "find header for height should not return error" )
92+ require .NotNil (t , header , "header should not be nil" )
93+ require .Equal (t , height - 5000 , header .Height , "header height should be equal to requested height" )
94+ t .Logf ("Header at height %d: %#+v" , header .Height , header )
95+ })
5896
5997 // when:
6098 service .Destroy ()
0 commit comments