Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove creator field from channel query #7523

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
130 changes: 40 additions & 90 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 @@ -34,8 +34,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
Loading