@@ -13,54 +13,64 @@ import (
13
13
"google.golang.org/grpc/metadata"
14
14
rpb "google.golang.org/grpc/reflection/grpc_reflection_v1alpha"
15
15
16
+ clienttx "github.com/cosmos/cosmos-sdk/client/tx"
16
17
"github.com/cosmos/cosmos-sdk/testutil/network"
17
18
"github.com/cosmos/cosmos-sdk/testutil/testdata"
18
19
sdk "github.com/cosmos/cosmos-sdk/types"
19
20
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
20
21
"github.com/cosmos/cosmos-sdk/types/tx"
21
22
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
23
+ "github.com/cosmos/cosmos-sdk/types/tx/signing"
24
+ authclient "github.com/cosmos/cosmos-sdk/x/auth/client"
22
25
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
23
26
)
24
27
25
28
type IntegrationTestSuite struct {
26
29
suite.Suite
27
30
31
+ cfg network.Config
28
32
network * network.Network
33
+ conn * grpc.ClientConn
29
34
}
30
35
31
36
func (s * IntegrationTestSuite ) SetupSuite () {
32
37
s .T ().Log ("setting up integration test suite" )
33
38
34
- s .network = network .New (s .T (), network .DefaultConfig ())
39
+ s .cfg = network .DefaultConfig ()
40
+ s .network = network .New (s .T (), s .cfg )
35
41
s .Require ().NotNil (s .network )
36
42
37
43
_ , err := s .network .WaitForHeight (2 )
38
44
s .Require ().NoError (err )
39
- }
40
-
41
- func (s * IntegrationTestSuite ) TearDownSuite () {
42
- s .T ().Log ("tearing down integration test suite" )
43
- s .network .Cleanup ()
44
- }
45
45
46
- func (s * IntegrationTestSuite ) TestGRPCServer () {
47
46
val0 := s .network .Validators [0 ]
48
- conn , err : = grpc .Dial (
47
+ s . conn , err = grpc .Dial (
49
48
val0 .AppConfig .GRPC .Address ,
50
49
grpc .WithInsecure (), // Or else we get "no transport security set"
51
50
)
52
51
s .Require ().NoError (err )
53
- defer conn . Close ()
52
+ }
54
53
54
+ func (s * IntegrationTestSuite ) TearDownSuite () {
55
+ s .T ().Log ("tearing down integration test suite" )
56
+ s .conn .Close ()
57
+ s .network .Cleanup ()
58
+ }
59
+
60
+ func (s * IntegrationTestSuite ) TestGRPCServer_TestService () {
55
61
// gRPC query to test service should work
56
- testClient := testdata .NewQueryClient (conn )
62
+ testClient := testdata .NewQueryClient (s . conn )
57
63
testRes , err := testClient .Echo (context .Background (), & testdata.EchoRequest {Message : "hello" })
58
64
s .Require ().NoError (err )
59
65
s .Require ().Equal ("hello" , testRes .Message )
66
+ }
67
+
68
+ func (s * IntegrationTestSuite ) TestGRPCServer_BankBalance () {
69
+ val0 := s .network .Validators [0 ]
60
70
61
71
// gRPC query to bank service should work
62
72
denom := fmt .Sprintf ("%stoken" , val0 .Moniker )
63
- bankClient := banktypes .NewQueryClient (conn )
73
+ bankClient := banktypes .NewQueryClient (s . conn )
64
74
var header metadata.MD
65
75
bankRes , err := bankClient .Balance (
66
76
context .Background (),
@@ -83,9 +93,11 @@ func (s *IntegrationTestSuite) TestGRPCServer() {
83
93
)
84
94
blockHeight = header .Get (grpctypes .GRPCBlockHeightHeader )
85
95
s .Require ().Equal ([]string {"1" }, blockHeight )
96
+ }
86
97
98
+ func (s * IntegrationTestSuite ) TestGRPCServer_Reflection () {
87
99
// Test server reflection
88
- reflectClient := rpb .NewServerReflectionClient (conn )
100
+ reflectClient := rpb .NewServerReflectionClient (s . conn )
89
101
stream , err := reflectClient .ServerReflectionInfo (context .Background (), grpc .WaitForReady (true ))
90
102
s .Require ().NoError (err )
91
103
s .Require ().NoError (stream .Send (& rpb.ServerReflectionRequest {
@@ -100,11 +112,13 @@ func (s *IntegrationTestSuite) TestGRPCServer() {
100
112
}
101
113
// Make sure the following services are present
102
114
s .Require ().True (servicesMap ["cosmos.bank.v1beta1.Query" ])
115
+ }
103
116
117
+ func (s * IntegrationTestSuite ) TestGRPCServer_GetTxsEvent () {
104
118
// Query the tx via gRPC without pagination. This used to panic, see
105
119
// https://github.com/cosmos/cosmos-sdk/issues/8038.
106
- txServiceClient := txtypes .NewServiceClient (conn )
107
- _ , err = txServiceClient .GetTxsEvent (
120
+ txServiceClient := txtypes .NewServiceClient (s . conn )
121
+ _ , err : = txServiceClient .GetTxsEvent (
108
122
context .Background (),
109
123
& tx.GetTxsEventRequest {
110
124
Events : []string {"message.action=send" },
@@ -115,6 +129,50 @@ func (s *IntegrationTestSuite) TestGRPCServer() {
115
129
s .Require ().NoError (err )
116
130
}
117
131
132
+ func (s * IntegrationTestSuite ) TestGRPCServer_BroadcastTx () {
133
+ val0 := s .network .Validators [0 ]
134
+
135
+ // prepare txBuilder with msg
136
+ txBuilder := val0 .ClientCtx .TxConfig .NewTxBuilder ()
137
+ feeAmount := sdk.Coins {sdk .NewInt64Coin (s .cfg .BondDenom , 10 )}
138
+ gasLimit := testdata .NewTestGasLimit ()
139
+ s .Require ().NoError (
140
+ txBuilder .SetMsgs (& banktypes.MsgSend {
141
+ FromAddress : val0 .Address .String (),
142
+ ToAddress : val0 .Address .String (),
143
+ Amount : sdk.Coins {sdk .NewInt64Coin (s .cfg .BondDenom , 10 )},
144
+ }),
145
+ )
146
+ txBuilder .SetFeeAmount (feeAmount )
147
+ txBuilder .SetGasLimit (gasLimit )
148
+
149
+ // setup txFactory
150
+ txFactory := clienttx.Factory {}.
151
+ WithChainID (val0 .ClientCtx .ChainID ).
152
+ WithKeybase (val0 .ClientCtx .Keyring ).
153
+ WithTxConfig (val0 .ClientCtx .TxConfig ).
154
+ WithSignMode (signing .SignMode_SIGN_MODE_DIRECT )
155
+
156
+ // Sign Tx.
157
+ err := authclient .SignTx (txFactory , val0 .ClientCtx , val0 .Moniker , txBuilder , false )
158
+ s .Require ().NoError (err )
159
+
160
+ txBytes , err := val0 .ClientCtx .TxConfig .TxEncoder ()(txBuilder .GetTx ())
161
+ s .Require ().NoError (err )
162
+
163
+ // Broadcast the tx via gRPC.
164
+ queryClient := tx .NewServiceClient (s .conn )
165
+ grpcRes , err := queryClient .BroadcastTx (
166
+ context .Background (),
167
+ & tx.BroadcastTxRequest {
168
+ Mode : tx .BroadcastMode_BROADCAST_MODE_SYNC ,
169
+ TxBytes : txBytes ,
170
+ },
171
+ )
172
+ s .Require ().NoError (err )
173
+ s .Require ().Equal (uint32 (0 ), grpcRes .TxResponse .Code )
174
+ }
175
+
118
176
// Test and enforce that we upfront reject any connections to baseapp containing
119
177
// invalid initial x-cosmos-block-height that aren't positive and in the range [0, max(int64)]
120
178
// See issue https://github.com/cosmos/cosmos-sdk/issues/7662.
0 commit comments