@@ -28,15 +28,18 @@ import (
2828 "github.com/vechain/thor/v2/tx"
2929)
3030
31- const defaultLogLimit uint64 = 1000
31+ const (
32+ defaultLogLimit uint64 = 1000
33+ defaultLogOffset uint64 = 100
34+ )
3235
3336var (
3437 ts * httptest.Server
3538 tclient * thorclient.Client
3639)
3740
3841func TestEmptyEvents (t * testing.T ) {
39- initEventServer (t , defaultLogLimit )
42+ initEventServer (t , defaultLogLimit , defaultLogOffset )
4043 defer ts .Close ()
4144
4245 tclient = thorclient .New (ts .URL )
@@ -49,7 +52,7 @@ func TestEmptyEvents(t *testing.T) {
4952}
5053
5154func TestEvents (t * testing.T ) {
52- thorChain := initEventServer (t , defaultLogLimit )
55+ thorChain := initEventServer (t , defaultLogLimit , defaultLogOffset )
5356 defer ts .Close ()
5457
5558 blocksToInsert := 5
@@ -59,7 +62,7 @@ func TestEvents(t *testing.T) {
5962}
6063
6164func TestOptionalIndexes (t * testing.T ) {
62- thorChain := initEventServer (t , defaultLogLimit )
65+ thorChain := initEventServer (t , defaultLogLimit , defaultLogOffset )
6366 defer ts .Close ()
6467 insertBlocks (t , thorChain , 5 )
6568 tclient = thorclient .New (ts .URL )
@@ -109,7 +112,7 @@ func TestOptionalIndexes(t *testing.T) {
109112}
110113
111114func TestEvents_WithOptionsNoLimit (t * testing.T ) {
112- thorChain := initEventServer (t , defaultLogLimit )
115+ thorChain := initEventServer (t , defaultLogLimit , defaultLogOffset )
113116 defer ts .Close ()
114117 insertBlocks (t , thorChain , 5 )
115118
@@ -133,7 +136,7 @@ func TestEvents_WithOptionsNoLimit(t *testing.T) {
133136}
134137
135138func TestOption (t * testing.T ) {
136- thorChain := initEventServer (t , 5 )
139+ thorChain := initEventServer (t , 5 , defaultLogOffset )
137140 defer ts .Close ()
138141 insertBlocks (t , thorChain , 5 )
139142
@@ -197,10 +200,27 @@ func TestOption(t *testing.T) {
197200 assert .NoError (t , err )
198201 assert .Equal (t , http .StatusBadRequest , statusCode )
199202 assert .Equal (t , "number of criteria in criteriaSet: 11 cannot be greater than: 10\n " , string (res ))
203+
204+ filter = api.EventFilter {
205+ CriteriaSet : make ([]* api.EventCriteria , 0 ),
206+ Range : nil ,
207+ Options : & api.Options {Offset : defaultLogOffset , Limit : new (uint64 (0 ))},
208+ Order : logdb .DESC ,
209+ }
210+
211+ _ , statusCode , err = tclient .RawHTTPClient ().RawHTTPPost ("/logs/event" , filter )
212+ require .NoError (t , err )
213+ assert .Equal (t , http .StatusOK , statusCode )
214+
215+ filter .Options .Offset = defaultLogOffset * 2
216+ res , statusCode , err = tclient .RawHTTPClient ().RawHTTPPost ("/logs/event" , filter )
217+ require .NoError (t , err )
218+ assert .Equal (t , http .StatusForbidden , statusCode )
219+ assert .Equal (t , "options.offset exceeds the maximum allowed value of 100" , strings .Trim (string (res ), "\n " ))
200220}
201221
202222func TestZeroFrom (t * testing.T ) {
203- thorChain := initEventServer (t , 100 )
223+ thorChain := initEventServer (t , 100 , defaultLogOffset )
204224 defer ts .Close ()
205225 insertBlocks (t , thorChain , 5 )
206226
@@ -234,7 +254,7 @@ func TestZeroFrom(t *testing.T) {
234254}
235255
236256func TestNullCriteriaSet (t * testing.T ) {
237- initEventServer (t , defaultLogLimit )
257+ initEventServer (t , defaultLogLimit , defaultLogOffset )
238258 defer ts .Close ()
239259
240260 tclient = thorclient .New (ts .URL )
@@ -328,12 +348,12 @@ func testEventWithBlocks(t *testing.T, expectedBlocks int) {
328348}
329349
330350// Init functions
331- func initEventServer (t * testing.T , limit uint64 ) * testchain.Chain {
351+ func initEventServer (t * testing.T , limit uint64 , offset uint64 ) * testchain.Chain {
332352 thorChain , err := testchain .NewDefault ()
333353 require .NoError (t , err )
334354
335355 router := mux .NewRouter ()
336- New (thorChain .Repo (), thorChain .LogDB (), limit , 10 ).Mount (router , "/logs/event" )
356+ New (thorChain .Repo (), thorChain .LogDB (), limit , offset , 10 ).Mount (router , "/logs/event" )
337357 ts = httptest .NewServer (router )
338358
339359 return thorChain
0 commit comments