Skip to content

Commit

Permalink
Merge branch 'feat/ibc-eureka' into damian/7478-packet-receipt-query
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan committed Oct 29, 2024
2 parents 3a1c3ec + e752c0d commit b6e5cb8
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 147 deletions.
3 changes: 2 additions & 1 deletion modules/core/04-channel/v2/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func getCmdQueryChannel() *cobra.Command {
cmd := &cobra.Command{
Use: "channel [channel-id]",
Short: "Query the information of a channel.",
Long: "Query the channel information (creator and channel) for the provided channel ID.",
Long: "Query the channel information for the provided channel ID.",
Example: fmt.Sprintf("%s query %s %s channel [channel-id]", version.AppName, exported.ModuleName, types.SubModuleName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -39,6 +39,7 @@ func getCmdQueryChannel() *cobra.Command {
return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
Expand Down
13 changes: 4 additions & 9 deletions modules/core/04-channel/v2/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,12 @@ func (q *queryServer) Channel(ctx context.Context, req *types.QueryChannelReques
return nil, status.Error(codes.InvalidArgument, err.Error())
}

creator, foundCreator := q.GetCreator(ctx, req.ChannelId)
channel, foundChannel := q.GetChannel(ctx, req.ChannelId)

if !foundCreator && !foundChannel {
return nil, status.Error(
codes.NotFound,
errorsmod.Wrapf(types.ErrChannelNotFound, "channel-id: %s", req.ChannelId).Error(),
)
channel, found := q.GetChannel(ctx, req.ChannelId)
if !found {
return nil, status.Error(codes.NotFound, errorsmod.Wrapf(types.ErrChannelNotFound, "channel-id: %s", req.ChannelId).Error())
}

return types.NewQueryChannelResponse(creator, channel), nil
return types.NewQueryChannelResponse(channel), nil
}

// PacketCommitment implements the Query/PacketCommitment gRPC method.
Expand Down
44 changes: 7 additions & 37 deletions modules/core/04-channel/v2/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
func (suite *KeeperTestSuite) TestQueryChannel() {
var (
req *types.QueryChannelRequest
expCreator string
expChannel types.Channel
)

Expand All @@ -28,7 +27,6 @@ func (suite *KeeperTestSuite) TestQueryChannel() {
"success",
func() {
ctx := suite.chainA.GetContext()
suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetCreator(ctx, ibctesting.FirstChannelID, expCreator)
suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetChannel(ctx, ibctesting.FirstChannelID, expChannel)

req = &types.QueryChannelRequest{
Expand All @@ -38,54 +36,28 @@ func (suite *KeeperTestSuite) TestQueryChannel() {
nil,
},
{
"success: no creator",
func() {
expCreator = ""

suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetChannel(suite.chainA.GetContext(), ibctesting.FirstChannelID, expChannel)

req = &types.QueryChannelRequest{
ChannelId: ibctesting.FirstChannelID,
}
},
nil,
},
{
"success: no channel",
"req is nil",
func() {
expChannel = types.Channel{}

suite.chainA.App.GetIBCKeeper().ChannelKeeperV2.SetCreator(suite.chainA.GetContext(), ibctesting.FirstChannelID, expCreator)

req = &types.QueryChannelRequest{
ChannelId: ibctesting.FirstChannelID,
}
req = nil
},
nil,
status.Error(codes.InvalidArgument, "empty request"),
},
{
"req is nil",
"invalid channelID",
func() {
req = nil
req = &types.QueryChannelRequest{}
},
status.Error(codes.InvalidArgument, "empty request"),
status.Error(codes.InvalidArgument, "identifier cannot be blank: invalid identifier"),
},
{
"no creator and no channel",
"channel not found",
func() {
req = &types.QueryChannelRequest{
ChannelId: ibctesting.FirstChannelID,
}
},
status.Error(codes.NotFound, fmt.Sprintf("channel-id: %s: channel not found", ibctesting.FirstChannelID)),
},
{
"invalid channelID",
func() {
req = &types.QueryChannelRequest{}
},
status.Error(codes.InvalidArgument, "identifier cannot be blank: invalid identifier"),
},
}

for _, tc := range testCases {
Expand All @@ -94,7 +66,6 @@ func (suite *KeeperTestSuite) TestQueryChannel() {
suite.Run(fmt.Sprintf("Case %s", tc.msg), func() {
suite.SetupTest() // reset

expCreator = ibctesting.TestAccAddress
merklePathPrefix := commitmenttypes.NewMerklePath([]byte("prefix"))
expChannel = types.Channel{ClientId: ibctesting.SecondClientID, CounterpartyChannelId: ibctesting.SecondChannelID, MerklePathPrefix: merklePathPrefix}

Expand All @@ -107,7 +78,6 @@ func (suite *KeeperTestSuite) TestQueryChannel() {
if expPass {
suite.Require().NoError(err)
suite.Require().NotNil(res)
suite.Require().Equal(expCreator, res.Creator)
suite.Require().Equal(expChannel, res.Channel)
} else {
suite.Require().ErrorIs(err, tc.expError)
Expand Down
3 changes: 1 addition & 2 deletions modules/core/04-channel/v2/types/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ func NewQueryChannelRequest(channelID string) *QueryChannelRequest {
}

// NewQueryChannelResponse creates and returns a new channel query response.
func NewQueryChannelResponse(creator string, channel Channel) *QueryChannelResponse {
func NewQueryChannelResponse(channel Channel) *QueryChannelResponse {
return &QueryChannelResponse{
Creator: creator,
Channel: channel,
}
}
Expand Down
141 changes: 45 additions & 96 deletions modules/core/04-channel/v2/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions proto/ibc/core/channel/v2/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ message QueryChannelRequest {

// QueryChannelRequest is the response type for the Query/Channel RPC method
message QueryChannelResponse {
string creator = 1;
Channel channel = 2 [(gogoproto.nullable) = false];
// the channel associated with the provided channel id
Channel channel = 1 [(gogoproto.nullable) = false];
}

// QueryPacketCommitmentRequest is the request type for the Query/PacketCommitment RPC method.
Expand Down

0 comments on commit b6e5cb8

Please sign in to comment.