@@ -5,6 +5,7 @@ package systemtests
5
5
import (
6
6
"context"
7
7
"fmt"
8
+ "net/http"
8
9
"net/url"
9
10
"testing"
10
11
"time"
@@ -82,6 +83,10 @@ func TestQueryBlockByHeight(t *testing.T) {
82
83
}
83
84
84
85
func TestQueryLatestValidatorSet (t * testing.T ) {
86
+ if sut .NodesCount () < 2 {
87
+ t .Skip ("not enough nodes" )
88
+ return
89
+ }
85
90
baseurl := fmt .Sprintf ("http://localhost:%d" , apiPortStart )
86
91
sut .ResetChain (t )
87
92
sut .StartChain (t )
@@ -103,7 +108,7 @@ func TestQueryLatestValidatorSet(t *testing.T) {
103
108
assert .NoError (t , err )
104
109
assert .Equal (t , len (res .Validators ), 2 )
105
110
106
- restRes := GetRequest (t , mustV ( url . JoinPath ( baseurl , " /cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=0 &pagination.limit=2" ) ))
111
+ restRes := GetRequest (t , fmt . Sprintf ( "%s /cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=%d &pagination.limit=%d" , baseurl , 0 , 2 ))
107
112
assert .Equal (t , len (gjson .GetBytes (restRes , "validators" ).Array ()), 2 )
108
113
}
109
114
@@ -161,13 +166,14 @@ func TestLatestValidatorSet_GRPCGateway(t *testing.T) {
161
166
}
162
167
for _ , tc := range testCases {
163
168
t .Run (tc .name , func (t * testing.T ) {
164
- rsp := GetRequest (t , mustV (url .JoinPath (baseurl , tc .url )))
165
169
if tc .expErr {
170
+ rsp := GetRequestWithHeaders (t , baseurl + tc .url , nil , http .StatusBadRequest )
166
171
errMsg := gjson .GetBytes (rsp , "message" ).String ()
167
172
assert .Contains (t , errMsg , tc .expErrMsg )
168
- } else {
169
- assert .Equal (t , len (vals ), int (gjson .GetBytes (rsp , "pagination.total" ).Int ()))
173
+ return
170
174
}
175
+ rsp := GetRequest (t , baseurl + tc .url )
176
+ assert .Equal (t , len (vals ), int (gjson .GetBytes (rsp , "pagination.total" ).Int ()))
171
177
})
172
178
}
173
179
}
@@ -204,41 +210,40 @@ func TestValidatorSetByHeight(t *testing.T) {
204
210
}
205
211
}
206
212
207
- func TestValidatorSetByHeight_GRPCGateway (t * testing.T ) {
213
+ func TestValidatorSetByHeight_GRPCRestGateway (t * testing.T ) {
208
214
sut .ResetChain (t )
209
215
sut .StartChain (t )
210
216
211
217
vals := sut .RPCClient (t ).Validators ()
212
218
213
- baseurl := fmt .Sprintf ("http://localhost:%d" , apiPortStart )
214
-
219
+ baseurl := sut .APIAddress ()
215
220
block := sut .AwaitNextBlock (t , time .Second * 3 )
216
221
testCases := []struct {
217
- name string
218
- url string
219
- expErr bool
220
- expErrMsg string
222
+ name string
223
+ url string
224
+ expErr bool
225
+ expErrMsg string
226
+ expHttpCode int
221
227
}{
222
- {"invalid height" , fmt .Sprintf ("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d" , baseurl , - 1 ), true , "height must be greater than 0" },
223
- {"no pagination" , fmt .Sprintf ("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d" , baseurl , block ), false , "" },
224
- {"pagination invalid fields" , fmt .Sprintf ("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d?pagination.offset=-1&pagination.limit=-2" , baseurl , block ), true , "strconv.ParseUint" },
225
- {"with pagination" , fmt .Sprintf ("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d?pagination.limit=2" , baseurl , 1 ), false , "" },
228
+ {"invalid height" , fmt .Sprintf ("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d" , baseurl , - 1 ), true , "height must be greater than 0" , http . StatusInternalServerError },
229
+ {"no pagination" , fmt .Sprintf ("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d" , baseurl , block ), false , "" , http . StatusOK },
230
+ {"pagination invalid fields" , fmt .Sprintf ("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d?pagination.offset=-1&pagination.limit=-2" , baseurl , block ), true , "strconv.ParseUint" , http . StatusBadRequest },
231
+ {"with pagination" , fmt .Sprintf ("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d?pagination.limit=2" , baseurl , 1 ), false , "" , http . StatusOK },
226
232
}
227
233
for _ , tc := range testCases {
228
234
t .Run (tc .name , func (t * testing.T ) {
229
- rsp := GetRequest (t , tc .url )
235
+ rsp := GetRequestWithHeaders (t , tc .url , nil , tc . expHttpCode )
230
236
if tc .expErr {
231
237
errMsg := gjson .GetBytes (rsp , "message" ).String ()
232
238
assert .Contains (t , errMsg , tc .expErrMsg )
233
- } else {
234
- assert .Equal (t , len (vals ), int (gjson .GetBytes (rsp , "pagination.total" ).Int ()))
239
+ return
235
240
}
241
+ assert .Equal (t , len (vals ), int (gjson .GetBytes (rsp , "pagination.total" ).Int ()))
236
242
})
237
243
}
238
244
}
239
245
240
246
func TestABCIQuery (t * testing.T ) {
241
- sut .ResetChain (t )
242
247
sut .StartChain (t )
243
248
244
249
qc := cmtservice .NewServiceClient (sut .RPCClient (t ))
@@ -312,7 +317,7 @@ func TestABCIQuery(t *testing.T) {
312
317
} else {
313
318
assert .NoError (t , err )
314
319
assert .NotNil (t , res )
315
- assert .Equal (t , res . Code , tc . expectedCode )
320
+ assert .Equal (t , tc . expectedCode , res . Code )
316
321
}
317
322
318
323
if tc .validQuery {
0 commit comments