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