@@ -131,32 +131,126 @@ func (s IntegrationTestSuite) TestQueryLatestValidatorSet() {
131
131
s .Require ().Equal (validatorSetRes .Validators [0 ].PubKey , anyPub )
132
132
}
133
133
134
- func (s IntegrationTestSuite ) TestQueryValidatorSetByHeight () {
135
- val := s .network .Validators [0 ]
136
-
137
- // nil pagination
138
- _ , err := s .queryClient .GetValidatorSetByHeight (context .Background (), & tmservice.GetValidatorSetByHeightRequest {
139
- Height : 1 ,
140
- Pagination : nil ,
141
- })
142
- s .Require ().NoError (err )
134
+ func (s IntegrationTestSuite ) TestLatestValidatorSet_GRPC () {
135
+ vals := s .network .Validators
136
+ testCases := []struct {
137
+ name string
138
+ req * tmservice.GetLatestValidatorSetRequest
139
+ expErr bool
140
+ expErrMsg string
141
+ }{
142
+ {"nil request" , nil , true , "cannot be nil" },
143
+ {"no pagination" , & tmservice.GetLatestValidatorSetRequest {}, false , "" },
144
+ {"with pagination" , & tmservice.GetLatestValidatorSetRequest {Pagination : & qtypes.PageRequest {Offset : 0 , Limit : uint64 (len (vals ))}}, false , "" },
145
+ }
146
+ for _ , tc := range testCases {
147
+ tc := tc
148
+ s .Run (tc .name , func () {
149
+ grpcRes , err := s .queryClient .GetLatestValidatorSet (context .Background (), tc .req )
150
+ if tc .expErr {
151
+ s .Require ().Error (err )
152
+ s .Require ().Contains (err .Error (), tc .expErrMsg )
153
+ } else {
154
+ s .Require ().NoError (err )
155
+ s .Require ().Len (grpcRes .Validators , len (vals ))
156
+ s .Require ().Equal (grpcRes .Pagination .Total , uint64 (len (vals )))
157
+ content , ok := grpcRes .Validators [0 ].PubKey .GetCachedValue ().(cryptotypes.PubKey )
158
+ s .Require ().Equal (true , ok )
159
+ s .Require ().Equal (content , vals [0 ].PubKey )
160
+ }
161
+ })
162
+ }
163
+ }
143
164
144
- _ , err = s .queryClient .GetValidatorSetByHeight (context .Background (), & tmservice.GetValidatorSetByHeightRequest {
145
- Height : 1 ,
146
- Pagination : & qtypes.PageRequest {
147
- Offset : 0 ,
148
- Limit : 10 ,
149
- }})
150
- s .Require ().NoError (err )
165
+ func (s IntegrationTestSuite ) TestLatestValidatorSet_GRPCGateway () {
166
+ vals := s .network .Validators
167
+ testCases := []struct {
168
+ name string
169
+ url string
170
+ expErr bool
171
+ expErrMsg string
172
+ }{
173
+ {"no pagination" , fmt .Sprintf ("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest" , vals [0 ].APIAddress ), false , "" },
174
+ {"pagination invalid fields" , fmt .Sprintf ("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=-1&pagination.limit=-2" , vals [0 ].APIAddress ), true , "strconv.ParseUint" },
175
+ {"with pagination" , fmt .Sprintf ("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=0&pagination.limit=2" , vals [0 ].APIAddress ), false , "" },
176
+ }
177
+ for _ , tc := range testCases {
178
+ tc := tc
179
+ s .Run (tc .name , func () {
180
+ res , err := rest .GetRequest (tc .url )
181
+ s .Require ().NoError (err )
182
+ if tc .expErr {
183
+ s .Require ().Contains (string (res ), tc .expErrMsg )
184
+ } else {
185
+ var result tmservice.GetLatestValidatorSetResponse
186
+ err = vals [0 ].ClientCtx .JSONMarshaler .UnmarshalJSON (res , & result )
187
+ s .Require ().NoError (err )
188
+ s .Require ().Equal (uint64 (len (vals )), result .Pagination .Total )
189
+ anyPub , err := codectypes .NewAnyWithValue (vals [0 ].PubKey )
190
+ s .Require ().NoError (err )
191
+ s .Require ().Equal (result .Validators [0 ].PubKey , anyPub )
192
+ }
193
+ })
194
+ }
195
+ }
151
196
152
- // no pagination rest
153
- _ , err = rest .GetRequest (fmt .Sprintf ("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d" , val .APIAddress , 1 ))
154
- s .Require ().NoError (err )
197
+ func (s IntegrationTestSuite ) TestValidatorSetByHeight_GRPC () {
198
+ vals := s .network .Validators
199
+ testCases := []struct {
200
+ name string
201
+ req * tmservice.GetValidatorSetByHeightRequest
202
+ expErr bool
203
+ expErrMsg string
204
+ }{
205
+ {"nil request" , nil , true , "request cannot be nil" },
206
+ {"empty request" , & tmservice.GetValidatorSetByHeightRequest {}, true , "height must be greater than 0" },
207
+ {"no pagination" , & tmservice.GetValidatorSetByHeightRequest {Height : 1 }, false , "" },
208
+ {"with pagination" , & tmservice.GetValidatorSetByHeightRequest {Height : 1 , Pagination : & qtypes.PageRequest {Offset : 0 , Limit : 1 }}, false , "" },
209
+ }
210
+ for _ , tc := range testCases {
211
+ tc := tc
212
+ s .Run (tc .name , func () {
213
+ grpcRes , err := s .queryClient .GetValidatorSetByHeight (context .Background (), tc .req )
214
+ if tc .expErr {
215
+ s .Require ().Error (err )
216
+ s .Require ().Contains (err .Error (), tc .expErrMsg )
217
+ } else {
218
+ s .Require ().NoError (err )
219
+ s .Require ().Len (grpcRes .Validators , len (vals ))
220
+ s .Require ().Equal (grpcRes .Pagination .Total , uint64 (len (vals )))
221
+ }
222
+ })
223
+ }
224
+ }
155
225
156
- // rest query with pagination
157
- restRes , err := rest .GetRequest (fmt .Sprintf ("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d?pagination.offset=%d&pagination.limit=%d" , val .APIAddress , 1 , 0 , 1 ))
158
- var validatorSetRes tmservice.GetValidatorSetByHeightResponse
159
- s .Require ().NoError (val .ClientCtx .JSONMarshaler .UnmarshalJSON (restRes , & validatorSetRes ))
226
+ func (s IntegrationTestSuite ) TestValidatorSetByHeight_GRPCGateway () {
227
+ vals := s .network .Validators
228
+ testCases := []struct {
229
+ name string
230
+ url string
231
+ expErr bool
232
+ expErrMsg string
233
+ }{
234
+ {"invalid height" , fmt .Sprintf ("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d" , vals [0 ].APIAddress , - 1 ), true , "height must be greater than 0" },
235
+ {"no pagination" , fmt .Sprintf ("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d" , vals [0 ].APIAddress , 1 ), false , "" },
236
+ {"pagination invalid fields" , fmt .Sprintf ("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d?pagination.offset=-1&pagination.limit=-2" , vals [0 ].APIAddress , 1 ), true , "strconv.ParseUint" },
237
+ {"with pagination" , fmt .Sprintf ("%s/cosmos/base/tendermint/v1beta1/validatorsets/%d?pagination.offset=0&pagination.limit=2" , vals [0 ].APIAddress , 1 ), false , "" },
238
+ }
239
+ for _ , tc := range testCases {
240
+ tc := tc
241
+ s .Run (tc .name , func () {
242
+ res , err := rest .GetRequest (tc .url )
243
+ s .Require ().NoError (err )
244
+ if tc .expErr {
245
+ s .Require ().Contains (string (res ), tc .expErrMsg )
246
+ } else {
247
+ var result tmservice.GetValidatorSetByHeightResponse
248
+ err = vals [0 ].ClientCtx .JSONMarshaler .UnmarshalJSON (res , & result )
249
+ s .Require ().NoError (err )
250
+ s .Require ().Equal (uint64 (len (vals )), result .Pagination .Total )
251
+ }
252
+ })
253
+ }
160
254
}
161
255
162
256
func TestIntegrationTestSuite (t * testing.T ) {
0 commit comments