Skip to content

Commit 5e95975

Browse files
test: fix ica compatibility tests (#7976) (#7994)
* test: fix ica compatibility tests * lint * fix event search * lint (cherry picked from commit 22efa6c) Co-authored-by: Gjermund Garaba <gjermund@garaba.net>
1 parent bd6b1b4 commit 5e95975

File tree

6 files changed

+75
-101
lines changed

6 files changed

+75
-101
lines changed

.github/workflows/e2e-compatibility.yaml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -236,24 +236,6 @@ jobs:
236236
test-file: "e2e/tests/transfer/send_receive_test.go"
237237
release-version: "${{ needs.determine-image-tag.outputs.release-version }}"
238238

239-
transfer-upgrades-v1-test:
240-
needs:
241-
- build-release-images
242-
- determine-image-tag
243-
uses: ./.github/workflows/e2e-compatibility-workflow-call.yaml
244-
with:
245-
test-file: "e2e/tests/transfer/upgradesv1_test.go"
246-
release-version: "${{ needs.determine-image-tag.outputs.release-version }}"
247-
248-
transfer-upgrades-v2-test:
249-
needs:
250-
- build-release-images
251-
- determine-image-tag
252-
uses: ./.github/workflows/e2e-compatibility-workflow-call.yaml
253-
with:
254-
test-file: "e2e/tests/transfer/upgradesv2_test.go"
255-
release-version: "${{ needs.determine-image-tag.outputs.release-version }}"
256-
257239
upgrade-genesis-test:
258240
needs:
259241
- build-release-images

e2e/tests/interchain_accounts/params_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,16 +252,13 @@ func (s *InterchainAccountsParamsTestSuite) TestHostEnabledParam() {
252252
})
253253

