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