github.com/Finschia/finschia-sdk@v0.48.1/x/slashing/client/testutil/grpc.go (about) 1 package testutil 2 3 import ( 4 "fmt" 5 "time" 6 7 "github.com/gogo/protobuf/proto" 8 9 "github.com/Finschia/finschia-sdk/testutil" 10 sdk "github.com/Finschia/finschia-sdk/types" 11 grpctypes "github.com/Finschia/finschia-sdk/types/grpc" 12 "github.com/Finschia/finschia-sdk/types/query" 13 "github.com/Finschia/finschia-sdk/x/slashing/types" 14 ) 15 16 func (s *IntegrationTestSuite) TestGRPCQueries() { 17 val := s.network.Validators[0] 18 baseURL := val.APIAddress 19 20 consAddr := sdk.ConsAddress(val.PubKey.Address()).String() 21 22 testCases := []struct { 23 name string 24 url string 25 headers map[string]string 26 expErr bool 27 respType proto.Message 28 expected proto.Message 29 }{ 30 { 31 "get signing infos (height specific)", 32 fmt.Sprintf("%s/cosmos/slashing/v1beta1/signing_infos", baseURL), 33 map[string]string{ 34 grpctypes.GRPCBlockHeightHeader: "1", 35 }, 36 false, 37 &types.QuerySigningInfosResponse{}, 38 &types.QuerySigningInfosResponse{ 39 Info: []types.ValidatorSigningInfo{ 40 { 41 Address: sdk.ConsAddress(val.PubKey.Address()).String(), 42 JailedUntil: time.Unix(0, 0), 43 }, 44 }, 45 Pagination: &query.PageResponse{ 46 Total: uint64(1), 47 }, 48 }, 49 }, 50 { 51 "get signing info (height specific)", 52 fmt.Sprintf("%s/cosmos/slashing/v1beta1/signing_infos/%s", baseURL, consAddr), 53 map[string]string{ 54 grpctypes.GRPCBlockHeightHeader: "1", 55 }, 56 false, 57 &types.QuerySigningInfoResponse{}, 58 &types.QuerySigningInfoResponse{ 59 ValSigningInfo: types.ValidatorSigningInfo{ 60 Address: sdk.ConsAddress(val.PubKey.Address()).String(), 61 JailedUntil: time.Unix(0, 0), 62 }, 63 }, 64 }, 65 { 66 "get signing info wrong address", 67 fmt.Sprintf("%s/cosmos/slashing/v1beta1/signing_infos/%s", baseURL, "wrongAddress"), 68 map[string]string{}, 69 true, 70 &types.QuerySigningInfoResponse{}, 71 nil, 72 }, 73 { 74 "params", 75 fmt.Sprintf("%s/cosmos/slashing/v1beta1/params", baseURL), 76 map[string]string{}, 77 false, 78 &types.QueryParamsResponse{}, 79 &types.QueryParamsResponse{ 80 Params: types.DefaultParams(), 81 }, 82 }, 83 } 84 85 for _, tc := range testCases { 86 tc := tc 87 88 s.Run(tc.name, func() { 89 resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) 90 s.Require().NoError(err) 91 92 err = val.ClientCtx.Codec.UnmarshalJSON(resp, tc.respType) 93 94 if tc.expErr { 95 s.Require().Error(err) 96 } else { 97 s.Require().NoError(err) 98 s.Require().Equal(tc.expected.String(), tc.respType.String()) 99 } 100 }) 101 } 102 }