254254
t.Run("verify acknowledgement error in ack transaction", func(t *testing.T) {
255-
cmd := "message.action=/ibc.core.channel.v1.MsgRecvPacket"
256-
if testvalues.TransactionEventQueryFeatureReleases.IsSupported(chainBVersion) {
257-
cmd = "message.action='/ibc.core.channel.v1.MsgRecvPacket'"
258-
}
255+
cmd := "message.action='/ibc.core.channel.v1.MsgRecvPacket'"
259256
txSearchRes, err := s.QueryTxsByEvents(ctx, chainB, 1, 1, cmd, "")
260257
s.Require().NoError(err)
261258
s.Require().Len(txSearchRes.Txs, 1)
262259

263260
errorMessage, isFound := s.ExtractValueFromEvents(
264-
txSearchRes.Txs[0].Events,
261+
txSearchRes.TxResponses[0].Events,
265262
coretypes.ErrorAttributeKeyPrefix+icatypes.EventTypePacket,
266263
coretypes.ErrorAttributeKeyPrefix+icatypes.AttributeKeyAckError,
267264
)

e2e/tests/interchain_accounts/query_test.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type InterchainAccountsQueryTestSuite struct {
3535
testsuite.E2ETestSuite
3636
}
3737

38-
// compatibility:InterchainAccountsQueryTestSuite:from_versions: v7.5.0,v7.6.0,v7.7.0,v7.8.0,v8.4.0,v8.5.0,v10.0.0
38+
// compatibility:TestInterchainAccountsQuery:from_versions: v7.5.0,v7.6.0,v7.7.0,v7.8.0,v8.4.0,v8.5.0,v10.0.0
3939
func (s *InterchainAccountsQueryTestSuite) TestInterchainAccountsQuery() {
4040
t := s.T()
4141
ctx := context.TODO()
@@ -44,7 +44,6 @@ func (s *InterchainAccountsQueryTestSuite) TestInterchainAccountsQuery() {
4444
relayer := s.CreateDefaultPaths(testName)
4545

4646
chainA, chainB := s.GetChains()
47-
chainBVersion := chainB.Config().Images[0].Version
4847

4948
// setup 2 accounts: controller account on chain A, a second chain B account.
5049
// host account will be created when the ICA is registered
@@ -106,26 +105,23 @@ func (s *InterchainAccountsQueryTestSuite) TestInterchainAccountsQuery() {
106105
txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, icaQueryMsg)
107106
s.AssertTxSuccess(txResp)
108107

109-
s.Require().NoError(testutil.WaitForBlocks(ctx, 10, chainA, chainB))
108+
s.Require().NoError(testutil.WaitForBlocks(ctx, 20, chainA, chainB))
110109
})
111110

112111
t.Run("verify query response", func(t *testing.T) {
113112
var expQueryHeight uint64
114113

115114
ack := &channeltypes.Acknowledgement_Result{}
116115
t.Run("retrieve acknowledgement", func(t *testing.T) {
117-
cmd := "message.action=/ibc.core.channel.v1.MsgRecvPacket"
118-
if testvalues.TransactionEventQueryFeatureReleases.IsSupported(chainBVersion) {
119-
cmd = "message.action='/ibc.core.channel.v1.MsgRecvPacket'"
120-
}
116+
cmd := "message.action='/ibc.core.channel.v1.MsgRecvPacket'"
121117
txSearchRes, err := s.QueryTxsByEvents(ctx, chainB, 1, 1, cmd, "")
122118
s.Require().NoError(err)
123-
s.Require().Len(txSearchRes.Txs, 1)
119+
s.Require().Len(txSearchRes.TxResponses, 1)
124120

125-
expQueryHeight = uint64(txSearchRes.Txs[0].Height)
121+
expQueryHeight = uint64(txSearchRes.TxResponses[0].Height)
126122

127123
ackHexValue, isFound := s.ExtractValueFromEvents(
128-
txSearchRes.Txs[0].Events,
124+
txSearchRes.TxResponses[0].Events,
129125
channeltypes.EventTypeWriteAck,
130126
channeltypes.AttributeKeyAckHex,
131127
)

e2e/testsuite/query/grpc_query.go

Lines changed: 51 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,49 @@ package query
33
import (
44
"context"
55
"fmt"
6-
"strings"
76

87
"github.com/cosmos/gogoproto/proto"
98
"github.com/strangelove-ventures/interchaintest/v8/ibc"
109
"google.golang.org/grpc"
1110
"google.golang.org/grpc/credentials/insecure"
11+
pb "google.golang.org/protobuf/proto"
12+
13+
msgv1 "cosmossdk.io/api/cosmos/msg/v1"
14+
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
1215
)
1316

17+
var queryReqToPath = make(map[string]string)
18+
19+
func PopulateQueryReqToPath(ctx context.Context, chain ibc.Chain) error {
20+
resp, err := queryFileDescriptors(ctx, chain)
21+
if err != nil {
22+
return err
23+
}
24+
25+
for _, fileDescriptor := range resp.Files {
26+
for _, service := range fileDescriptor.GetService() {
27+
// Skip services that are annotated with the "cosmos.msg.v1.service" option.
28+
if ext := pb.GetExtension(service.GetOptions(), msgv1.E_Service); ext != nil {
29+
if ok, extBool := ext.(bool); ok && extBool {
30+
continue
31+
}
32+
}
33+
34+
for _, method := range service.GetMethod() {
35+
// trim the first character from input which is a dot
36+
queryReqToPath[method.GetInputType()[1:]] = fileDescriptor.GetPackage() + "." + service.GetName() + "/" + method.GetName()
37+
}
38+
}
39+
}
40+
41+
return nil
42+
}
43+
1444
// GRPCQuery queries the chain with a query request and deserializes the response to T
1545
func GRPCQuery[T any](ctx context.Context, chain ibc.Chain, req proto.Message, opts ...grpc.CallOption) (*T, error) {
16-
path, err := getProtoPath(req)
17-
if err != nil {
18-
return nil, err
46+
path, ok := queryReqToPath[proto.MessageName(req)]
47+
if !ok {
48+
return nil, fmt.Errorf("no path found for %s", proto.MessageName(req))
1949
}
2050

2151
return grpcQueryWithMethod[T](ctx, chain, req, path, opts...)
@@ -43,48 +73,26 @@ func grpcQueryWithMethod[T any](ctx context.Context, chain ibc.Chain, req proto.
4373
return resp, nil
4474
}
4575

46-
func getProtoPath(req proto.Message) (string, error) {
47-
typeURL := "/" + proto.MessageName(req)
48-
49-
switch {
50-
case strings.Contains(typeURL, "Query"):
51-
return getQueryProtoPath(typeURL)
52-
case strings.Contains(typeURL, "cosmos.base.tendermint"):
53-
return getCmtProtoPath(typeURL)
54-
default:
55-
return "", fmt.Errorf("unsupported typeURL: %s", typeURL)
56-
}
57-
}
58-
59-
func getQueryProtoPath(queryTypeURL string) (string, error) {
60-
queryIndex := strings.Index(queryTypeURL, "Query")
61-
if queryIndex == -1 {
62-
return "", fmt.Errorf("invalid typeURL: %s", queryTypeURL)
63-
}
64-
65-
// Add to the index to account for the length of "Query"
66-
queryIndex += len("Query")
67-
68-
// Add a slash before the query
69-
urlWithSlash := queryTypeURL[:queryIndex] + "/" + queryTypeURL[queryIndex:]
70-
if !strings.HasSuffix(urlWithSlash, "Request") {
71-
return "", fmt.Errorf("invalid typeURL: %s", queryTypeURL)
76+
func queryFileDescriptors(ctx context.Context, chain ibc.Chain) (*reflectionv1.FileDescriptorsResponse, error) {
77+
// Create a connection to the gRPC server.
78+
grpcConn, err := grpc.Dial(
79+
chain.GetHostGRPCAddress(),
80+
grpc.WithTransportCredentials(insecure.NewCredentials()),
81+
)
82+
if err != nil {
83+
return nil, err
7284
}
7385

74-
return strings.TrimSuffix(urlWithSlash, "Request"), nil
75-
}
76-
77-
func getCmtProtoPath(cmtTypeURL string) (string, error) {
78-
cmtIndex := strings.Index(cmtTypeURL, "Get")
79-
if cmtIndex == -1 {
80-
return "", fmt.Errorf("invalid typeURL: %s", cmtTypeURL)
81-
}
86+
defer grpcConn.Close()
8287

83-
// Add a slash before the commitment
84-
urlWithSlash := cmtTypeURL[:cmtIndex] + "Service/" + cmtTypeURL[cmtIndex:]
85-
if !strings.HasSuffix(urlWithSlash, "Request") {
86-
return "", fmt.Errorf("invalid typeURL: %s", cmtTypeURL)
88+
resp := new(reflectionv1.FileDescriptorsResponse)
89+
err = grpcConn.Invoke(
90+
ctx, reflectionv1.ReflectionService_FileDescriptors_FullMethodName,
91+
&reflectionv1.FileDescriptorsRequest{}, resp,
92+
)
93+
if err != nil {
94+
return nil, err
8795
}
8896

89-
return strings.TrimSuffix(urlWithSlash, "Request"), nil
97+
return resp, nil
9098
}

e2e/testsuite/testsuite.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ func (s *E2ETestSuite) SetupChains(ctx context.Context, channelOptionsModifier C
192192
}
193193

194194
s.Require().NoError(ic.Build(ctx, s.GetRelayerExecReporter(), buildOpts))
195+
196+
// setup query paths for GRPC queries:
197+
for _, chain := range s.chains {
198+
s.Require().NoError(query.PopulateQueryReqToPath(ctx, chain))
199+
}
195200
}
196201

197202
// CreateDefaultPaths creates a path between the chains using the default client and channel options.

e2e/testsuite/tx.go

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import (
1717
sdkmath "cosmossdk.io/math"
1818

1919
"github.com/cosmos/cosmos-sdk/client"
20-
"github.com/cosmos/cosmos-sdk/client/flags"
2120
"github.com/cosmos/cosmos-sdk/client/tx"
2221
sdk "github.com/cosmos/cosmos-sdk/types"
22+
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
2323
signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing"
2424
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
2525
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
@@ -309,43 +309,29 @@ func (s *E2ETestSuite) PruneAcknowledgements(
309309
func (*E2ETestSuite) QueryTxsByEvents(
310310
ctx context.Context, chain ibc.Chain,
311311
page, limit int, queryReq, orderBy string,
312-
) (*sdk.SearchTxsResult, error) {
312+
) (*txtypes.GetTxsEventResponse, error) {
313313
cosmosChain, ok := chain.(*cosmos.CosmosChain)
314314
if !ok {
315315
return nil, errors.New("QueryTxsByEvents must be passed a cosmos.CosmosChain")
316316
}
317317

318-
cmd := []string{"txs"}
319-
320-
chainVersion := chain.Config().Images[0].Version
321-
if testvalues.TransactionEventQueryFeatureReleases.IsSupported(chainVersion) {
322-
cmd = append(cmd, "--query", queryReq)
323-
} else {
324-
cmd = append(cmd, "--events", queryReq)
325-
}
326-
327-
if orderBy != "" {
328-
cmd = append(cmd, "--order_by", orderBy)
329-
}
330-
if page != 0 {
331-
cmd = append(cmd, "--"+flags.FlagPage, strconv.Itoa(page))
332-
}
333-
if limit != 0 {
334-
cmd = append(cmd, "--"+flags.FlagLimit, strconv.Itoa(limit))
318+
req := &txtypes.GetTxsEventRequest{
319+
Page: uint64(page),
320+
Limit: uint64(limit),
321+
Query: queryReq,
335322
}
336323

337-
stdout, _, err := cosmosChain.GetNode().ExecQuery(ctx, cmd...)
338-
if err != nil {
339-
return nil, err
324+
if !testvalues.TransactionEventQueryFeatureReleases.IsSupported(chain.Config().Images[0].Version) {
325+
req.Events = []string{queryReq}
326+
req.Query = ""
340327
}
341328

342-
result := &sdk.SearchTxsResult{}
343-
err = Codec().UnmarshalJSON(stdout, result)
329+
res, err := query.GRPCQuery[txtypes.GetTxsEventResponse](ctx, cosmosChain, req)
344330
if err != nil {
345331
return nil, err
346332
}
347333

348-
return result, nil
334+
return res, nil
349335
}
350336

351337
// ExtractValueFromEvents extracts the value of an attribute from a list of events.

0 commit comments

Comments
 (0)