From cd25f8882b2d62b1692c84fd2e46279ac5bb59c9 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Tue, 19 Sep 2023 16:15:17 +0100 Subject: [PATCH] fix(query): get next send sequence for transfer packets (#4706) * feat(packet): get next send sequence for transfer packets * chore(channels): fixed tests for unordered sequence * Update modules/core/04-channel/keeper/grpc_query_test.go Co-authored-by: Carlos Rodriguez * chore: removed useless error handling --------- Co-authored-by: Carlos Rodriguez --- modules/core/04-channel/keeper/grpc_query.go | 17 ++--------------- .../core/04-channel/keeper/grpc_query_test.go | 6 ++++-- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/modules/core/04-channel/keeper/grpc_query.go b/modules/core/04-channel/keeper/grpc_query.go index 171c88d435f..1802b2f4a1e 100644 --- a/modules/core/04-channel/keeper/grpc_query.go +++ b/modules/core/04-channel/keeper/grpc_query.go @@ -555,26 +555,13 @@ func (k Keeper) NextSequenceSend(c context.Context, req *types.QueryNextSequence ctx := sdk.UnwrapSDKContext(c) - channel, found := k.GetChannel(ctx, req.PortId, req.ChannelId) + sequence, found := k.GetNextSequenceSend(ctx, req.PortId, req.ChannelId) if !found { return nil, status.Error( codes.NotFound, - errorsmod.Wrapf(types.ErrChannelNotFound, "port-id: %s, channel-id %s", req.PortId, req.ChannelId).Error(), + errorsmod.Wrapf(types.ErrSequenceSendNotFound, "port-id: %s, channel-id %s", req.PortId, req.ChannelId).Error(), ) } - - // Return the next sequence send for ordered channels. Unordered channels - // do not make use of the next sequence send. - var sequence uint64 - if channel.Ordering != types.UNORDERED { - sequence, found = k.GetNextSequenceSend(ctx, req.PortId, req.ChannelId) - if !found { - return nil, status.Error( - codes.NotFound, - errorsmod.Wrapf(types.ErrSequenceSendNotFound, "port-id: %s, channel-id %s", req.PortId, req.ChannelId).Error(), - ) - } - } selfHeight := clienttypes.GetSelfHeight(ctx) return types.NewQueryNextSequenceSendResponse(sequence, nil, selfHeight), nil } diff --git a/modules/core/04-channel/keeper/grpc_query_test.go b/modules/core/04-channel/keeper/grpc_query_test.go index 725b6d1655a..00937161d97 100644 --- a/modules/core/04-channel/keeper/grpc_query_test.go +++ b/modules/core/04-channel/keeper/grpc_query_test.go @@ -1620,12 +1620,14 @@ func (suite *KeeperTestSuite) TestQueryNextSequenceSend() { false, }, { - "basic success on unordered channel returns zero", + "basic success on unordered channel returns the set send sequence", func() { path := ibctesting.NewPath(suite.chainA, suite.chainB) suite.coordinator.Setup(path) - expSeq = 0 + expSeq = 42 + seq := uint64(42) + suite.chainA.App.GetIBCKeeper().ChannelKeeper.SetNextSequenceSend(suite.chainA.GetContext(), path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, seq) req = &types.QueryNextSequenceSendRequest{ PortId: path.EndpointA.ChannelConfig.PortID, ChannelId: path.EndpointA.ChannelID,