@@ -21,16 +21,18 @@ import (
21
21
"fmt"
22
22
"os"
23
23
"path/filepath"
24
+ "strings"
24
25
"testing"
26
+ "time"
25
27
26
- //nolint:staticcheck
27
- "github.com/golang/protobuf/proto"
28
+ "github.com/cosmos/gogoproto/proto"
28
29
"github.com/stretchr/testify/require"
29
30
"google.golang.org/grpc"
30
31
"google.golang.org/grpc/credentials/insecure"
31
32
32
33
sdkerrors "cosmossdk.io/errors"
33
34
clienttx "github.com/cosmos/cosmos-sdk/client/tx"
35
+ "github.com/cosmos/cosmos-sdk/codec"
34
36
"github.com/cosmos/cosmos-sdk/crypto/keyring"
35
37
sdk "github.com/cosmos/cosmos-sdk/types"
36
38
"github.com/cosmos/cosmos-sdk/types/tx"
@@ -59,6 +61,7 @@ func (suite *TestSuite) GetGRPCConn() *grpc.ClientConn {
59
61
grpcConn , err := grpc .Dial (
60
62
"127.0.0.1:26630" , // Or your gRPC server address.
61
63
grpc .WithTransportCredentials (insecure .NewCredentials ()), // The SDK doesn't support any transport security mechanism.
64
+ grpc .WithDefaultCallOptions (grpc .ForceCodec (codec .NewProtoCodec (suite .EncodingConfig .InterfaceRegistry ).GRPCCodec ())),
62
65
)
63
66
require .NoError (suite .T , err )
64
67
@@ -144,21 +147,30 @@ func (suite *TestSuite) BroadcastTx(txBytes []byte) (*sdk.TxResponse, error) {
144
147
TxBytes : txBytes ,
145
148
}
146
149
147
- if suite .Rest {
148
- var _resp tx.GetTxResponse
150
+ if suite .Rest { //nolint:nestif
151
+ var _getResp tx.GetTxResponse
152
+ var _brdResp tx.BroadcastTxResponse
149
153
150
154
bodyBytes , err := suite .EncodingConfig .Codec .MarshalJSON (& body )
151
155
require .NoError (suite .T , err )
152
156
153
- _ , err = SendPostRequest ("/cosmos/tx/v1beta1/txs" , bodyBytes , "" , "" )
157
+ respBytes , err := SendPostRequest ("/cosmos/tx/v1beta1/txs" , bodyBytes , "" , "" )
158
+ require .NoError (suite .T , err )
159
+ require .NoError (suite .T , suite .EncodingConfig .Codec .UnmarshalJSON (respBytes , & _brdResp ))
160
+
161
+ for i := 1 ; i <= 10 ; i ++ {
162
+ respBytes , err = SendGetRequest (fmt .Sprintf ("/cosmos/tx/v1beta1/txs/%s" , _brdResp .GetTxResponse ().TxHash ))
163
+ if err == nil {
164
+ require .NoError (suite .T , suite .EncodingConfig .Codec .UnmarshalJSON (respBytes , & _getResp ))
165
+
166
+ break
167
+ }
168
+ time .Sleep (2 * time .Second )
169
+ }
154
170
if err != nil {
155
171
return nil , err
156
172
}
157
-
158
- respBytes , err := SendGetRequest (fmt .Sprintf ("/cosmos/tx/v1beta1/txs/%s" , _resp .GetTxResponse ().TxHash ))
159
- require .NoError (suite .T , err )
160
- require .NoError (suite .T , suite .EncodingConfig .Codec .UnmarshalJSON (respBytes , & _resp ))
161
- txResponse = & _resp
173
+ txResponse = & _getResp
162
174
} else {
163
175
grpcConn := suite .GetGRPCConn ()
164
176
defer grpcConn .Close ()
@@ -171,7 +183,13 @@ func (suite *TestSuite) BroadcastTx(txBytes []byte) (*sdk.TxResponse, error) {
171
183
return nil , err
172
184
}
173
185
174
- txResponse , err = txClient .GetTx (context .Background (), & tx.GetTxRequest {Hash : broadCastResponse .GetTxResponse ().TxHash })
186
+ for i := 1 ; i <= 10 ; i ++ {
187
+ txResponse , err = txClient .GetTx (context .Background (), & tx.GetTxRequest {Hash : broadCastResponse .GetTxResponse ().TxHash })
188
+ if err == nil && ! strings .Contains (txResponse .TxResponse .RawLog , "tx not found" ) {
189
+ break
190
+ }
191
+ time .Sleep (2 * time .Second )
192
+ }
175
193
if err != nil {
176
194
return nil , err
177
195
}
@@ -209,7 +227,7 @@ func (suite *TestSuite) QueryREST(uri string, resp proto.Message) error {
209
227
210
228
func (suite * TestSuite ) AssertNotFound (err error ) {
211
229
require .Error (suite .T , err )
212
- require .Contains (suite .T , err .Error (), "rpc error: code = NotFound desc = not found" )
230
+ require .Contains (suite .T , err .Error (), "not found" )
213
231
214
232
if suite .Rest {
215
233
var resterr * RESTError
0 commit comments