@@ -7,16 +7,23 @@ import (
77 "strings"
88 "time"
99
10+ "e2e/testconfig"
11+
12+ sdk "github.com/cosmos/cosmos-sdk/types"
1013 dockerclient "github.com/docker/docker/client"
1114 "github.com/strangelove-ventures/ibctest"
15+ "github.com/strangelove-ventures/ibctest/broadcast"
1216 "github.com/strangelove-ventures/ibctest/chain/cosmos"
1317 "github.com/strangelove-ventures/ibctest/ibc"
18+ "github.com/strangelove-ventures/ibctest/test"
1419 "github.com/strangelove-ventures/ibctest/testreporter"
1520 "github.com/stretchr/testify/suite"
1621 "go.uber.org/zap"
1722 "go.uber.org/zap/zaptest"
23+ "google.golang.org/grpc"
24+ "google.golang.org/grpc/credentials/insecure"
1825
19- "e2e/testconfig "
26+ feetypes "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/types "
2027)
2128
2229const (
@@ -29,13 +36,22 @@ const (
2936// E2ETestSuite has methods and functionality which can be shared among all test suites.
3037type E2ETestSuite struct {
3138 suite.Suite
39+
40+ grpcClients map [string ]GRPCClients
3241 paths map [string ]path
3342 logger * zap.Logger
3443 DockerClient * dockerclient.Client
3544 network string
3645 startRelayerFn func (relayer ibc.Relayer )
3746}
3847
48+ // GRPCClients holds a reference to any GRPC clients that are needed by the tests.
49+ // These should typically be used for query clients only. If we need to make changes, we should
50+ // use E2ETestSuite.BroadcastMessages to broadcast transactions instead.
51+ type GRPCClients struct {
52+ FeeQueryClient feetypes.QueryClient
53+ }
54+
3955// path is a pairing of two chains which will be used in a test.
4056type path struct {
4157 chainA , chainB * cosmos.CosmosChain
@@ -102,6 +118,9 @@ func (s *E2ETestSuite) SetupChainsRelayerAndChannel(ctx context.Context, channel
102118 time .Sleep (time .Second * 10 )
103119 }
104120
121+ s .initGRPCClients (chainA )
122+ s .initGRPCClients (chainB )
123+
105124 return r
106125}
107126
@@ -129,6 +148,20 @@ func (s *E2ETestSuite) GetChains(chainOpts ...testconfig.ChainOptionConfiguratio
129148 return path .chainA , path .chainB
130149}
131150
151+ // BroadcastMessages broadcasts the provided messages to the given chain and signs them on behalf of the provided user.
152+ // Once the broadcast response is returned, we wait for a few blocks to be created on both chain A and chain B.
153+ func (s * E2ETestSuite ) BroadcastMessages (ctx context.Context , chain * cosmos.CosmosChain , user broadcast.User , msgs ... sdk.Msg ) (sdk.TxResponse , error ) {
154+ broadcaster := cosmos .NewBroadcaster (s .T (), chain )
155+ resp , err := ibctest .BroadcastTx (ctx , broadcaster , user , msgs ... )
156+ if err != nil {
157+ return sdk.TxResponse {}, err
158+ }
159+
160+ chainA , chainB := s .GetChains ()
161+ err = test .WaitForBlocks (ctx , 2 , chainA , chainB )
162+ return resp , err
163+ }
164+
132165// GetRelayerWallets returns the relayer wallets associated with the chains.
133166func (s * E2ETestSuite ) GetRelayerWallets (relayer ibc.Relayer ) (ibc.RelayerWallet , ibc.RelayerWallet , error ) {
134167 chainA , chainB := s .GetChains ()
@@ -196,6 +229,37 @@ func (s *E2ETestSuite) GetChainBNativeBalance(ctx context.Context, user *ibctest
196229 return GetNativeChainBalance (ctx , chainB , user )
197230}
198231
232+ // GetChainGRCPClients gets the GRPC clients associated with the given chain.
233+ func (s * E2ETestSuite ) GetChainGRCPClients (chain ibc.Chain ) GRPCClients {
234+ cs , ok := s .grpcClients [chain .Config ().ChainID ]
235+ s .Require ().True (ok , "chain %s does not have GRPC clients" , chain .Config ().ChainID )
236+ return cs
237+ }
238+
239+ // initGRPCClients establishes GRPC clients with the given chain.
240+ // The created GRPCClients can be retrieved with GetChainGRCPClients.
241+ func (s * E2ETestSuite ) initGRPCClients (chain * cosmos.CosmosChain ) {
242+ // Create a connection to the gRPC server.
243+ grpcConn , err := grpc .Dial (
244+ chain .GetHostGRPCAddress (),
245+ grpc .WithTransportCredentials (insecure .NewCredentials ()),
246+ )
247+ s .Require ().NoError (err )
248+ s .T ().Cleanup (func () {
249+ if err := grpcConn .Close (); err != nil {
250+ s .T ().Logf ("failed closing GRPC connection to chain %s: %s" , chain .Config ().ChainID , err )
251+ }
252+ })
253+
254+ if s .grpcClients == nil {
255+ s .grpcClients = make (map [string ]GRPCClients )
256+ }
257+
258+ s .grpcClients [chain .Config ().ChainID ] = GRPCClients {
259+ FeeQueryClient : feetypes .NewQueryClient (grpcConn ),
260+ }
261+ }
262+
199263// createCosmosChains creates two separate chains in docker containers.
200264// test and can be retrieved with GetChains.
201265func (s * E2ETestSuite ) createCosmosChains (chainOptions testconfig.ChainOptions ) (* cosmos.CosmosChain , * cosmos.CosmosChain ) {
0 commit comments